[英]How can I add ESLInt custom rules directory to VSCode
我正在使用 ESLint 插件运行 VSCode。 我的项目包含一些自定义规则,它们位于特定目录中。
如果我从命令行运行 ESLint 并传入--rulesdir=./custom-eslint-rules
一切都按预期工作。
但是,我特别指的是编辑器本身中每个文件发生的 linting。 在那里,它使用正常规则进行检查,但显示错误,我的自定义规则的定义丢失了。
我如何配置 VSCode,以便每个文件 linting 看到我在特定目录中的自定义规则定义?
在您的 setting.json 中:
"eslint.options": {
"rulePaths": "<path>"
}
参考: https : //eslint.org/docs/developer-guide/nodejs-api#cliengine
有没有办法传递额外的参数来忽略我的自定义规则目录中的某些文件。 就我而言,我在与自定义规则相同的目录中有测试文件(.spec.js)。 我想忽略eslint.options.rulePaths
这个测试文件。
eslint-plugin-rulesdir@0.2.1
yarn add --dev eslint-plugin-rulesdir@0.2.1
const rulesDirPlugin = require("eslint-plugin-rulesdir");
rulesDirPlugin.RULES_DIR = "src/rules"; // it is example
plugins: [...,"rulesdir"]
rules: {
...,
"rulesdir/no-get-payments": "error"
}
module.exports = {
create: function (context) {
return {
CallExpression: function (node) {
if (node.callee.name === "getPayments") {
context.report({
node: node,
message: "getPayments is depricated! ",
});
}
},
};
},
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.