[英]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.