I need to write an Angular Typescript rule to warn people if they utilize certain 'keywords/phrases'. For example, if keyword "Birthdate" or "SSN" is in the source file directly, it should give a warning.
How would someone write this rule to restrict words using ESLint?
Trying to research currently, did not see any articles in Stackoverflow article search archive,
Curious how to manipulate example code below or (open to any other solutions),
I applied the following below "id-blacklist": ["SSN","Birthdate"], receiving error
module.exports = {
"env": {
"browser": true,
"es6": true
},
"extends": [
"eslint:remended",
"plugin:@typescript-eslint/eslint-remended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"id-blacklist": ["SSN","Birthdate"]
}
};
Error:
Configuration for rule "id-blacklist" is invalid:Severity should be one of the following: 0 = off, 1 = warn, 2 = error
Other Resources:
/
/@andrey.igorevich.borisov/writing-custom-tslint-rules-from-scratch-62e7f0237124
I need to write an Angular Typescript rule to warn people if they utilize certain 'keywords/phrases'. For example, if keyword "Birthdate" or "SSN" is in the source file directly, it should give a warning.
How would someone write this rule to restrict words using ESLint?
Trying to research currently, did not see any articles in Stackoverflow article search archive,
Curious how to manipulate example code below or (open to any other solutions),
I applied the following below "id-blacklist": ["SSN","Birthdate"], receiving error
https://eslint/docs/rules/id-blacklist
module.exports = {
"env": {
"browser": true,
"es6": true
},
"extends": [
"eslint:remended",
"plugin:@typescript-eslint/eslint-remended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"id-blacklist": ["SSN","Birthdate"]
}
};
Error:
Configuration for rule "id-blacklist" is invalid:Severity should be one of the following: 0 = off, 1 = warn, 2 = error
Other Resources:
https://rangle.io/blog/custom-tslint-for-angular/
https://medium./@andrey.igorevich.borisov/writing-custom-tslint-rules-from-scratch-62e7f0237124
Share Improve this question edited Dec 16, 2019 at 23:24 asked Dec 16, 2019 at 19:29 user10126227user10126227 2- Hmm... don't you think a git pre-mit hook might be a better alternative? And isn't TSLint deprecated? – Jared Smith Commented Dec 16, 2019 at 19:31
- hi @JaredSmith we already have existing examples of this in our code, want to flag as warnings – user10126227 Commented Dec 16, 2019 at 19:32
2 Answers
Reset to default 2I did it with pipeline check but you can with pre-mit as shown here: Is it possible to ban a list of words with ESlint or anything else when pre-mit?
and you can do it with ESlint [TSlint is deprecated] like this: https://eslint/docs/rules/id-blacklist
'no-restricted-syntax': [
'error',
'Literal[value=/^(special|zzz|xxx)$/i]',
'BinaryExpression[right.value = /^(special|zzz|xxx)$/i]',
],
This rule is work for me, my requirement is we don't want some key will be hard code in repo.
It will show error if your code like below:
const t = {
pp: 'special',
};
const tt = 'special',
const f = (arg) => {
return arg === 'special';
}
function ff(arg) {
return arg === 'special';
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745299742a4621363.html
评论列表(0条)