-
Notifications
You must be signed in to change notification settings - Fork 100
Added no-unused-expression converter #205
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 8 commits into
typescript-eslint:master
from
asponda:feature/no-unused-expression-converter
Oct 7, 2019
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
75c8e27
feat: added no-unused-expression converter and unit tests
asponda bc4d63c
Merge branch 'master' into feature/no-unused-expression-converter
asponda 696d09c
feat: Add notice for optional configs that not equals to allow-tagged…
asponda 2bd035c
Merge branch 'master' into feature/no-unused-expression-converter
asponda dd271af
fix: no-unused-expression converter - add converter for allow-fast-nu…
asponda 643c8df
Merge branch 'master' into feature/no-unused-expression-converter
asponda a5b71df
fix: undo unrelated removed comments in converters.ts
asponda d7be846
fix: no-unused-expression - fix espace in the notice message
asponda 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { RuleConverter } from "../converter"; | ||
|
|
||
| export const convertNoUnusedExpression: RuleConverter = tslintRule => { | ||
| return { | ||
| rules: [ | ||
| { | ||
| ruleName: "no-unused-expressions", | ||
| ...collectNoticesAndArguments(tslintRule.ruleArguments), | ||
| }, | ||
| ], | ||
| }; | ||
| }; | ||
|
|
||
| const collectNoticesAndArguments = (tsLintRuleArguments: any[]) => { | ||
| const noAllowNewNotice = `The TSLint optional config "allow-new" is the default ESLint behavior and will no longer be ignored.`; | ||
asponda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (tsLintRuleArguments.length === 0) { | ||
| return { | ||
| notices: [noAllowNewNotice], | ||
| }; | ||
| } | ||
|
|
||
| const notices = []; | ||
| const ruleArguments: any[] = []; | ||
|
|
||
| if (tsLintRuleArguments.includes("allow-tagged-template")) { | ||
| ruleArguments.push({ allowTaggedTemplates: true }); | ||
| } | ||
|
|
||
| if (tsLintRuleArguments.includes("allow-fast-null-checks")) { | ||
| ruleArguments.push({ allowShortCircuit: true }); | ||
| } | ||
|
|
||
| if (!tsLintRuleArguments.includes("allow-new")) { | ||
| notices.push(noAllowNewNotice); | ||
| } | ||
|
|
||
| return { | ||
| ...(notices.length > 0 && { notices }), | ||
| ...(ruleArguments.length > 0 && { | ||
| ruleArguments: [ | ||
| ruleArguments.reduce((value, current) => Object.assign(value, current), {}), | ||
| ], | ||
| }), | ||
| }; | ||
| }; | ||
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,83 @@ | ||
| import { convertNoUnusedExpression } from "../no-unused-expression"; | ||
|
|
||
| describe(convertNoUnusedExpression, () => { | ||
| test("conversion without arguments", () => { | ||
| const result = convertNoUnusedExpression({ | ||
| ruleArguments: [], | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| rules: [ | ||
| { | ||
| ruleName: "no-unused-expressions", | ||
| notices: [ | ||
| `The TSLint optional config "allow-new" is the default ESLint behavior and will no longer be ignored.`, | ||
| ], | ||
| }, | ||
| ], | ||
| }); | ||
| }); | ||
|
|
||
| test("conversion without allow-new argument", () => { | ||
| const result = convertNoUnusedExpression({ | ||
| ruleArguments: ["allow-fast-null-checks"], | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| rules: [ | ||
| { | ||
| ruleName: "no-unused-expressions", | ||
| ruleArguments: [{ allowShortCircuit: true }], | ||
| notices: [ | ||
| `The TSLint optional config "allow-new" is the default ESLint behavior and will no longer be ignored.`, | ||
| ], | ||
| }, | ||
| ], | ||
| }); | ||
| }); | ||
|
|
||
| test("conversion with allow-tagged-template argument", () => { | ||
| const result = convertNoUnusedExpression({ | ||
| ruleArguments: ["allow-new", "allow-tagged-template"], | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| rules: [ | ||
| { | ||
| ruleArguments: [{ allowTaggedTemplates: true }], | ||
| ruleName: "no-unused-expressions", | ||
| }, | ||
| ], | ||
| }); | ||
| }); | ||
|
|
||
| test("conversion with allow-fast-null-checks argument", () => { | ||
| const result = convertNoUnusedExpression({ | ||
| ruleArguments: ["allow-new", "allow-fast-null-checks"], | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| rules: [ | ||
| { | ||
| ruleName: "no-unused-expressions", | ||
| ruleArguments: [{ allowShortCircuit: true }], | ||
| }, | ||
| ], | ||
| }); | ||
| }); | ||
|
|
||
| test("conversion with multiple arguments", () => { | ||
| const result = convertNoUnusedExpression({ | ||
| ruleArguments: ["allow-new", "allow-tagged-template", "allow-fast-null-checks"], | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| rules: [ | ||
| { | ||
| ruleName: "no-unused-expressions", | ||
| ruleArguments: [{ allowTaggedTemplates: true, allowShortCircuit: true }], | ||
| }, | ||
| ], | ||
| }); | ||
| }); | ||
| }); |
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.