-
Notifications
You must be signed in to change notification settings - Fork 13k
Disallow underspecified types #21485
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
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4c0eac9
Disallow underspecified types.
gundermanc c2f47af
Suppress instances.
gundermanc dcfe4dd
More suppressions.
gundermanc 2f34fbb
Revert.
gundermanc 9a5e33f
Disable in tests.
gundermanc d32eb4b
Merge remote-tracking branch 'origin/main' into gundermanc/disallow-u…
gundermanc 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 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 |
|---|---|---|
|
|
@@ -132,7 +132,16 @@ export default tseslint.config( | |
| 'no-cond-assign': 'error', | ||
| 'no-debugger': 'error', | ||
| 'no-duplicate-case': 'error', | ||
| 'no-restricted-syntax': ['error', ...commonRestrictedSyntaxRules], | ||
| 'no-restricted-syntax': [ | ||
| 'error', | ||
| ...commonRestrictedSyntaxRules, | ||
| { | ||
| selector: | ||
| 'UnaryExpression[operator="typeof"] > MemberExpression[computed=true][property.type="Literal"]', | ||
| message: | ||
| 'Do not use typeof to check object properties. Define a TypeScript interface and a type guard function instead.', | ||
| }, | ||
| ], | ||
| 'no-unsafe-finally': 'error', | ||
| 'no-unused-expressions': 'off', // Disable base rule | ||
| '@typescript-eslint/no-unused-expressions': [ | ||
|
|
@@ -263,6 +272,38 @@ export default tseslint.config( | |
| ...vitest.configs.recommended.rules, | ||
| 'vitest/expect-expect': 'off', | ||
| 'vitest/no-commented-out-tests': 'off', | ||
| 'no-restricted-syntax': [ | ||
| 'error', | ||
| { | ||
| selector: 'CallExpression[callee.name="require"]', | ||
| message: 'Avoid using require(). Use ES6 imports instead.', | ||
| }, | ||
| { | ||
| selector: 'ThrowStatement > Literal:not([value=/^\\w+Error:/])', | ||
| message: | ||
| 'Do not throw string literals or non-Error objects. Throw new Error("...") instead.', | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| { | ||
| files: [ | ||
| 'integration-tests/**/*.ts', | ||
| 'evals/**/*.ts', | ||
| ], | ||
| rules: { | ||
| 'no-restricted-syntax': [ | ||
| 'error', | ||
| { | ||
| selector: 'CallExpression[callee.name="require"]', | ||
| message: 'Avoid using require(). Use ES6 imports instead.', | ||
| }, | ||
| { | ||
| selector: 'ThrowStatement > Literal:not([value=/^\\w+Error:/])', | ||
| message: | ||
| 'Do not throw string literals or non-Error objects. Throw new Error("...") instead.', | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
|
||
| { | ||
|
|
||
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
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
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
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
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.
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.
To improve maintainability and prevent the configurations from drifting apart, you can reuse the
commonRestrictedSyntaxRulesconstant here instead of duplicating the rules. The same applies to the configuration forintegration-testsandevalsbelow.