Skip to content
This repository was archived by the owner on Mar 25, 2021. It is now read-only.

Commit db04231

Browse files
isabelleweberJosh Goldberg
authored and
Josh Goldberg
committed
Add quotemark type validation to allow early return (#4310) (#4344)
* Add quotemark type validation to allow early return (#4310) * Fix no-unsafe-any linting error in quotemark rule * Separate invalid quote tests into new tests * Fixed introduced build break
1 parent 9d6d49a commit db04231

File tree

7 files changed

+26
-2
lines changed

7 files changed

+26
-2
lines changed

src/rules/quotemarkRule.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ interface Options {
5151
avoidTemplate: boolean;
5252
}
5353

54+
function isQuoteMark(value: string): value is QUOTEMARK {
55+
return ["'", '"', "`"].indexOf(value) > -1;
56+
}
57+
5458
export class Rule extends Lint.Rules.AbstractRule {
5559
/* tslint:disable:object-literal-sort-keys */
5660
public static metadata: Lint.IRuleMetadata = {
@@ -140,8 +144,8 @@ function walk(ctx: Lint.WalkContext<Options>) {
140144
return;
141145
}
142146

143-
// We already have the expected quotemark. Done.
144-
if (actualQuotemark === expectedQuotemark) {
147+
// We already have the expected quotemark, or the quotemark is invalid. Done.
148+
if (actualQuotemark === expectedQuotemark || !isQuoteMark(actualQuotemark)) {
145149
return;
146150
}
147151

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var single = "single";
2+
var unbalancedSingleAfter = ('a)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var single = 'single';
2+
~~~~~~~~ [' should be "]
3+
var unbalancedSingleAfter = ('a)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"quotemark": [true, "double"]
4+
}
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var single = 'single';
2+
var unbalancedSingleAfter = ("a)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var single = "single";
2+
~~~~~~~~ [" should be ']
3+
var unbalancedSingleAfter = ("a)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"quotemark": [true, "single"]
4+
}
5+
}

0 commit comments

Comments
 (0)