Skip to content

vue/script-indent false positive on switch case in methods #459

Closed
@evenfrost

Description

@evenfrost

Tell us about your environment

  • ESLint Version: v4.19.1
  • eslint-plugin-vue Version: 4.4.0
  • Node Version: 9.11.1

Please show your full configuration:

{
  "extends": [
    "../.eslintrc",
    "plugin:vue/base",
    "plugin:vue/essential",
    "plugin:vue/strongly-recommended",
    "plugin:vue/recommended"
  ],
  "parser": "vue-eslint-parser",
  "parserOptions": {
    "parser": "typescript-eslint-parser"
  },
  "plugins": [
    "import",
    "typescript"
  ],
  "settings": {
    "import/resolver": {
      "webpack": {
        "config": "./webpack.dev.js"
      }
    }
  },
  "rules": {
    "no-undef": "off",
    "import/extensions": ["error", "always", {
      "js": "never",
      "ts": "never"
    }],
    "vue/html-closing-bracket-newline": ["error", {
      "singleline": "never",
      "multiline": "always"
    }],
    "vue/html-closing-bracket-spacing": ["error", {
      "startTag": "never",
      "endTag": "never",
      "selfClosingTag": "always"
    }],
    "vue/html-self-closing": ["error", {
      "html": {
        "normal": "never"
      }
    }],
    "vue/prop-name-casing": ["error", "camelCase"],
    "vue/script-indent": ["error", 2]
  }
}

What did you do? Please include the actual source code causing the issue.

export default Vue.extend({
  methods: {
    getStarClassNamePostfix(index: number) {
      let starClassNamePostfix: string = '';

      switch (index) {
        case 0:
          starClassNamePostfix = '-lighter';
          break;
        case 1:
          starClassNamePostfix = '-light';
          break;
        case 2:
          starClassNamePostfix = '';
          break;
        case 3:
          starClassNamePostfix = 'dark';
          break;
        case 4:
          starClassNamePostfix = 'darker';
          break;
        default:
          starClassNamePostfix = '';
      }

      return starClassNamePostfix;
    },
  },
});

When using switch case in methods with configured vue/script-indent param, eslint-plugin-vue falsely reports wrong indentation inside it as seen here:

eslint-vue-indent

However, when changing indentation to that considered proper one by vue/script-indent (which is actually wrong), 'native' indent ESLint rule comes in:

eslint-indent

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions