Search code examples
javascriptvue.jsvuejs3eslintprettier

Vue's script and style 0 tab indent error with Prettier


I have got an indent error with prettier in .vue files.

How can I disable prettier's indent check in .vue files?

enter image description here

This is my eslint config

.eslintrc.js

module.exports = {
  root: true,
  env: {
    node: true,
  },
  plugins: ['prettier'],
  extends: [
    'plugin:vue/vue3-essential',
    'plugin:prettier/recommended',
    'prettier',
    'eslint:recommended',
  ],
  parserOptions: {
    parser: '@babel/eslint-parser',
  },
  rules: {
    'vue/script-indent': 'off',
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
  },
  overrides: [
    {
      files: ['*.vue'],
      rules: {
        indent: 'off',
      },
    },
  ],
};

This is my prettier config

.prettierrc.js

module.exports = {
  trailingComma: 'es5',
  tabWidth: 2,
  singleQuote: true,
  semi: true,
};

Solution

  • I found an answer which works for my config.

    Just need to add this code to rules of eslint's config.

    'prettier/prettier': [
      'error',
      {
        vueIndentScriptAndStyle: false,
      },
    ],