From 00b1d2ebfec492d715bafae8fd4057814ed34c31 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Fri, 6 Jan 2017 18:54:43 -0800 Subject: [PATCH] Rename to arrow-return-shorthand and fix metadata --- docs/_data/rules.json | 32 +++++++++++-------- docs/rules/arrow-parens/index.html | 2 +- docs/rules/arrow-return-shorthand/index.html | 26 +++++++++++++++ src/rules/arrowParensRule.ts | 2 +- ...urnRule.ts => arrowReturnShorthandRule.ts} | 11 +++++-- .../default/test.js.fix | 0 .../default/test.js.lint | 0 .../default/test.ts.fix | 0 .../default/test.ts.lint | 0 .../default/tslint.json | 8 +++++ .../multiline/test.ts.fix | 0 .../multiline/test.ts.lint | 0 .../multiline/tslint.json | 5 +++ .../default/tslint.json | 8 ----- .../multiline/tslint.json | 5 --- 15 files changed, 68 insertions(+), 31 deletions(-) create mode 100644 docs/rules/arrow-return-shorthand/index.html rename src/rules/{preferArrowShorthandReturnRule.ts => arrowReturnShorthandRule.ts} (92%) rename test/rules/{prefer-arrow-shorthand-return => arrow-return-shorthand}/default/test.js.fix (100%) rename test/rules/{prefer-arrow-shorthand-return => arrow-return-shorthand}/default/test.js.lint (100%) rename test/rules/{prefer-arrow-shorthand-return => arrow-return-shorthand}/default/test.ts.fix (100%) rename test/rules/{prefer-arrow-shorthand-return => arrow-return-shorthand}/default/test.ts.lint (100%) create mode 100644 test/rules/arrow-return-shorthand/default/tslint.json rename test/rules/{prefer-arrow-shorthand-return => arrow-return-shorthand}/multiline/test.ts.fix (100%) rename test/rules/{prefer-arrow-shorthand-return => arrow-return-shorthand}/multiline/test.ts.lint (100%) create mode 100644 test/rules/arrow-return-shorthand/multiline/tslint.json delete mode 100644 test/rules/prefer-arrow-shorthand-return/default/tslint.json delete mode 100644 test/rules/prefer-arrow-shorthand-return/multiline/tslint.json diff --git a/docs/_data/rules.json b/docs/_data/rules.json index 5bafaa6ab97..fdb410f447d 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": "functionality", + "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..e54258ccc93 --- /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: functionality +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..c4f424be55b 100644 --- a/src/rules/preferArrowShorthandReturnRule.ts +++ b/src/rules/arrowReturnShorthandRule.ts @@ -24,10 +24,15 @@ 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}"]`, 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"] - } -}