ESLint 规则排除 Angular 中的某些关键字和短语?

ESLint Rule to Exclude Certain Keywords and Phrases in Angular?

我需要编写一个 Angular Typescript 规则来警告人们是否使用某些 'keywords/phrases'。 比如关键字"Birthdate"或"SSN"直接在源文件中,应该给出警告。

如何使用 ESLint 编写此规则来限制单词?

目前正在尝试研究,在 Whosebug 文章搜索存档中没有看到任何文章,

想知道如何操作下面的示例代码或(对任何其他解决方案开放),

我在下面应用了以下内容 "id-blacklist": ["SSN","Birthdate"], 接收错误

https://eslint.org/docs/rules/id-blacklist

module.exports = {
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:@typescript-eslint/eslint-recommended"
    ],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    "plugins": [
        "@typescript-eslint"
    ],
    "rules": {
        "id-blacklist": ["SSN","Birthdate"]
    }
};

错误:

Configuration for rule "id-blacklist" is invalid:Severity should be one of the following: 0 = off, 1 = warn, 2 = error

其他资源:

https://rangle.io/blog/custom-tslint-for-angular/

https://medium.com/@andrey.igorevich.borisov/writing-custom-tslint-rules-from-scratch-62e7f0237124

我是通过管道检查完成的,但您可以使用预提交,如下所示:

你可以用 ESlint [TSlint is deprecated] 这样做: https://eslint.org/docs/rules/id-blacklist

'no-restricted-syntax': [
      'error',
      'Literal[value=/^(special|zzz|xxx)$/i]',
      'BinaryExpression[right.value = /^(special|zzz|xxx)$/i]',
    ],

这条规则对我有用,我的要求是我们不希望某些密钥在 repo 中被硬编码。

如果您的代码如下所示,它将显示错误:

const t = {
    pp: 'special',
};

const tt = 'special',

const f = (arg) => {
  return arg === 'special';
}

function ff(arg) {
  return arg === 'special';
}