【问题标题】:vue-cli linting throwing camelcase warning when the rule is disabled禁用规则时,vue-cli linting 抛出驼峰警告
【发布时间】:2019-10-22 14:43:06
【问题描述】:

我正在使用 vue-cli 构建一个应用程序,使用 airbnb 规则进行 lint。

尽管我在我的 .eslintrc.js 配置文件中添加了一条规则,并且该规则适用于其他文件,但我的 Welcome.vue 文件中的这个特定变量在 linting 时仍会发出警告。

警告:

warning: Identifier 'tables_count' is not in camel case (camelcase) at src\components\Welcome.vue:49:33:
47 |         enableAll: function enableAll() {
48 |             const tables_count = this.tables.length;
49 |             for (let i = 0; i < tables_count; i += 1) {
   |                                 ^
50 |                 this.tables[i].enabled = true;
51 |             }
52 |         },

完整的 .eslintrc.js 文件:

module.exports = {
    root: true,
    env: {
        node: true,
    },
    extends: [
        'plugin:vue/essential',
        '@vue/airbnb',
    ],
    rules: {
        'no-console': process.env.NODE_ENV === 'production' ? 'error' :     'off',
        'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
        indent: ['error', 4],
        camelcase: ['warn', { properties: 'never' }],
    },
    parserOptions: {
        parser: 'babel-eslint',
    },
};

我的应用程序结构如下:

  • App.vue
    • Welcome.vue
    • Game.vue

App.vueGame.vue 的变量都低于分数,并且 linting 不会向它们发出警告。

  • App.vue: this.show_welcome = true;
  • Game.vue: this.current_answer = '';

我做错了什么让一个特定的 Vue 文件如此冒犯 linter?!

这是当我运行 npm run servenpm run lint

注意:我以为我已经解决了,但仍然没有......

目前我只有 Welcome.vue 的单元测试,它有自己的 lint 文件,但我已经在其中添加了规则,但仍然收到警告:

测试/单元/eslintrc.js

module.exports = {
    env: {
        jest: true,
    },
    rules: {
        camelcase: ['warn', { properties: 'never' }],
    },
};

【问题讨论】:

    标签: vue.js eslint vue-cli-3 eslint-config-airbnb


    【解决方案1】:

    对于打字稿项目:

    .eslintrc.js

    {
      rules: {
        '@typescript-eslint/camelcase': 'off'
      }
    }
    

    【讨论】:

      【解决方案2】:

      如果您不想让 eslint 检查可变大小写,那么只需在您的 .eslintrc.js 中使用 camelcase: 'off' 将其关闭即可。

      【讨论】:

        猜你喜欢
        • 2018-11-17
        • 2019-05-22
        • 2020-07-21
        • 2019-04-15
        • 1970-01-01
        • 2018-09-18
        • 1970-01-01
        • 2018-03-31
        • 2019-10-16
        相关资源
        最近更新 更多