diff --git a/docs/_data/rules.json b/docs/_data/rules.json index 5bafaa6ab97..79910f3d4ba 100644 --- a/docs/_data/rules.json +++ b/docs/_data/rules.json @@ -61,7 +61,7 @@ "description": "Requires parentheses around the parameters of arrow function definitions.", "hasFix": true, "rationale": "Maintains stylistic consistency with other arrow function definitions.", - "optionsDescription": "\nif `ban-single-arg-parens` is specified, then arrow functions with one parameter\nmust not have parentheses if removing them is allowed by TypeScript.", + "optionsDescription": "\nIf `ban-single-arg-parens` is specified, then arrow functions with one parameter\nmust not have parentheses if removing them is allowed by TypeScript.", "options": { "type": "string", "enum": [ @@ -75,6 +75,24 @@ "type": "style", "typescriptOnly": false }, + { + "ruleName": "arrow-return-shorthand", + "description": "Suggests to convert `() => { return x; }` to `() => x`.", + "hasFix": true, + "optionsDescription": "\nIf `multiline` is specified, then this will warn even if the function spans multiple lines.", + "options": { + "type": "string", + "enum": [ + "multiline" + ] + }, + "optionExamples": [ + "[true]", + "[true, \"multiline\"]" + ], + "type": "style", + "typescriptOnly": false + }, { "ruleName": "ban", "description": "Bans the use of specific functions or global methods.", @@ -1189,18 +1207,6 @@ "type": "style", "typescriptOnly": false }, - { - "ruleName": "prefer-arrow-shorthand-return", - "description": "Suggests to convert `() => { return x; }` to `() => x`.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "[true]", - "[true, \"multiline\"]" - ], - "type": "functionality", - "typescriptOnly": false - }, { "ruleName": "prefer-const", "description": "Requires that variable declarations use `const` instead of `let` if possible.", diff --git a/docs/rules/arrow-parens/index.html b/docs/rules/arrow-parens/index.html index 95180701d85..d6bec9d8a20 100644 --- a/docs/rules/arrow-parens/index.html +++ b/docs/rules/arrow-parens/index.html @@ -5,7 +5,7 @@ rationale: Maintains stylistic consistency with other arrow function definitions. optionsDescription: |- - if `ban-single-arg-parens` is specified, then arrow functions with one parameter + If `ban-single-arg-parens` is specified, then arrow functions with one parameter must not have parentheses if removing them is allowed by TypeScript. options: type: string diff --git a/docs/rules/arrow-return-shorthand/index.html b/docs/rules/arrow-return-shorthand/index.html new file mode 100644 index 00000000000..69ca43199ca --- /dev/null +++ b/docs/rules/arrow-return-shorthand/index.html @@ -0,0 +1,26 @@ +--- +ruleName: arrow-return-shorthand +description: 'Suggests to convert `() => { return x; }` to `() => x`.' +hasFix: true +optionsDescription: |- + + If `multiline` is specified, then this will warn even if the function spans multiple lines. +options: + type: string + enum: + - multiline +optionExamples: + - '[true]' + - '[true, "multiline"]' +type: style +typescriptOnly: false +layout: rule +title: 'Rule: arrow-return-shorthand' +optionsJSON: |- + { + "type": "string", + "enum": [ + "multiline" + ] + } +--- \ No newline at end of file diff --git a/src/rules/arrowParensRule.ts b/src/rules/arrowParensRule.ts index 0e53fecf000..99aa7f885f5 100644 --- a/src/rules/arrowParensRule.ts +++ b/src/rules/arrowParensRule.ts @@ -29,7 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { hasFix: true, rationale: "Maintains stylistic consistency with other arrow function definitions.", optionsDescription: Lint.Utils.dedent` - if \`${BAN_SINGLE_ARG_PARENS}\` is specified, then arrow functions with one parameter + If \`${BAN_SINGLE_ARG_PARENS}\` is specified, then arrow functions with one parameter must not have parentheses if removing them is allowed by TypeScript.`, options: { type: "string", diff --git a/src/rules/preferArrowShorthandReturnRule.ts b/src/rules/arrowReturnShorthandRule.ts similarity index 92% rename from src/rules/preferArrowShorthandReturnRule.ts rename to src/rules/arrowReturnShorthandRule.ts index 8bcc014d3c7..58bb7e869d6 100644 --- a/src/rules/preferArrowShorthandReturnRule.ts +++ b/src/rules/arrowReturnShorthandRule.ts @@ -24,15 +24,20 @@ const OPTION_MULTILINE = "multiline"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ public static metadata: Lint.IRuleMetadata = { - ruleName: "prefer-arrow-shorthand-return", + ruleName: "arrow-return-shorthand", description: "Suggests to convert `() => { return x; }` to `() => x`.", - optionsDescription: "Not configurable.", - options: null, + hasFix: true, + optionsDescription: Lint.Utils.dedent` + If \`${OPTION_MULTILINE}\` is specified, then this will warn even if the function spans multiple lines.`, + options: { + type: "string", + enum: [OPTION_MULTILINE], + }, optionExamples: [ `[true]`, `[true, "${OPTION_MULTILINE}"]`, ], - type: "functionality", + type: "style", typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/test/rules/prefer-arrow-shorthand-return/default/test.js.fix b/test/rules/arrow-return-shorthand/default/test.js.fix similarity index 100% rename from test/rules/prefer-arrow-shorthand-return/default/test.js.fix rename to test/rules/arrow-return-shorthand/default/test.js.fix diff --git a/test/rules/prefer-arrow-shorthand-return/default/test.js.lint b/test/rules/arrow-return-shorthand/default/test.js.lint similarity index 100% rename from test/rules/prefer-arrow-shorthand-return/default/test.js.lint rename to test/rules/arrow-return-shorthand/default/test.js.lint diff --git a/test/rules/prefer-arrow-shorthand-return/default/test.ts.fix b/test/rules/arrow-return-shorthand/default/test.ts.fix similarity index 100% rename from test/rules/prefer-arrow-shorthand-return/default/test.ts.fix rename to test/rules/arrow-return-shorthand/default/test.ts.fix diff --git a/test/rules/prefer-arrow-shorthand-return/default/test.ts.lint b/test/rules/arrow-return-shorthand/default/test.ts.lint similarity index 100% rename from test/rules/prefer-arrow-shorthand-return/default/test.ts.lint rename to test/rules/arrow-return-shorthand/default/test.ts.lint diff --git a/test/rules/arrow-return-shorthand/default/tslint.json b/test/rules/arrow-return-shorthand/default/tslint.json new file mode 100644 index 00000000000..09560397671 --- /dev/null +++ b/test/rules/arrow-return-shorthand/default/tslint.json @@ -0,0 +1,8 @@ +{ + "rules": { + "arrow-return-shorthand": true + }, + "jsRules": { + "arrow-return-shorthand": true + } +} diff --git a/test/rules/prefer-arrow-shorthand-return/multiline/test.ts.fix b/test/rules/arrow-return-shorthand/multiline/test.ts.fix similarity index 100% rename from test/rules/prefer-arrow-shorthand-return/multiline/test.ts.fix rename to test/rules/arrow-return-shorthand/multiline/test.ts.fix diff --git a/test/rules/prefer-arrow-shorthand-return/multiline/test.ts.lint b/test/rules/arrow-return-shorthand/multiline/test.ts.lint similarity index 100% rename from test/rules/prefer-arrow-shorthand-return/multiline/test.ts.lint rename to test/rules/arrow-return-shorthand/multiline/test.ts.lint diff --git a/test/rules/arrow-return-shorthand/multiline/tslint.json b/test/rules/arrow-return-shorthand/multiline/tslint.json new file mode 100644 index 00000000000..429bf4cc655 --- /dev/null +++ b/test/rules/arrow-return-shorthand/multiline/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "arrow-return-shorthand": [true, "multiline"] + } +} diff --git a/test/rules/prefer-arrow-shorthand-return/default/tslint.json b/test/rules/prefer-arrow-shorthand-return/default/tslint.json deleted file mode 100644 index d2a91f9fc0b..00000000000 --- a/test/rules/prefer-arrow-shorthand-return/default/tslint.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "rules": { - "prefer-arrow-shorthand-return": true - }, - "jsRules": { - "prefer-arrow-shorthand-return": true - } -} diff --git a/test/rules/prefer-arrow-shorthand-return/multiline/tslint.json b/test/rules/prefer-arrow-shorthand-return/multiline/tslint.json deleted file mode 100644 index 8fd2a984f8e..00000000000 --- a/test/rules/prefer-arrow-shorthand-return/multiline/tslint.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "rules": { - "prefer-arrow-shorthand-return": [true, "multiline"] - } -}