首页 > 解决方案 > 使用覆盖在 ESLint 配置中设置文件扩展名

问题描述

我试图通过overrides在配置中设置而不是需要使用--ext命令行标志来指定 ESLint 应该检查的文件扩展名。文档说:

默认情况下,ESLint 会检查*.js文件以及与overrides配置条目匹配的文件。

for的文档overrides说,glob 模式files可以遵循 "src/*.js"or"**/*.js"并且这些是相对于您的 ESLint 配置文件的基本目录的。这些选项都不适用于我使 ESLint 进程文件超出默认值*.js(在我的情况下*.jsx)。

这是我运行 ESLint 时的输出--ext

scott@dev /home/scott/project (main)
$ npx eslint --ext .js,.jsx ./src

/home/scott/project/src/file.jsx
  1:1  warning  Unexpected console statement  no-console

✖ 1 problem (0 errors, 1 warning)

正如预期的那样,它会产生一个警告。但是没有--ext,ESLint 不会产生任何输出。

目录结构:

/home/scott/project/
  .eslintrc.js
  src/
      file.jsx

.eslintrc.js

const rules = {
    // ...
};

module.exports = {
    // ...
    overrides: [
        {
          files: [ "*.jsx" ], // also doesn't work with "src/**/*.jsx", "**/*.jsx"
          rules: rules
        }
    ],
    rules: rules
};

我需要做什么?

标签: javascripteslint

解决方案


推荐阅读