我需要为我的 Ember 5.8 项目自定义 linting 规则。 Ember 5.8 使用 ESLint 8.57,ESLint 允许通过插件自定义规则,请参阅本教程。 该教程的第8步内容如下:
您可能想在以下场景之一使用本地定义的插件:
- 您想使用插件,但不想将其发布到 npm。
这就是我想要的:本地的,而不是发布的。但为了使其工作,我必须引入 ESLint 插件作为 npm 的本地依赖项,这在教程中没有提及,但在 here 进行了描述(基于 here):
{
// ...
"devDependencies": {
// ...
"eslint-plugin-acme": "file:./config/eslint"
}
}
“有效”的意思是“
npm install
拾取它”和“npm run lint
按预期工作”。
但是:它对 Ember 不起作用:
npx ember build
抛出
Missing npm packages:
Package: eslint-plugin-acme
* Specified: file:./config/eslint
* Installed: (not installed)
Run `npm install` to install missing dependencies.
Stack Trace and Error Report: /tmp/error.dump.8b24e5db90b94e60ef96136863733d8a.log
An error occurred in the constructor for ember-cli-dependency-checker at /home/crusy/code/acme/frontend/node_modules/ember-cli-dependency-checker
有什么问题吗?再次强调,
npm install
有效,为什么 ember-cli-dependency-checker
推荐它?
好吧,虽然
npm install
看起来很高兴,但我必须在package.json
上添加一个./config/eslint
:
{
"name": "eslint-plugin-acme",
"version": "1.0.0",
"author": "crusy"
}
并链接它:
npm link ./config/eslint/ --save
。现在 npx ember build
也可以工作了。