@ typescript-eslint / naming-convention:如何混合错误和警告规则?

时间:2020-07-14 20:41:54

标签: typescript eslint

我正在尝试为我的项目设置命名约定。

我在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变量添加警告?

1 个答案:

答案 0 :(得分:2)

如果您想让ESLint警告您驼峰式变量中没有的变量名,它就很简单:

"@typescript-eslint/naming-convention": [
  "warn",
  {
    selector: "variable",
    format: ["camelCase"]
  },
],

VS代码中显示的相应警告:

Array.some()