简体   繁体   English

vue 和 eslint 仅对更改的文件进行 linting

[英]vue and eslint is only linting changed files

We are using vue-cli with the eslint plugin and we have an.eslintrc config like this:我们将 vue-cli 与 eslint 插件一起使用,并且我们有一个 .eslintrc 配置,如下所示:

const devOff = process.env.NODE_ENV === 'production' ? 'error' : 'warn';

module.exports = {
  root: true,
  env: {
    node: true
  },
  'extends': [
    'plugin:vue/essential',
    "eslint:recommended"
  ],
  rules: {
    'no-console': devOff,
  },
  parserOptions: {
    parser: 'babel-eslint'
  }
};

When we run npm run build the first time we get an error and that's fine as eslint should report errors when building for production.当我们运行npm run build时,我们得到一个错误,这很好,因为 eslint 应该在构建生产时报告错误。

warning: Unexpected console statement (no-console)...警告:意外的控制台语句(无控制台)...

When we run npm run build again without changing anything, the build runs fine.当我们运行npm run build而不更改任何内容时,构建运行良好。 It seems to me eslint is caching already parsed files regardless of having errors or not.在我看来,eslint 正在缓存已经解析的文件,无论是否有错误。

I found the CLI optin --cache in the eslint guide but I couldn't manage to set this option in vue.config.js nor.eslintrc.js我在eslint 指南中找到了 CLI optin --cache 但我无法在 vue.config.js nor.eslintrc.js 中设置此选项

How can I set up vue/eslint to fail repeatedly the production build if we have any linting errors in any file.如果我们在任何文件中有任何 linting 错误,我如何设置 vue/eslint 以使生产构建反复失败。

This is how I solve this issue in all my projects:这就是我在所有项目中解决此问题的方法:

// vue.config.js
module.exports =
{
  chainWebpack: config =>
  {
    config.module.rule('eslint').use('eslint-loader').loader('eslint-loader').tap(options =>
    {
      delete options.cacheIdentifier;
      options.cache = false; // otherwise on each restart cached errors won't be shown !!!
      return options;
    });
    config.module.rule('vue').use('vue-loader').loader('vue-loader').tap(options =>
    {
      delete options.cacheDirectory;
      return options;
    });
    config.module.rule('vue').uses.delete('cache-loader');
    config.module.rule('js').uses.delete('cache-loader');
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM