我正在为一个打字项目设置eslint。
这是在重构情况下未使用变量的规则
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"ignoreRestSiblings": true,
"destructuredArrayIgnorePattern": "^_"
}
],
//ex:
// error lint
const [a, b] = ['a', 'b']
console.log(b)
// ok
const [_a, b] = ['a', 'b']
console.log(b)
但是@typescript-eslint/naming-convention
规则触发了一个错误。我没有在规则中指定它,但我认为它是通过插件“@typescript-eslint”添加的,我不想删除它。
我怎样才能使一条规则不干扰另一条规则呢?或者怎样使用这两条规则
1条答案
按热度按时间pcww981p1#
@typescript-eslint/naming-convention
在typescript-eslint
自带的任何配置中通常都是默认不启用的。如果在配置中设置了它,则必须扩展其他一些启用它的配置。对于您的特定示例,您可以跳过数组解构模式中的特定元素,只需在元素所在的位置放置一个逗号即可。请参见Destructuring assignment中的以下示例:
或者在您的情况下:
然而,更一般地说,如果你确实想在一个未使用的变量前面加上下划线,
@typescript-eslint/naming-convention
规则中有一个选项可以实现。根据自己的需要进行调整。您可以将其用于变量以外的其他类型,或者不必使用"严格"的驼峰式大小写(与camelCase相同,但不允许连续大写[即myId有效,但myID无效]),或者您可以允许下划线,但不一定是必需的。