我有以下的eslintrc.js
module.exports = {
extends: ['airbnb-typescript/base'],
parserOptions: {
project: './tsconfig.json',
sourceType: 'module',
},
ignorePatterns: ['*.js'],
rules: {
'no-underscore-dangle': 0,
...
}
};我想在allow: [ /** */ ]中加入一些例外。但是每次我将其作为key: value属性添加到我的文件中时,ESLint都会返回一个错误,其中包含以下文本:unable to use allow on top level。那么问题是,如何在允许的情况下取得这样的结果呢?
长话短说,我无法使用带有MongoDB _id命名的规则集,所以在变量命名中,ESLint只能忽略_id,而不是禁用命名约定规则本身。
有办法解决这个问题吗?
发布于 2022-06-08 12:00:47
它适用于我:
"no-underscore-dangle": ["error", { allow: ["_id"] }]如果您使用的是@typescript-eslint/naming-convention规则,您可能还需要添加以下内容:
"@typescript-eslint/naming-convention": [
"error",
{
selector: ["variable"],
format: ["strictCamelCase", "PascalCase", "UPPER_CASE"],
filter: {
regex: "^_id$",
match: false,
},
},
],https://stackoverflow.com/questions/68563727
复制相似问题