From 3aec0d55b000762382185e27bf06562bd4ff5eee Mon Sep 17 00:00:00 2001 From: Pavel Birukov Date: Thu, 5 Sep 2019 14:19:55 +0300 Subject: [PATCH] Improve wording and remove string literals from 'object-literal-shorthand' --- src/rules/objectLiteralShorthandRule.ts | 18 ++++++++++++------ .../onlyMethods/tslint.json | 3 ++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/rules/objectLiteralShorthandRule.ts b/src/rules/objectLiteralShorthandRule.ts index 54bd4532e69..73e9d6faf3f 100644 --- a/src/rules/objectLiteralShorthandRule.ts +++ b/src/rules/objectLiteralShorthandRule.ts @@ -49,9 +49,15 @@ export class Rule extends Lint.Rules.AbstractRule { description: "Enforces/disallows use of ES6 object literal shorthand.", hasFix: true, optionsDescription: Lint.Utils.dedent` - If the \'never\' option is provided, any shorthand object literal syntax will cause a failure. - With \`{"property": "never"}\` provided, the rule fails on property shothands only, - and respectively with \`{"method": "never"}\`, the rule fails only on method shorthands`, + \`"always"\` assumed to be default option, thus with no options provided + the rule enforces object literal methods and properties shorthands. + With \`"never"\` option provided, any shorthand object literal syntax causes an error. + + The rule can be configured in a more granular way. + With \`{"property": "never"}\` provided (which is equivalent to \`{"property": "never", "method": "always"}\`), + the rule only flags property shorthand assignments, + and respectively with \`{"method": "never"}\` (equivalent to \`{"property": "always", "method": "never"}\`), + the rule fails only on method shorthands.`, options: { oneOf: [ { @@ -118,12 +124,12 @@ export class Rule extends Lint.Rules.AbstractRule { const optionsObject: RawOptions | undefined = options.find( (el: string | RawOptions): el is RawOptions => typeof el === "object" && - (el[OPTION_KEY_PROPERTY] === "never" || el[OPTION_KEY_METHOD] === "never"), + (el[OPTION_KEY_PROPERTY] === OPTION_VALUE_NEVER || el[OPTION_KEY_METHOD] === OPTION_VALUE_NEVER), ); if (optionsObject !== undefined) { return { - enforceShorthandMethods: !(optionsObject[OPTION_KEY_METHOD] === "never"), - enforceShorthandProperties: !(optionsObject[OPTION_KEY_PROPERTY] === "never"), + enforceShorthandMethods: !(optionsObject[OPTION_KEY_METHOD] === OPTION_VALUE_NEVER), + enforceShorthandProperties: !(optionsObject[OPTION_KEY_PROPERTY] === OPTION_VALUE_NEVER), }; } else { return { diff --git a/test/rules/object-literal-shorthand/onlyMethods/tslint.json b/test/rules/object-literal-shorthand/onlyMethods/tslint.json index bb3baad7359..fc32bc1d466 100644 --- a/test/rules/object-literal-shorthand/onlyMethods/tslint.json +++ b/test/rules/object-literal-shorthand/onlyMethods/tslint.json @@ -3,7 +3,8 @@ "object-literal-shorthand": [ true, { - "property": "never" + "property": "never", + "method": "always" } ] }