-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: add allow
option for restrict-template-expressions
#8556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JoshuaKGoldberg
merged 81 commits into
typescript-eslint:main
from
abrahamguo:restrict-template-expressions-ignoredtypenames
Sep 16, 2024
Merged
Changes from all commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
c035774
WIP
abrahamguo 4a41e8f
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo f51c879
finish logic
abrahamguo 0116b14
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo 37cfa52
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo b7217e7
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo 592c036
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo fbd2f30
add doc section
abrahamguo 4ee7087
update snapshot
abrahamguo 035b963
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo bf925e5
refactors and renames
abrahamguo f56d8e9
simplify type flag testers
abrahamguo 8245146
rename
abrahamguo bf1a087
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo a6e0c7b
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo f4bb1e8
write tests
abrahamguo 0a60320
simplify test
abrahamguo d77d075
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo cb1f33e
ignoredtypenames
abrahamguo cfd521d
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo f5396c6
restore suppression
abrahamguo 20dc709
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo a58a8bd
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo fcad2cd
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo c41785b
rename option
abrahamguo ca0bb6e
change option type
abrahamguo aba1edb
change to typematchesspecifier
abrahamguo b6f9be9
finish
abrahamguo d6a81ef
change defaults
abrahamguo 6a0a384
add tests
abrahamguo ea164f5
change defaults
abrahamguo ecb9e27
add documentation
abrahamguo c03c335
removed extra quote
abrahamguo 1b16bcb
add description
abrahamguo 1a3b934
add language
abrahamguo 2cb8963
fix JS error
abrahamguo a0dd1e7
fix types from node
abrahamguo dab25fe
extract repeated documentation
abrahamguo 6551b47
update comment clarifying string array
abrahamguo e25e842
update import path
abrahamguo d964a12
update snapshot
abrahamguo aba6dcd
revert unnecessary formatting change
abrahamguo 48fd991
add test for type from Node
abrahamguo 3072622
restore comment
abrahamguo f9e18ad
push more into var
abrahamguo d3215c7
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo aa2faf8
sync tests
abrahamguo 98577d2
move to shared folder
abrahamguo 899f146
add shared folder to test
abrahamguo 5a4c9c6
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo 86cd269
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo 9049fe7
update snapshot
abrahamguo e7e88bc
change check for consistency
abrahamguo b3d052a
clarify documentation for string form
abrahamguo d6cb2a8
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo 03c9a67
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo e056af8
clean up
abrahamguo 3e58a1e
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo 3a9c50b
make docs secret, tweak tests
abrahamguo 3c76c7f
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo 8b54864
revert
abrahamguo 6e93bd3
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo 42d4afa
cleanup
abrahamguo 33904bf
finish rename
abrahamguo f45a979
simplify tests
abrahamguo 34c24a5
change URL to Error
abrahamguo 53a069a
add tsconfig withdom
abrahamguo 089809c
revert docs tsconfig change
abrahamguo b7ea22f
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo 712ab4b
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo 346f9f4
fix TS error
abrahamguo 4bcf91b
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo f9e528a
simplify docs
abrahamguo 68fd177
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo 4a3d824
update snapshot
abrahamguo 87854b0
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo 66a9d4c
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo 30c1121
update docs
abrahamguo cdfbb46
remove unused import
abrahamguo 9842430
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into r…
abrahamguo d8509be
simplify unit tests to only use non-DOM types
abrahamguo 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
abrahamguo marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 |
---|---|---|
|
@@ -85,7 +85,7 @@ const msg2 = `arg = ${arg || 'not truthy'}`; | |
|
||
### `allowAny` | ||
|
||
Whether to `any` typed values in template expressions. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol |
||
Whether to allow `any` typed values in template expressions. | ||
|
||
Examples of additional **correct** code for this rule with `{ allowAny: true }`: | ||
|
||
|
@@ -124,7 +124,7 @@ const msg1 = `arg = ${arg}`; | |
|
||
### `allowNever` | ||
|
||
Whether to `never` typed values in template expressions. | ||
Whether to allow `never` typed values in template expressions. | ||
|
||
Examples of additional **correct** code for this rule with `{ allowNever: true }`: | ||
|
||
|
@@ -135,7 +135,7 @@ const msg1 = typeof arg === 'string' ? arg : `arg = ${arg}`; | |
|
||
### `allowArray` | ||
|
||
Whether to `Array` typed values in template expressions. | ||
Whether to allow `Array` typed values in template expressions. | ||
|
||
Examples of additional **correct** code for this rule with `{ allowArray: true }`: | ||
|
||
|
@@ -144,6 +144,19 @@ const arg = ['foo', 'bar']; | |
const msg1 = `arg = ${arg}`; | ||
``` | ||
|
||
### `allow` | ||
abrahamguo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Whether to allow additional types in template expressions. | ||
|
||
This option takes the shared [`TypeOrValueSpecifier` format](/packages/type-utils/type-or-value-specifier). | ||
|
||
Examples of additional **correct** code for this rule with the default option `{ allow: [{ from: 'lib', name: 'Error' }, { from: 'lib', name: 'URL' }, { from: 'lib', name: 'URLSearchParams' }] }`: | ||
|
||
```ts showPlaygroundButton | ||
const error = new Error(); | ||
const msg1 = `arg = ${error}`; | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
If you're not worried about incorrectly stringifying non-string values in template literals, then you likely don't need this rule. | ||
|
This file contains hidden or 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 hidden or 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
8 changes: 8 additions & 0 deletions
8
packages/eslint-plugin/tests/docs-eslint-output-snapshots/restrict-template-expressions.shot
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
113 changes: 113 additions & 0 deletions
113
packages/eslint-plugin/tests/schema-snapshots/restrict-template-expressions.shot
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.