eslint 出现问题

我有一个新插件未能通过 lint 测试:

Run if test -f .prettierrc.cjs; then
yarn run v1.22.22
$ /home/runner/work/discourse-multi-rating/discourse-multi-rating/node_modules/.bin/eslint --ext .js,.gjs,.js.es6 --no-error-on-unmatched-pattern test/javascripts assets/javascripts admin/assets/javascripts
Invalid option '--ext' - perhaps you meant '-c'?
You're using eslint.config.js, some command line flags are no longer available. Please see https://eslint.org/docs/latest/use/command-line-interface for details.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 2.

我在我的源代码树中没有看到 --ext,所以也许它在 @discourse/lint-configs/eslint)` 中?我不知道在哪里可以找到它。

我看不出我哪里做错了,或者为什么这没有影响到很多插件。 :person_shrugging:

我在自己的插件中看到了这个错误。我发现这是因为我尝试通过 eslint 迁移将 eslint 配置文件从 .eslintrc.cjs 更新到最新的扁平化配置文件格式 eslint.config.jseslint.config.js 不支持 --ext (Command Line Interface Reference - ESLint - Pluggable JavaScript Linter),因此将文件更改为旧的 .eslintrc.cjs 应该可以解决此问题。

有关如何设置 lint 文件的更多说明,请参阅 lint-configs/lint-configs at main · discourse/lint-configs · GitHub

作为一些额外的背景信息,@discourse/lint-configs 使用 eslint 8.57.0,该版本默认不使用新的扁平化配置文件 Configuration Files - ESLint - Pluggable JavaScript Linter

2 个赞

这太奇怪了。我在我的文件系统中找不到任何 eslint.confi.js(如果我信任 locate 命令的话,而且我的源代码树里肯定没有)。

你成功了吗?

哦,那很奇怪……是的,我成功让我的工作了。

我将检查 package.json,看看 devDependencies 是否有 \"eslint\": \"8.57.0\", 而不是 9.x.x。

是的。 :crying_cat_face: 我刚注意到 package.json 中的 eslint 和 prettier 被更改了。我发誓它就在一分钟前我从 skeleton 克隆下来的。 :person_shrugging:

现在它在 github 上给了我(合法的)错误,但我无法在本地运行 estlint 来修复东西。

1 个赞

Jay,

执行:

yarn

然后:

yarn eslint --fix plugins/<my-plugin>

(显然需要更新“my plugin”)

以上命令均在 discourse 目录下执行。

2 个赞

太棒了。我刚刚以一种完全无法重现的方式设法修复了它,所以这真是救命稻草。现在我已经把它添加到我的魔法文件中了,所以下次可能会奏效

if [[ "$ARG" == 'fix-eslint' ]]
then
  cd ~/src/discourse-repos/discourse
  yarn
  for x in ~/plugins/*
  do
    yarn eslint --fix x
  done
fi
2 个赞

等等。你的意思是这将把 eslint 更新到正确的版本?还是运行 eslint?或者如果我那样运行,它就是正确的版本?