[英]How to use allow: options with eslintrc.js
I am having the following eslintrc.js
:我有以下
eslintrc.js
:
module.exports = {
extends: ['airbnb-typescript/base'],
parserOptions: {
project: './tsconfig.json',
sourceType: 'module',
},
ignorePatterns: ['*.js'],
rules: {
'no-underscore-dangle': 0,
...
}
};
And I'd like to include some exceptions with allow: [ /** */ ]
.我想包括一些例外情况
allow: [ /** */ ]
。 But each time when I am adding this as a key: value property in my file, ESLint returns me an error with the following text: unable to use allow on top level
.但是每次当我在我的文件中将其添加为 key: value 属性时,ESLint 都会返回一个错误,并显示以下文本:
unable to use allow on top level
。 So the question is, how to achieve such results, with allow?那么问题来了,如何通过allow实现这样的结果?
Long story short, I am unable to use my set of rules with MongoDB _id
naming, so I have ESLint just to ignore only _id
in variable naming, instead of disabling the naming-convention rule itself.长话短说,我无法将我的规则集与 MongoDB
_id
命名一起使用,所以我有 ESLint 只是为了忽略变量命名中的_id
,而不是禁用命名约定规则本身。
Is there any way to solve this problem?有没有办法解决这个问题?
It works for me:这个对我有用:
"no-underscore-dangle": ["error", { allow: ["_id"] }]
If you are using the @typescript-eslint/naming-convention
rule, you may also need to add this:如果您使用的是
@typescript-eslint/naming-convention
规则,您可能还需要添加以下内容:
"@typescript-eslint/naming-convention": [
"error",
{
selector: ["variable"],
format: ["strictCamelCase", "PascalCase", "UPPER_CASE"],
filter: {
regex: "^_id$",
match: false,
},
},
],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.