首页 > 解决方案 > @typescript-eslint/naming-convention:如何混合错误和警告规则?

问题描述

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

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

标签: typescripteslint

解决方案


如果您希望 ESLint 警告您有关不在 camelCase 中的变量名称,它很简单:

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

VS Code 中显示的相应警告:

在此处输入图像描述


推荐阅读