diff --git a/README.md b/README.md index 48013251..9845ca86 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Code Smells, or maintainability issues, are raised for places of code which migh * "switch" statements should not be nested ([`no-nested-switch`]) * Template literals should not be nested ([`no-nested-template-literals`]) * Boolean literals should not be redundant ([`no-redundant-boolean`]) -* Jump statements should not be redundant ([`no-redundant-jump`]) +* Jump statements should not be redundant ([`no-redundant-jump`]) (:wrench: *fixable*) * Conditionals should start on new lines ([`no-same-line-conditional`]) * "switch" statements should have at least 3 "case" clauses ([`no-small-switch`]) * Collection and array contents should be used ([`no-unused-collection`]) diff --git a/docs/rules/no-redundant-jump.md b/docs/rules/no-redundant-jump.md index dfc35a35..2262193b 100644 --- a/docs/rules/no-redundant-jump.md +++ b/docs/rules/no-redundant-jump.md @@ -1,5 +1,7 @@ # no-redundant-jump +:wrench: *fixable* + Jump statements, such as `return`, `break` and `continue` let you change the default flow of program execution, but jump statements that direct the control flow to the original direction are just a waste of keystrokes. ## Noncompliant Code Example diff --git a/src/rules/no-redundant-jump.ts b/src/rules/no-redundant-jump.ts index 63a76bb6..c4954dcf 100644 --- a/src/rules/no-redundant-jump.ts +++ b/src/rules/no-redundant-jump.ts @@ -28,9 +28,11 @@ const rule: TSESLint.RuleModule = { meta: { messages: { removeRedundantJump: 'Remove this redundant jump.', + suggestJumpRemoval: 'Remove this redundant jump', }, schema: [], type: 'suggestion', + hasSuggestions: true, docs: { description: 'Jump statements should not be redundant', recommended: 'error', @@ -46,6 +48,7 @@ const rule: TSESLint.RuleModule = { context.report({ messageId: 'removeRedundantJump', node, + suggest: [{ messageId: 'suggestJumpRemoval', fix: fixer => fixer.remove(node) }], }); } } diff --git a/tests/rules/no-redundant-jump.test.ts b/tests/rules/no-redundant-jump.test.ts index e5c63c43..930cef58 100644 --- a/tests/rules/no-redundant-jump.test.ts +++ b/tests/rules/no-redundant-jump.test.ts @@ -94,6 +94,17 @@ ruleTester.run('Jump statements should not be redundant', rule, { return; // Noncompliant }`, ), + { + code: `function foo(x) { console.log(x); return; }`, + errors: [ + { + messageId: 'removeRedundantJump', + suggestions: [ + { messageId: 'suggestJumpRemoval', output: `function foo(x) { console.log(x); }` }, + ], + }, + ], + }, ], valid: [ {