ESLint Prettier Plugin for Vue SFC

5.0.0 · active · verified Sun Apr 19

This ESLint plugin integrates Prettier formatting specifically for Vue Single File Components (SFCs). At version 5.0.0, it is actively maintained and provides a robust solution for ensuring consistent code style in Vue projects. It includes all functionalities of `eslint-plugin-prettier` but extends them to properly handle the unique structure of Vue SFCs. Its key differentiators include the ability to process and format custom blocks (e.g., `<docs>`, `<config>`) within Vue SFCs, which `eslint-plugin-prettier` does not support. It also offers granular control over whether `<template>`, `<script>`, or `<style>` blocks should be processed by Prettier, allowing developers to disable formatting for specific sections if needed. While no explicit release cadence is documented, it typically updates to support new versions of ESLint, Prettier, and Vue. It is designed to be the sole Prettier-ESLint integration for Vue projects, superseding the general `eslint-plugin-prettier`.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates installation of the plugin and its dependencies, followed by the essential `.eslintrc.js` configuration including recommended presets and custom block handling.

npm install --save-dev eslint-plugin-prettier-vue eslint-plugin-vue eslint-config-prettier eslint prettier

// .eslintrc.js
module.exports = {
  extends: [
    'plugin:vue/recommended',
    'plugin:prettier-vue/recommended' // ALWAYS last to override conflicting rules
  ],
  settings: {
    'prettier-vue': {
      SFCBlocks: {
        template: true,
        script: true,
        style: true,
        customBlocks: {
          docs: { lang: 'markdown' }, // Example for a custom <docs> block
          config: { lang: 'json' }
        }
      },
      usePrettierrc: true,
      fileInfoOptions: { withNodeModules: false }
    }
  },
  rules: {
    'prettier-vue/prettier': [
      'error',
      {
        // Override specific Prettier options here if needed, e.g.:
        printWidth: 100,
        singleQuote: true,
        semi: false
      }
    ]
  }
};

view raw JSON →