Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement variable-name rule converter (#222)
* Implement variable-name converter * Feedback changes * Add more test cases * Set const values to improve readability and order converters rules * Optimize rules array on variable name
- Loading branch information
1 parent
6ae5bb7
commit bd694e7
Showing
3 changed files
with
445 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,331 @@ | ||
import { | ||
convertVariableName, | ||
IgnoreLeadingTrailingUnderscoreMsg, | ||
ForbiddenLeadingTrailingIdentifierMsg, | ||
IgnoreLeadingTrailingIdentifierMsg, | ||
ForbiddenPascalSnakeMsg, | ||
ConstRequiredForAllCapsMsg, | ||
IgnoreOnlyLeadingUnderscoreMsg, | ||
IgnoreOnlyTrailingUnderscoreMsg, | ||
} from "../variable-name"; | ||
|
||
describe(convertVariableName, () => { | ||
test("conversion without arguments", () => { | ||
const result = convertVariableName({ | ||
ruleArguments: [], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "camelcase", | ||
notices: [IgnoreLeadingTrailingUnderscoreMsg], | ||
}, | ||
{ | ||
ruleName: "no-underscore-dangle", | ||
ruleArguments: [], | ||
notices: [ForbiddenLeadingTrailingIdentifierMsg], | ||
}, | ||
{ | ||
ruleName: "id-blacklist", | ||
ruleArguments: [], | ||
}, | ||
{ | ||
ruleName: "id-match", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test("conversion with require-const-for-all-caps argument", () => { | ||
const result = convertVariableName({ | ||
ruleArguments: ["require-const-for-all-caps"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "camelcase", | ||
notices: [IgnoreLeadingTrailingUnderscoreMsg, ConstRequiredForAllCapsMsg], | ||
}, | ||
{ | ||
ruleName: "no-underscore-dangle", | ||
ruleArguments: [], | ||
notices: [ForbiddenLeadingTrailingIdentifierMsg], | ||
}, | ||
{ | ||
ruleName: "id-blacklist", | ||
ruleArguments: [], | ||
}, | ||
{ | ||
ruleName: "id-match", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test("conversion with allow-pascal-case argument", () => { | ||
const result = convertVariableName({ | ||
ruleArguments: ["allow-pascal-case"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "camelcase", | ||
notices: [IgnoreLeadingTrailingUnderscoreMsg, ForbiddenPascalSnakeMsg], | ||
}, | ||
{ | ||
ruleName: "no-underscore-dangle", | ||
ruleArguments: [], | ||
notices: [ForbiddenLeadingTrailingIdentifierMsg], | ||
}, | ||
{ | ||
ruleName: "id-blacklist", | ||
ruleArguments: [], | ||
}, | ||
{ | ||
ruleName: "id-match", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test("conversion with allow-snake-case argument", () => { | ||
const result = convertVariableName({ | ||
ruleArguments: ["allow-snake-case"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "camelcase", | ||
notices: [IgnoreLeadingTrailingUnderscoreMsg, ForbiddenPascalSnakeMsg], | ||
}, | ||
{ | ||
ruleName: "no-underscore-dangle", | ||
ruleArguments: [], | ||
notices: [ForbiddenLeadingTrailingIdentifierMsg], | ||
}, | ||
{ | ||
ruleName: "id-blacklist", | ||
ruleArguments: [], | ||
}, | ||
{ | ||
ruleName: "id-match", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test("conversion with allow-leading-underscore without check-format argument", () => { | ||
const result = convertVariableName({ | ||
ruleArguments: ["allow-leading-underscore"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "camelcase", | ||
notices: [IgnoreLeadingTrailingUnderscoreMsg], | ||
}, | ||
{ | ||
ruleName: "no-underscore-dangle", | ||
ruleArguments: [], | ||
notices: [ForbiddenLeadingTrailingIdentifierMsg], | ||
}, | ||
{ | ||
ruleName: "id-blacklist", | ||
ruleArguments: [], | ||
}, | ||
{ | ||
ruleName: "id-match", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test("conversion with allow-trailing-underscore without check-format argument", () => { | ||
const result = convertVariableName({ | ||
ruleArguments: ["allow-trailing-underscore"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "camelcase", | ||
notices: [IgnoreLeadingTrailingUnderscoreMsg], | ||
}, | ||
{ | ||
ruleName: "no-underscore-dangle", | ||
ruleArguments: [], | ||
notices: [ForbiddenLeadingTrailingIdentifierMsg], | ||
}, | ||
{ | ||
ruleName: "id-blacklist", | ||
ruleArguments: [], | ||
}, | ||
{ | ||
ruleName: "id-match", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test("conversion with check-format argument", () => { | ||
const result = convertVariableName({ | ||
ruleArguments: ["check-format"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "camelcase", | ||
notices: [IgnoreLeadingTrailingUnderscoreMsg], | ||
}, | ||
{ | ||
ruleName: "no-underscore-dangle", | ||
ruleArguments: [], | ||
notices: [ForbiddenLeadingTrailingIdentifierMsg], | ||
}, | ||
{ | ||
ruleName: "id-blacklist", | ||
ruleArguments: [], | ||
}, | ||
{ | ||
ruleName: "id-match", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test("conversion with allow-leading-underscore and check-format argument", () => { | ||
const result = convertVariableName({ | ||
ruleArguments: ["check-format", "allow-leading-underscore"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "camelcase", | ||
notices: [IgnoreOnlyLeadingUnderscoreMsg], | ||
}, | ||
{ | ||
ruleName: "no-underscore-dangle", | ||
ruleArguments: ["off"], | ||
notices: [IgnoreLeadingTrailingIdentifierMsg], | ||
}, | ||
{ | ||
ruleName: "id-blacklist", | ||
ruleArguments: [], | ||
}, | ||
{ | ||
ruleName: "id-match", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test("conversion with allow-trailing-underscore and check-format argument", () => { | ||
const result = convertVariableName({ | ||
ruleArguments: ["check-format", "allow-trailing-underscore"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "camelcase", | ||
notices: [IgnoreOnlyTrailingUnderscoreMsg], | ||
}, | ||
{ | ||
ruleName: "no-underscore-dangle", | ||
ruleArguments: ["off"], | ||
notices: [IgnoreLeadingTrailingIdentifierMsg], | ||
}, | ||
{ | ||
ruleName: "id-blacklist", | ||
ruleArguments: [], | ||
}, | ||
{ | ||
ruleName: "id-match", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test("conversion with allow-leading-underscore, allow-trailing-underscore and check-format argument", () => { | ||
const result = convertVariableName({ | ||
ruleArguments: [ | ||
"check-format", | ||
"allow-leading-underscore", | ||
"allow-trailing-underscore", | ||
], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "camelcase", | ||
notices: [], | ||
}, | ||
{ | ||
ruleName: "no-underscore-dangle", | ||
ruleArguments: ["off"], | ||
notices: [IgnoreLeadingTrailingIdentifierMsg], | ||
}, | ||
{ | ||
ruleName: "id-blacklist", | ||
ruleArguments: [], | ||
}, | ||
{ | ||
ruleName: "id-match", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test("conversion with all arguments", () => { | ||
const result = convertVariableName({ | ||
ruleArguments: [ | ||
"check-format", | ||
"allow-leading-underscore", | ||
"allow-pascal-case", | ||
"allow-snake-case", | ||
"allow-trailing-underscore", | ||
"require-const-for-all-caps", | ||
"ban-keywords", | ||
], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "camelcase", | ||
notices: [ConstRequiredForAllCapsMsg, ForbiddenPascalSnakeMsg], | ||
}, | ||
{ | ||
ruleName: "no-underscore-dangle", | ||
ruleArguments: ["off"], | ||
notices: [IgnoreLeadingTrailingIdentifierMsg], | ||
}, | ||
{ | ||
ruleName: "id-blacklist", | ||
ruleArguments: [ | ||
"any", | ||
"Number", | ||
"number", | ||
"String", | ||
"string", | ||
"Boolean", | ||
"boolean", | ||
"Undefined", | ||
"undefined", | ||
], | ||
}, | ||
{ | ||
ruleName: "id-match", | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.