From d66e41ccd436e17c7a79028884484e4098a62c2b Mon Sep 17 00:00:00 2001 From: lowkay Date: Wed, 6 Jul 2016 16:25:54 +0100 Subject: [PATCH] Allow implicit whitespace separation between tslint:enable/disable and rules list (#1352) Fixes #1269 --- src/enableDisableRules.ts | 15 ++++++++++++++- .../_integration/enable-disable/test.ts.lint | 13 +++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/enableDisableRules.ts b/src/enableDisableRules.ts index 5491b9f7dd7..a01657499b3 100644 --- a/src/enableDisableRules.ts +++ b/src/enableDisableRules.ts @@ -65,10 +65,23 @@ export class EnableDisableRulesWalker extends SkippableTokenAwareRuleWalker { const isEnabled = enableOrDisableMatch[1] === "enable"; const isCurrentLine = enableOrDisableMatch[3] === "line"; const isNextLine = enableOrDisableMatch[3] === "next-line"; + let rulesList = ["all"]; - if (commentTextParts.length > 2) { + + if (commentTextParts.length === 2) { + // an implicit whitespace separator is used for the rules list. + rulesList = commentTextParts[1].split(/\s+/).slice(1); + + // remove empty items and potential comment end. + rulesList = rulesList.filter(item => !!item && item.indexOf("*/") === -1); + + // potentially there were no items, so default to `all`. + rulesList = rulesList.length > 0 ? rulesList : ["all"]; + } else if (commentTextParts.length > 2) { + // an explicit separator was specified for the rules list. rulesList = commentTextParts[2].split(/\s+/); } + for (const ruleToAdd of rulesList) { if (!(ruleToAdd in this.enableDisableRuleMap)) { this.enableDisableRuleMap[ruleToAdd] = []; diff --git a/test/rules/_integration/enable-disable/test.ts.lint b/test/rules/_integration/enable-disable/test.ts.lint index ba78e3b5740..a628d1bc4d8 100644 --- a/test/rules/_integration/enable-disable/test.ts.lint +++ b/test/rules/_integration/enable-disable/test.ts.lint @@ -25,6 +25,19 @@ var AAAaA = 'test' /* tslint:enable:zasdadsa */ var AAAaA = 'test' +/* tslint:enable quotemark */ +var AAAaA = 'test' + ~~~~~~ [' should be "] +/* tslint:disable */ +var AAAaA = 'test' +/* tslint:enable quotemark variable-name */ +var AAAaA = 'test' + ~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~ [' should be "] +/* tslint:disable quotemark */ +var AAAaA = 'test' + ~~~~~ [variable name must be in camelcase or uppercase] + /* tslint:enable */ var re; re = /`/;