This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 887
[quotemark] Excuse more backtick edge cases #4642
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
95899d6
[quotemark] Excuse more backtick edge cases
ericbf 765a634
[quotemark] Add tests for different versions
ericbf 6f94a59
Merge branch 'master' into fix-quotemark-edge-cases
adidahiya 4aa87c1
Update quotemarkRule.ts
adidahiya 886a8b1
Update quotemarkRule.ts
adidahiya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
if (typeof v === "string") {} | ||
|
||
if (typeof `string` === 'number') {} | ||
|
||
const object: { | ||
"optional-prop"?: "hello-optional" | ||
"another-kebab": "hello-value" | ||
} = { | ||
"optional-prop": undefined, | ||
"another-kebab": "hello-value" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[typescript]: <2.7.1 | ||
if (typeof v === "string") {} | ||
|
||
if (typeof "string" === 'number') {} | ||
~~~~~~~~ [double] | ||
|
||
const object: { | ||
"optional-prop"?: "hello-optional" | ||
"another-kebab": "hello-value" | ||
} = { | ||
"optional-prop": undefined, | ||
"another-kebab": "hello-value" | ||
}; | ||
[single]: ' should be ` | ||
[double]: " should be ` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
if (typeof v === `string`) {} | ||
|
||
if (typeof `string` === `number`) {} | ||
|
||
const object: { | ||
"optional-prop"?: `hello-optional` | ||
"optional-function"?(): void | ||
"another-kebab": `hello-value` | ||
} = { | ||
"optional-prop": undefined, | ||
"optional-function"() {}, | ||
"another-kebab": `hello-value` | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[typescript]: >=2.7.1 | ||
if (typeof v === "string") {} | ||
~~~~~~~~ [double] | ||
|
||
if (typeof "string" === 'number') {} | ||
~~~~~~~~ [double] | ||
~~~~~~~~ [single] | ||
|
||
const object: { | ||
"optional-prop"?: `hello-optional` | ||
"optional-function"?(): void | ||
"another-kebab": "hello-value" | ||
~~~~~~~~~~~~~ [double] | ||
} = { | ||
"optional-prop": undefined, | ||
"optional-function"() {}, | ||
"another-kebab": "hello-value" | ||
~~~~~~~~~~~~~ [double] | ||
}; | ||
[single]: ' should be ` | ||
[double]: " should be ` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Directly checking
ts.version
is a little unusual... maybe there's a cleaner way? Thoughts @adidahiya?Also, @ericbf, could you elaborate on why this is necessary?
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.
Typescript below the listed version fails compilation (or otherwise misbehaves) when backticks are used in some places where it succeeds in future versions. For instance,
typeof str === `string`
does not narrow the type ofstr
in TS versions below 2.7.1, causing compilation errors if you try to use it as a string later. In the other cases, older TS throws errors where NoSubstitutionLiterals are used instead of single/double quoted strings, but works fine in above 2.7.1; rather than cripple the rule to support order versions, I split it up.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.
See the
typeof
issue here. Its milestone was 2.7 (hence the split in this PR).And here's the issue for backticks strings as types. This one was 2.6, but rather than doing multiple splits, I just did one at 2.7.
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.
Created corresponding issue, #4645
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.
Thanks! This LGTM but before merging I'd like to hear from adidahiya on whether there's a cleaner way to check on these things.
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 agree it's unusual and should be avoided if possible, but this seems like a reasonable use case for checking ts.version.
However, can you please use the semver package and the helper function from
parse.ts
to check version ranges instead?