没有找到ESLint配置错误

50

最近我们升级到 ESLint 3.0.0 并在运行 grunt eslint 任务时接收到以下信息:

> $ grunt eslint
Running "eslint:files" (eslint) task
Warning: No ESLint configuration found. Use --force to continue.

这里是 grunt-eslint 的配置:

var lintTargets = [
    "<%= app.src %>/**/*/!(*test|swfobject)+(.js)",
    "test/e2e/**/*/*.js",
    "!test/e2e/db/models/*.js"
];
module.exports.tasks = {
    eslint: {
        files: {
            options: {
                config: 'eslint.json',
                fix: true,
                rulesdir: ['eslint_rules']
            },
            src: lintTargets
        }
    }
};

我们应该怎么做来修复这个错误?

11个回答

49

我遇到了同样的错误。看起来需要进行配置。

前往您的项目根目录并在终端中运行

./node_modules/.bin/eslint --init

我还需要将Node更新到v12才能使其正常工作。 - patricksurry
在Windows上运行node_modules\.bin\eslint --init - Jarad
你可以使用这个代替:npm init @eslint/config - undefined

46

你面对的错误是因为你的配置文件不存在。 要配置eslint,请输入

eslint --init

然后按照你的需求进行配置。

最后再次执行项目。


从根目录执行此命令将会出现bash: eslint: command not found的错误提示。值得一提的是,该命令应该从/node_modules/.bin目录下执行。 - undefined

30

尝试将config替换为configFile。然后:

  1. 创建eslint.json文件并
  2. 指定其正确位置(相对于Gruntfile.js文件)
  3. 在该文件(eslint.json)中放置一些配置,例如:

.

{
    "rules": {
        "eqeqeq": "off",
        "curly": "warn",
        "quotes": ["warn", "double"]
    }
}

获取更多示例,请前往此处


2
是的,configFile 也起作用了。看起来我们一直在使用 config,但它没有任何效果,只是因为 eslint 2 默认搜索它而已。现在我们已经迁移到 eslint 3 并且默认配置文件名已更改,eslint 不会自动找到配置文件,这表明我们应该从一开始就使用 configFile。这是我现在的理论。谢谢! - alecxe
1
不用谢。我最近刚解决了配置问题,所以避免了旧系统的问题。 - Arkadiusz Lendzian

16

我遇到了与 Gulp 和运行“gulp-eslint”: "^3.0.1" 版本相同的问题。我不得不在 Gulp 任务中将 config: 重命名为 configFile。

.pipe(lint({configFile: 'eslint.json'}))

8

对于遇到同样问题的人,这是我们如何解决它的方法。

按照Requiring Configuration to Run迁移过程,我们不得不eslint.json重命名为.eslintrc.json,这是现在默认的ESLint配置文件名称之一。

我们还删除了config grunt-eslint选项。


3
在根目录下创建一个名为.eslintrc.json的新文件:
 {
    "parserOptions": {
         "ecmaVersion": 6,
         "sourceType": "module",
         "ecmaFeatures": {
             "jsx": true
         }
    },
    "rules": {
        "semi": "error"
    }
}

2

Webpack

我在项目根目录添加了eslint.rc文件,但是仍然遇到错误。
解决方案是将"eslint-loader"规则配置中的exclude属性添加进去:

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: "eslint-loader",
        options: {
          // eslint options (if necessary)
        }
      },
    ],
  },
  // ...
}

2

只需按照以下步骤操作:
1.创建名为eslintrc.json的eslint配置文件。
2.将以下代码放置在文件中即可。

gulp.src(jsFiles)
        // eslint() attaches the lint output to the "eslint" property
        // of the file object so it can be used by other modules.
        .pipe(eslint({configFile: 'eslintrc.json'}))
        // eslint.format() outputs the lint results to the console.
        // Alternatively use eslint.formatEach() (see Docs).
        .pipe(eslint.format())
        // To have the process exit with an error code (1) on
        // lint error, return the stream and pipe to failAfterError last.
        .pipe(eslint.failAfterError());

2
今天我们遇到了这个问题,并意识到问题并不是由我们正在工作的项目引起的,而是由我们使用命令链接的一个包内部引起的:
yarn link

这是一个经常用于测试新功能或在另一个项目中出现问题时进行调试的功能。

我们通过删除链接或在ember.js中禁用插件包的开发者模式来解决这个问题。

index.js

module.exports = {
    isDevelopingAddon: function() {
      return false;
    },
    ...
}

1

运行命令 ember init。 当它询问是否覆盖现有文件时,请键入 n 以跳过覆盖文件。 现在,它将自动创建所需的文件,例如 .eslintrc 等。

对我来说,当我将文件夹复制到另一个系统中(除了 dist、dist_production 和 node_modules 文件夹),并尝试运行 ember build 时出现了相同的问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接