-
Notifications
You must be signed in to change notification settings - Fork 887
quotemark-rule: single/double options can be at any index in arg list #3114
Conversation
src/rules/quotemarkRule.ts
Outdated
@@ -141,3 +133,21 @@ function walk(ctx: Lint.WalkContext<Options>) { | |||
ts.forEachChild(node, cb); | |||
}); | |||
} | |||
|
|||
function hasSingleDoublePreference(args: any[]): boolean { | |||
for (const arg of args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can simply return getQuotemarkPreference(args) !== undefined;
src/rules/quotemarkRule.ts
Outdated
@@ -75,18 +73,12 @@ export class Rule extends Lint.Rules.AbstractRule { | |||
} | |||
|
|||
public isEnabled(): boolean { | |||
return super.isEnabled() && (this.ruleArguments[0] === OPTION_SINGLE || this.ruleArguments[0] === OPTION_DOUBLE); | |||
return super.isEnabled() && hasSingleDoublePreference(this.ruleArguments); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we remove this method, the rule will default to double quotes? I think that's more reasonable than just doing nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree and yes removing that call will set default to double quotes.
} | ||
|
||
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { | ||
const args = this.ruleArguments; | ||
if (args.length > 0) { | ||
if (args[0] !== OPTION_SINGLE && args[0] !== OPTION_DOUBLE) { | ||
showWarningOnce(`Warning: First argument to 'quotemark' rule should be "${OPTION_SINGLE}" or "${OPTION_DOUBLE}"`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's funny that this code would show the correct warning, but was never executed because the rule was disabled.
src/rules/quotemarkRule.ts
Outdated
function getQuotemarkPreference(args: any[]): string | undefined { | ||
for (const arg of args) { | ||
if (arg === OPTION_SINGLE || arg === OPTION_DOUBLE) { | ||
return (arg === OPTION_SINGLE) ? OPTION_SINGLE : OPTION_DOUBLE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just return arg;
src/rules/quotemarkRule.ts
Outdated
@@ -1,6 +1,6 @@ | |||
/** | |||
* @license | |||
* Copyright 2013 Palantir Technologies, Inc. | |||
* Copyright 2017 Palantir Technologies, Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one should stay unchanged
Added a couple util functions to quotemark rule. Checks argument list for OPTION_SINGLE or OPTION_DOUBLE in such a way that argument order doesn't matter. Currently, isEnabled() will return false if no single/double option is specified. Maybe defaulting to double quotes makes more sense?