Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-plugin-prettier-vue

meteorlxy163.6kMIT5.0.0TypeScript support: included

ESLint plugin for Prettier formatting, which is better for Vue SFC

readme

eslint-plugin-prettier-vue

npm prettier GitHub

Make prettier works better on Vue SFC

  • Includes all functions of eslint-plugin-prettier.
  • Provides the ability for prettier to process custom blocks of Vue SFCs.
  • Options to disable prettier for <template>, <script> or <style> blocks of Vue SFCs.

Demo

Prettier custom blocks:

demo

Usage

Installation

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

ESLint Config

DO NOT use eslint-plugin-prettier together. This plugin includes all functionalities of eslint-plugin-prettier so you do not need it.

// .eslintrc.js
module.exports = {
  extends: ['plugin:vue/recommended', 'plugin:prettier-vue/recommended'],

  settings: {
    'prettier-vue': {
      // Settings for how to process Vue SFC Blocks
      SFCBlocks: {
        /**
         * Use prettier to process `<template>` blocks or not
         *
         * If set to `false`, you may need to enable those vue rules that are disabled by `eslint-config-prettier`,
         * because you need them to lint `<template>` blocks
         *
         * @default true
         */
        template: true,

        /**
         * Use prettier to process `<script>` blocks or not
         *
         * If set to `false`, you may need to enable those rules that are disabled by `eslint-config-prettier`,
         * because you need them to lint `<script>` blocks
         *
         * @default true
         */
        script: true,

        /**
         * Use prettier to process `<style>` blocks or not
         *
         * @default true
         */
        style: true,

        // Settings for how to process custom blocks
        customBlocks: {
          // Treat the `<docs>` block as a `.markdown` file
          docs: { lang: 'markdown' },

          // Treat the `<config>` block as a `.json` file
          config: { lang: 'json' },

          // Treat the `<module>` block as a `.js` file
          module: { lang: 'js' },

          // Ignore `<comments>` block (omit it or set it to `false` to ignore the block)
          comments: false,

          // Other custom blocks that are not listed here will be ignored
        },
      },

      // Use prettierrc for prettier options or not (default: `true`)
      usePrettierrc: true,

      // Set the options for `prettier.getFileInfo`.
      // @see https://prettier.io/docs/en/api.html#prettiergetfileinfofilepath-options
      fileInfoOptions: {
        // Path to ignore file (default: `'.prettierignore'`)
        // Notice that the ignore file is only used for this plugin
        ignorePath: '.testignore',

        // Process the files in `node_modules` or not (default: `false`)
        withNodeModules: false,
      },
    },
  },

  rules: {
    'prettier-vue/prettier': [
      'error',
      {
        // Override all options of `prettier` here
        // @see https://prettier.io/docs/en/options.html
        printWidth: 100,
        singleQuote: true,
        semi: false,
        trailingComma: 'es5',
      },
    ],
  },
};

LICENSE

MIT © @meteorlxy & Contributors

MIT © eslint-plugin-prettier

changelog

5.0.0 (2023-08-25)

Build System

  • update build target to node 16 (6599897)

Features

BREAKING CHANGES

  • upgrade to prettier v3
  • drop support for node 14

4.2.0 (2022-06-30)

Features

  • sync some changes from eslint-plugin-prettier (196a5cf)

4.1.0 (2022-06-09)

Features

  • update options schema to prettier 2.6 (fda709d)

4.0.0 (2022-06-09)

Build System

  • migrate to pnpm and bump dependencies (897ce8a)

BREAKING CHANGES

  • drop support for node 10 & 12

3.1.0 (2021-05-28)

Features

3.0.0 (2021-04-21)

3.0.0-alpha.2 (2020-08-07)

3.0.0-alpha.1 (2020-08-07)

Features

  • use vue 3 compiler-sfc and migrate to typescript (db976d1)

2.1.1 (2020-07-24)

Bug Fixes

  • support vue-indent-script-and-style option (close #12) (ec36426)

2.1.0 (2020-04-28)

Features

2.0.2 (2019-10-24)

Bug Fixes

  • warning for unsupported file format (1c6b918)

2.0.1 (2019-10-22)

Bug Fixes

  • add prefix to avoid cache (d80eaaf)

2.0.0 (2019-08-22)

Features

  • make this plugin more flexible (e67cffd)
    • ability to process <template> block
    • options to disable prettier for <template>, <script> and <style> blocks

BREAKING CHANGES

  • settings for custom blocks migrate from settings['prettier-vue].customBlocks to settings['prettier-vue].SFCBlocks.customBlocks
  • this plugin will process <template> block by default

1.1.3 (2019-08-22)

Bug Fixes

  • disable deindent option (a98b58d)

1.1.2 (2019-08-05)

Bug Fixes

  • move prettier to dependencies (6797c8c)

1.1.1 (2019-08-05)

Bug Fixes

  • restriction of vue-template-compiler version (a7c20fa)

1.1.0 (2019-08-04)

Features

  • ignore custom blocks by default (a5e4907)

1.0.0 (2019-08-03)

Features

  • set options in settings field (3751942)

BREAKING CHANGES

  • options set in the third item of the rule is not valid

0.2.0 (2019-08-03)

Features

  • process all sfc blocks in the same way (546d098)

0.1.2 (2019-08-03)

Bug Fixes

0.1.1 (2019-08-03)

Bug Fixes

  • set default lang of custom blocks to vue (194d86a)

0.1.0 (2019-08-03)

Features

  • specify prettier options (957d17b)
  • support style and custom blocks (238912f)

0.0.1 (2019-07-31)