我正在尝试为我的项目设置命名约定。
我在snake_case
中有一些变量,希望ESLint向我发出警告,例如:
const { order_id } = req.params;
我已删除typescript-eslint/camelcase
,因为它已过时,并尝试设置naming-convention
并为布尔值添加了新的error
规则。
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'variable',
types: ['boolean'],
format: ['PascalCase'],
prefix: ['is', 'should', 'has', 'can', 'did', 'will'],
},
],
如何为snake_case
变量添加警告?
答案 0 :(得分:2)
如果您想让ESLint警告您驼峰式变量中没有的变量名,它就很简单:
"@typescript-eslint/naming-convention": [
"warn",
{
selector: "variable",
format: ["camelCase"]
},
],
VS代码中显示的相应警告: