Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eslint insists on not indenting <script> tag

I have 'indent': ['warn', 2, { 'SwitchCase' : 1 }] in my eslintrc rules.

However, it complains that the indentation of this code in a Vue template is wrong:

<script>
  export default {
    name: 'Sausage',
  }
</script>

Instead, it wants this:

<script>
export default {
  name: 'Sausage',
}
</script>

I find this much uglier and harder to read — and it's inconstent with the <template> and <style> tags in the same template.

How can I tell eslint that the contents of a <script> tag should be indented one level?

like image 382
John Y Avatar asked Oct 08 '18 09:10

John Y


1 Answers

In your .eslintrc.js, add a rule for "vue/script-indent" and turn off the "indent" rule for .vue files. There's options to configure indentation for switch statements here as well.

module.exports = {
    root: true,
    env: {
        node: true
    },
    'extends': [
        'plugin:vue/essential',
        'eslint:recommended'
    ],
    rules: {
        'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
        'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
        "indent": ["error", 4],
        "vue/script-indent": ["error", 4, {
            "baseIndent": 1,
            "switchCase": 1,
            "ignores": []
        }],
        "space-before-function-paren": ["error", "never"],
    },
    overrides: [
        {
            "files": ["*.vue"],
            "rules": {
                "indent": "off"
            }
        }
    ],
    parserOptions: {
        parser: 'babel-eslint'
    }
}
like image 185
Evil Pigeon Avatar answered Sep 19 '22 03:09

Evil Pigeon