Skip to content
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

fix: missing placeholders in violation messages for no-unnecessary-type-constraint and no-unsafe-argument (and enable eslint-plugin/recommended rules internally) #5453

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Expand Up @@ -15,6 +15,7 @@ module.exports = {
},
extends: [
'eslint:recommended',
'plugin:eslint-plugin/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
Expand Down Expand Up @@ -194,7 +195,7 @@ module.exports = {
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'eslint-plugin/no-identical-tests': 'error',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule is now included in the recommended config.

'eslint-plugin/consistent-output': 'off', // Might eventually be removed from `eslint-plugin/recommended`: https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/284
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-alias-methods': 'error',
Expand Down
Expand Up @@ -35,7 +35,6 @@ export default createRule({
description:
"Enforces rules don't use TS API properties with known bad type definitions",
recommended: 'error',
suggestion: true,
requiresTypeChecking: true,
},
fixable: 'code',
Expand Down
4 changes: 4 additions & 0 deletions packages/eslint-plugin/src/rules/naming-convention.ts
@@ -1,3 +1,7 @@
/* eslint-disable eslint-comments/no-use */
/* eslint eslint-plugin/no-unused-message-ids:"off" -- https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/283 */
/* eslint-enable eslint-comments/no-use */

import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/utils';
import { PatternVisitor } from '@typescript-eslint/scope-manager';
import type { ScriptTarget } from 'typescript';
Expand Down
Expand Up @@ -9,7 +9,7 @@ export default util.createRule({
description: 'Disallow duplicate enum member values',
recommended: 'strict',
},
hasSuggestions: true,
hasSuggestions: false,
Copy link
Contributor Author

@bmish bmish Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many of these rules indicated they had suggestions but do not actually provide suggestions.

Caught by the eslint-plugin/require-meta-has-suggestions rule.

messages: {
duplicateValue: 'Duplicate enum member value {{value}}.',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin/src/rules/no-empty-interface.ts
Expand Up @@ -15,10 +15,9 @@ export default util.createRule<Options, MessageIds>({
docs: {
description: 'Disallow the declaration of empty interfaces',
recommended: 'error',
suggestion: true,
Copy link
Contributor Author

@bmish bmish Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This meta.docs.suggestion property was replaced by meta.hasSuggestions (more info in eslint/eslint#14312). It's confusing to leave the old property here especially when it's incorrectly specified in many of the rules.

},
fixable: 'code',
hasSuggestions: true,
hasSuggestions: true, // eslint-disable-line eslint-plugin/require-meta-has-suggestions -- https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/272
messages: {
noEmpty: 'An empty interface is equivalent to `{}`.',
noEmptyWithSuper:
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin/src/rules/no-explicit-any.ts
Expand Up @@ -16,10 +16,9 @@ export default util.createRule<Options, MessageIds>({
docs: {
description: 'Disallow the `any` type',
recommended: 'warn',
suggestion: true,
},
fixable: 'code',
hasSuggestions: true,
hasSuggestions: true, // eslint-disable-line eslint-plugin/require-meta-has-suggestions -- https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/281
messages: {
unexpectedAny: 'Unexpected any. Specify a different type.',
suggestUnknown:
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-plugin/src/rules/no-floating-promises.ts
Expand Up @@ -20,7 +20,6 @@ export default util.createRule<Options, MessageId>({
description:
'Require Promise-like statements to be handled appropriately',
recommended: 'error',
suggestion: true,
requiresTypeChecking: true,
},
hasSuggestions: true,
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-plugin/src/rules/no-implicit-any-catch.ts
Expand Up @@ -19,7 +19,6 @@ export default util.createRule<Options, MessageIds>({
docs: {
description: 'Disallow usage of the implicit `any` type in catch clauses',
recommended: false,
suggestion: true,
},
fixable: 'code',
hasSuggestions: true,
Expand Down
Expand Up @@ -20,7 +20,6 @@ export default util.createRule<
description:
'Disallow the `void` operator except when used to discard a value',
recommended: 'strict',
suggestion: true,
requiresTypeChecking: true,
},
fixable: 'code',
Expand Down
Expand Up @@ -19,7 +19,6 @@ export default util.createRule({
description:
'Disallow non-null assertions after an optional chain expression',
recommended: 'error',
suggestion: true,
},
hasSuggestions: true,
messages: {
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-plugin/src/rules/no-non-null-assertion.ts
Expand Up @@ -11,7 +11,6 @@ export default util.createRule<[], MessageIds>({
description:
'Disallow non-null assertions using the `!` postfix operator',
recommended: 'warn',
suggestion: true,
},
hasSuggestions: true,
messages: {
Expand Down
Expand Up @@ -31,7 +31,6 @@ export default util.createRule({
docs: {
description: 'Disallow unnecessary constraints on generic types',
recommended: 'error',
suggestion: true,
},
hasSuggestions: true,
messages: {
Expand Down Expand Up @@ -89,6 +88,9 @@ export default util.createRule({
suggest: [
{
messageId: 'removeUnnecessaryConstraint',
data: {
constraint,
Copy link
Contributor Author

@bmish bmish Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an actual bug. This data was missing for the suggestion message and would thus show as {{constraint}} to the user instead of the actual value. I updated the tests to test this data.

I can extract this bug fix into a separate PR if desired.

Caught by the eslint-plugin/no-missing-placeholders and eslint-plugin/no-unused-placeholders rules.

},
fix(fixer): TSESLint.RuleFix | null {
return fixer.replaceTextRange(
[node.name.range[1], node.constraint.range[1]],
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-unsafe-argument.ts
Expand Up @@ -142,7 +142,7 @@ export default util.createRule<[], MessageIds>({
unsafeArgument:
'Unsafe argument of type `{{sender}}` assigned to a parameter of type `{{receiver}}`.',
unsafeTupleSpread:
'Unsafe spread of a tuple type. The {{index}} element is of type `{{sender}}` and is assigned to a parameter of type `{{reciever}}`.',
'Unsafe spread of a tuple type. The argument is of type `{{sender}}` and is assigned to a parameter of type `{{receiver}}`.',
Copy link
Contributor Author

@bmish bmish Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an actual bug. The {{index}} placeholder was never provided for this message. It also doesn't seem necessary to me as the violation is already reported on the specific argument that it refers to.

I can extract this bug fix into a separate PR if desired.

Caught by the eslint-plugin/no-missing-placeholders and eslint-plugin/no-unused-placeholders rules.

Copy link
Contributor Author

@bmish bmish Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an actual bug. There is a typo in the receiver placeholder name.

I can extract this bug fix into a separate PR if desired.

Caught by the eslint-plugin/no-missing-placeholders and eslint-plugin/no-unused-placeholders rules.

unsafeArraySpread: 'Unsafe spread of an `any` array type.',
unsafeSpread: 'Unsafe spread of an `any` type.',
},
Expand Down
4 changes: 4 additions & 0 deletions packages/eslint-plugin/src/rules/no-unsafe-call.ts
@@ -1,3 +1,7 @@
/* eslint-disable eslint-comments/no-use */
/* eslint eslint-plugin/no-unused-message-ids:"off" -- https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/282 */
/* eslint-enable eslint-comments/no-use */

import { TSESTree } from '@typescript-eslint/utils';
import * as tsutils from 'tsutils';
import * as util from '../util';
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin/src/rules/no-useless-empty-export.ts
Expand Up @@ -28,10 +28,9 @@ export default util.createRule({
description:
"Disallow empty exports that don't change anything in a module file",
recommended: false,
suggestion: true,
},
fixable: 'code',
hasSuggestions: true,
hasSuggestions: false,
messages: {
uselessExport: 'Empty export does nothing and can be removed.',
},
Expand Down
Expand Up @@ -11,7 +11,6 @@ export default util.createRule({
description: 'Enforce non-null assertions over explicit type casts',
recommended: 'strict',
requiresTypeChecking: true,
suggestion: true,
},
fixable: 'code',
messages: {
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/object-curly-spacing.ts
Expand Up @@ -20,6 +20,7 @@ export type MessageIds = InferMessageIdsTypeFromRule<typeof baseRule>;

export default createRule<Options, MessageIds>({
name: 'object-curly-spacing',
// eslint-disable-next-line eslint-plugin/prefer-message-ids,eslint-plugin/require-meta-type,eslint-plugin/require-meta-schema,eslint-plugin/require-meta-fixable -- all in base rule - https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/274
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
meta: {
...baseRule.meta,
docs: {
Expand Down
Expand Up @@ -592,7 +592,7 @@ export default util.createRule<Options, MessageIds>({
extendsBaseRule: true,
},
fixable: 'whitespace',
hasSuggestions: true,
hasSuggestions: false,
schema: {
definitions: {
paddingType: {
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-plugin/src/rules/prefer-as-const.ts
Expand Up @@ -8,7 +8,6 @@ export default util.createRule({
docs: {
description: 'Enforce the use of `as const` over literal type',
recommended: 'error',
suggestion: true,
},
fixable: 'code',
hasSuggestions: true,
Expand Down
Expand Up @@ -11,7 +11,6 @@ export default util.createRule<[], MessageIds>({
description:
'Require each enum member value to be explicitly initialized',
recommended: false,
suggestion: true,
},
hasSuggestions: true,
messages: {
Expand Down
Expand Up @@ -28,7 +28,6 @@ export default util.createRule<Options, MessageIds>({
description:
'Enforce using the nullish coalescing operator instead of logical chaining',
recommended: 'strict',
suggestion: true,
requiresTypeChecking: true,
},
hasSuggestions: true,
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-plugin/src/rules/prefer-optional-chain.ts
Expand Up @@ -36,7 +36,6 @@ export default util.createRule({
description:
'Enforce using concise optional chain expressions instead of chained logical ands',
recommended: 'strict',
suggestion: true,
},
hasSuggestions: true,
messages: {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/return-await.ts
Expand Up @@ -25,7 +25,7 @@ export default util.createRule({
extendsBaseRule: 'no-return-await',
},
fixable: 'code',
hasSuggestions: true,
hasSuggestions: true, // eslint-disable-line eslint-plugin/require-meta-has-suggestions -- https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/272
type: 'problem',
messages: {
nonPromiseAwait:
Expand Down
Expand Up @@ -110,7 +110,7 @@ export default util.createRule<Options, MessageIds>({
recommended: false,
},
fixable: 'code',
hasSuggestions: true,
hasSuggestions: true, // eslint-disable-line eslint-plugin/require-meta-has-suggestions -- https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/272
messages: {
notSorted: '{{type}} type members must be sorted.',
notSortedNamed: '{{type}} type {{name}} members must be sorted.',
Expand Down
Expand Up @@ -18,7 +18,6 @@ export default createRule({
description:
'Require switch-case statements to be exhaustive with union type',
recommended: false,
suggestion: true,
requiresTypeChecking: true,
},
hasSuggestions: true,
Expand Down
Expand Up @@ -194,11 +194,7 @@ interface B extends A {
[index: number]: unknown;
}
`,
output: `
interface B extends A {
[index: number]: unknown;
}
`,
output: null,
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
errors: [{ messageId: 'preferRecord', line: 2, column: 1 }],
},
// Readonly interface with generic parameter
Expand Down