[英]How to get local eslint plugins to work with locally installed eslint
According to the docs plugins should work if they are npm modules named "eslint-plugin-" 根据文档插件应该工作,如果他们是名为“eslint-plugin-”的npm模块
Here's a plugin that follows that pattern . 这是一个遵循该模式的插件 。 Source is here .
来源就在这里 。
So, we make a new project 所以,我们制作了一个新项目
md foo
cd foo
npm init
... answer questions ..
npm install --save-dev eslint
npm install --save-dev eslint-plugin-require
echo "define(function(){});" > test.js
echo "{\"rules\":{\"require\": 2}}" > conf.json
node node_modules/eslint/bin/eslint.js -c conf.json --plugin eslint-plugin-require test.js
produces 产生
~/node_modules/eslint/lib/eslint.js:569
throw new Error("Definition for rule '" + key + "' was not
^
Error: Definition for rule 'require' was not found.
change the config to 将配置更改为
echo "{\"rules\":{\"eslint-plugin-require\": 2}}" > conf.json
nor 也不
echo "{\"rules\":{\"require-define\": 2}}" > conf.json
nor 也不
echo "{\"rules\":{\"require-require-define\": 2}}" > conf.json
nor 也不
echo "{\"rules\":{\"eslint-plugin-require-define\": 2}}" > conf.json
nor 也不
echo "{\"rules\":{\"eslint-plugin-require-require-define\": 2}}" > conf.json
does not fix it 不解决它
How do I use locally installed eslint plugins? 如何使用本地安装的eslint插件?
It is fairly simple to use local plugins with a local eslint install, just not immediately obvious at first. 使用带有本地eslint安装的本地插件非常简单,起初并不是很明显。
1. Install 1.安装
Nothing different here from what you're already doing. 这与你正在做的事情没有什么不同。
npm install --save-dev eslint
npm install --save-dev eslint-plugin-require
2. Configure 2.配置
I'm using a .eslintrc
file in my case, but the same principle should apply if you're passing a custom config file to the CLI. 我在我的案例中使用的是
.eslintrc
文件,但如果您将自定义配置文件传递给CLI,则应遵循相同的原则。 Note the difference in how rules are defined when it's a plugin. 注意当插件是规则时如何定义规则的区别。
{
"plugins": [
// Tell eslint about the require plugin
"require"
],
"rules": {
// Built-in Rules
"camelcase": 2,
"no-trailing-spaces": 2,
// Require Plugin Rules (note plugin prefix)
"require/require-define": 2,
"require/require-array-syntax": 2,
"require/require-module-prefix": 2
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.