Skip to content

fix: [variable-name] Use id-denylist ESLint rule instread of id-blacklist that deprecated #1221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe(convertVariableName, () => {
ruleName: "no-underscore-dangle",
},
{
ruleName: "id-blacklist",
ruleName: "id-denylist",
},
{
ruleName: "id-match",
Expand Down Expand Up @@ -61,7 +61,7 @@ describe(convertVariableName, () => {
ruleName: "no-underscore-dangle",
},
{
ruleName: "id-blacklist",
ruleName: "id-denylist",
},
{
ruleName: "id-match",
Expand Down Expand Up @@ -93,7 +93,7 @@ describe(convertVariableName, () => {
ruleName: "no-underscore-dangle",
},
{
ruleName: "id-blacklist",
ruleName: "id-denylist",
},
{
ruleName: "id-match",
Expand Down Expand Up @@ -125,7 +125,7 @@ describe(convertVariableName, () => {
ruleName: "no-underscore-dangle",
},
{
ruleName: "id-blacklist",
ruleName: "id-denylist",
},
{
ruleName: "id-match",
Expand Down Expand Up @@ -157,7 +157,7 @@ describe(convertVariableName, () => {
notices: [ForbiddenLeadingTrailingIdentifierMsg],
},
{
ruleName: "id-blacklist",
ruleName: "id-denylist",
},
{
ruleName: "id-match",
Expand Down Expand Up @@ -189,7 +189,7 @@ describe(convertVariableName, () => {
ruleName: "no-underscore-dangle",
},
{
ruleName: "id-blacklist",
ruleName: "id-denylist",
},
{
ruleName: "id-match",
Expand Down Expand Up @@ -221,7 +221,7 @@ describe(convertVariableName, () => {
ruleName: "no-underscore-dangle",
},
{
ruleName: "id-blacklist",
ruleName: "id-denylist",
},
{
ruleName: "id-match",
Expand Down Expand Up @@ -254,7 +254,7 @@ describe(convertVariableName, () => {
ruleName: "no-underscore-dangle",
},
{
ruleName: "id-blacklist",
ruleName: "id-denylist",
},
{
ruleName: "id-match",
Expand Down Expand Up @@ -287,7 +287,7 @@ describe(convertVariableName, () => {
ruleSeverity: "off",
},
{
ruleName: "id-blacklist",
ruleName: "id-denylist",
},
{
ruleName: "id-match",
Expand Down Expand Up @@ -320,7 +320,7 @@ describe(convertVariableName, () => {
ruleSeverity: "off",
},
{
ruleName: "id-blacklist",
ruleName: "id-denylist",
},
{
ruleName: "id-match",
Expand Down Expand Up @@ -357,7 +357,7 @@ describe(convertVariableName, () => {
ruleSeverity: "off",
},
{
ruleName: "id-blacklist",
ruleName: "id-denylist",
},
{
ruleName: "id-match",
Expand Down Expand Up @@ -399,7 +399,7 @@ describe(convertVariableName, () => {
ruleSeverity: "off",
},
{
ruleName: "id-blacklist",
ruleName: "id-denylist",
ruleArguments: [
"any",
"Number",
Expand Down
40 changes: 23 additions & 17 deletions src/converters/lintConfigs/rules/ruleConverters/variable-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ export const convertVariableName: RuleConverter = (tslintRule) => {
const constRequiredForAllCaps = tslintRule.ruleArguments.includes("require-const-for-all-caps");
const allowPascalCase = tslintRule.ruleArguments.includes("allow-pascal-case");
const allowSnakeCase = tslintRule.ruleArguments.includes("allow-snake-case");
/**
* disallows the use of certain TypeScript keywords as variable or parameter names.
* @see https://palantir.github.io/tslint/rules/variable-name/
* @see https://github.com/palantir/tslint/blob/285fc1db18d1fd24680d6a2282c6445abf1566ee/src/rules/variableNameRule.ts#L26-L36
*/
const banKeywords = [
"any",
"Number",
"number",
"String",
"string",
"Boolean",
"boolean",
"Undefined",
"undefined",
];

const getCamelCaseRuleOptions = () => {
const camelCaseRules: Record<string, unknown>[] = [];
Expand Down Expand Up @@ -77,34 +93,24 @@ export const convertVariableName: RuleConverter = (tslintRule) => {
};
};

const getBlackListRuleOptions = () => {
const blackListOptionArguments = tslintRule.ruleArguments.includes("ban-keywords")
? [
"any",
"Number",
"number",
"String",
"string",
"Boolean",
"boolean",
"Undefined",
"undefined",
]
const getDenyListRuleOptions = () => {
const denyListOptionArguments = tslintRule.ruleArguments.includes("ban-keywords")
? banKeywords
: [];

return {
...(blackListOptionArguments.length !== 0 && {
ruleArguments: blackListOptionArguments,
...(denyListOptionArguments.length !== 0 && {
ruleArguments: denyListOptionArguments,
}),
ruleName: "id-blacklist",
ruleName: "id-denylist",
};
};

return {
rules: [
getCamelCaseRuleOptions(),
getUnderscoreDangleRuleOptions(),
getBlackListRuleOptions(),
getDenyListRuleOptions(),
{
ruleName: "id-match",
},
Expand Down