-
Notifications
You must be signed in to change notification settings - Fork 101
added semicolon rule converter plus tests #220
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
JoshuaKGoldberg
merged 5 commits into
typescript-eslint:master
from
YashdalfTheGray:semicolon
Oct 6, 2019
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aec5772
added the editor tab width for people who have their editors configur…
YashdalfTheGray 0fbc611
added the semicolon rule and some tests, plus export from converters
YashdalfTheGray 764e786
fixed an eslint issue with the build
YashdalfTheGray 4a73c46
fixed not following converter naming convention
YashdalfTheGray 996d11e
code review changes
YashdalfTheGray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,52 @@ | ||
import { RuleConverter } from "../converter"; | ||
|
||
// for reference, see here | ||
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/semi.md | ||
YashdalfTheGray marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export const convertSemicolon: RuleConverter = tslintRule => { | ||
const getMultilineDelimiter = (strategy: "always" | "never") => { | ||
if (strategy === "always") { | ||
return "semi"; | ||
} | ||
return "none"; | ||
}; | ||
|
||
const ignoreInterfaces = tslintRule.ruleArguments.includes("ignore-interfaces"); | ||
const strictBoundClassMethods = tslintRule.ruleArguments.includes("strict-bound-class-methods"); | ||
|
||
return { | ||
rules: [ | ||
{ | ||
ruleName: "@typescript-eslint/semi", | ||
ruleArguments: [tslintRule.ruleArguments[0]], | ||
}, | ||
...(ignoreInterfaces | ||
? [] | ||
: [ | ||
{ | ||
ruleName: "@typescript-estlint/member-delimiter-style", | ||
YashdalfTheGray marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ruleArguments: [ | ||
"error", | ||
{ | ||
multiline: { | ||
delimiter: getMultilineDelimiter(tslintRule.ruleArguments[0]), | ||
requireLast: true, | ||
}, | ||
singleline: { | ||
delimiter: "semi", | ||
requireLast: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
]), | ||
], | ||
notices: [ | ||
"You must disable the base rule (semi) as it can report incorrect errors.", | ||
YashdalfTheGray marked this conversation as resolved.
Show resolved
Hide resolved
|
||
...(strictBoundClassMethods | ||
? [ | ||
"Option `strict-bound-class-methods` was found, there is no exact equivalent yet supported.", | ||
] | ||
: []), | ||
], | ||
}; | ||
}; |
This file contains hidden or 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,207 @@ | ||
import { convertSemicolon } from "../semicolon"; | ||
|
||
describe(convertSemicolon, () => { | ||
test("conversion with always", () => { | ||
const result = convertSemicolon({ | ||
ruleArguments: ["always"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "@typescript-eslint/semi", | ||
ruleArguments: ["always"], | ||
}, | ||
{ | ||
ruleName: "@typescript-estlint/member-delimiter-style", | ||
ruleArguments: [ | ||
"error", | ||
{ | ||
multiline: { | ||
delimiter: "semi", | ||
requireLast: true, | ||
}, | ||
singleline: { | ||
delimiter: "semi", | ||
requireLast: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
notices: ["You must disable the base rule (semi) as it can report incorrect errors."], | ||
}); | ||
}); | ||
|
||
test("conversion with never", () => { | ||
const result = convertSemicolon({ | ||
ruleArguments: ["never"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "@typescript-eslint/semi", | ||
ruleArguments: ["never"], | ||
}, | ||
{ | ||
ruleName: "@typescript-estlint/member-delimiter-style", | ||
ruleArguments: [ | ||
"error", | ||
{ | ||
multiline: { | ||
delimiter: "none", | ||
requireLast: true, | ||
}, | ||
singleline: { | ||
delimiter: "semi", | ||
requireLast: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
notices: ["You must disable the base rule (semi) as it can report incorrect errors."], | ||
}); | ||
}); | ||
|
||
test("conversion with always and strict bound class methods", () => { | ||
const result = convertSemicolon({ | ||
ruleArguments: ["always", "strict-bound-class-methods"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "@typescript-eslint/semi", | ||
ruleArguments: ["always"], | ||
}, | ||
{ | ||
ruleName: "@typescript-estlint/member-delimiter-style", | ||
ruleArguments: [ | ||
"error", | ||
{ | ||
multiline: { | ||
delimiter: "semi", | ||
requireLast: true, | ||
}, | ||
singleline: { | ||
delimiter: "semi", | ||
requireLast: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
notices: [ | ||
"You must disable the base rule (semi) as it can report incorrect errors.", | ||
"Option `strict-bound-class-methods` was found, there is no exact equivalent yet supported.", | ||
], | ||
}); | ||
}); | ||
|
||
test("conversion with never and strict bound class methods", () => { | ||
const result = convertSemicolon({ | ||
ruleArguments: ["never", "strict-bound-class-methods"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "@typescript-eslint/semi", | ||
ruleArguments: ["never"], | ||
}, | ||
{ | ||
ruleName: "@typescript-estlint/member-delimiter-style", | ||
ruleArguments: [ | ||
"error", | ||
{ | ||
multiline: { | ||
delimiter: "none", | ||
requireLast: true, | ||
}, | ||
singleline: { | ||
delimiter: "semi", | ||
requireLast: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
notices: [ | ||
"You must disable the base rule (semi) as it can report incorrect errors.", | ||
"Option `strict-bound-class-methods` was found, there is no exact equivalent yet supported.", | ||
], | ||
}); | ||
}); | ||
|
||
test("conversion with always and ignore interfaces", () => { | ||
const result = convertSemicolon({ | ||
ruleArguments: ["always", "ignore-interfaces"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "@typescript-eslint/semi", | ||
ruleArguments: ["always"], | ||
}, | ||
], | ||
notices: ["You must disable the base rule (semi) as it can report incorrect errors."], | ||
}); | ||
}); | ||
|
||
test("conversion with never and ignore interfaces", () => { | ||
const result = convertSemicolon({ | ||
ruleArguments: ["never", "ignore-interfaces"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "@typescript-eslint/semi", | ||
ruleArguments: ["never"], | ||
}, | ||
], | ||
notices: ["You must disable the base rule (semi) as it can report incorrect errors."], | ||
}); | ||
}); | ||
|
||
test("conversion with always, strict bound class methods and ignore interfaces", () => { | ||
const result = convertSemicolon({ | ||
ruleArguments: ["always", "ignore-interfaces", "strict-bound-class-methods"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "@typescript-eslint/semi", | ||
ruleArguments: ["always"], | ||
}, | ||
], | ||
notices: [ | ||
"You must disable the base rule (semi) as it can report incorrect errors.", | ||
"Option `strict-bound-class-methods` was found, there is no exact equivalent yet supported.", | ||
], | ||
}); | ||
}); | ||
|
||
test("conversion with always, strict bound class methods and ignore interfaces", () => { | ||
const result = convertSemicolon({ | ||
ruleArguments: ["never", "ignore-interfaces", "strict-bound-class-methods"], | ||
}); | ||
|
||
expect(result).toEqual({ | ||
rules: [ | ||
{ | ||
ruleName: "@typescript-eslint/semi", | ||
ruleArguments: ["never"], | ||
}, | ||
], | ||
notices: [ | ||
"You must disable the base rule (semi) as it can report incorrect errors.", | ||
"Option `strict-bound-class-methods` was found, there is no exact equivalent yet supported.", | ||
], | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.