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) #5414

Closed
Closed
Show file tree
Hide file tree
Changes from all 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: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
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,6 +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/consistent-output': 'off',
'eslint-plugin/no-identical-tests': 'error',
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
Expand Down Expand Up @@ -243,6 +245,7 @@ module.exports = {
'packages/eslint-plugin/src/rules/**/*.ts',
],
rules: {
'eslint-plugin/require-meta-schema': 'off', // TODO: allow variable
// specifically for rules - default exports makes the tooling easier
'import/no-default-export': 'off',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default util.createRule({
description: 'Disallow duplicate enum member values',
recommended: 'strict',
},
hasSuggestions: true,
hasSuggestions: false,
messages: {
duplicateValue: 'Duplicate enum member value {{value}}.',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default util.createRule({
suggestion: true,
},
fixable: 'code',
hasSuggestions: true,
hasSuggestions: false,
messages: {
uselessExport: 'Empty export does nothing and can be removed.',
},
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,7 @@ interface B extends A {
[index: number]: unknown;
}
`,
output: `
interface B extends A {
[index: number]: unknown;
}
`,
output: null,
errors: [{ messageId: 'preferRecord', line: 2, column: 1 }],
},
// Readonly interface with generic parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,7 @@ export class XXXX {
line: 3,
},
],
output: `
export class XXXX {
public constructor(readonly value: string) {}
}
`,
output: null,
},
{
filename: 'test.ts',
Expand All @@ -383,11 +379,7 @@ export class WithParameterProperty {
`,
options: [{ accessibility: 'explicit' }],
errors: [{ messageId: 'missingAccessibility' }],
output: `
export class WithParameterProperty {
public constructor(readonly value: string) {}
}
`,
output: null,
},
{
filename: 'test.ts',
Expand All @@ -406,11 +398,7 @@ export class XXXX {
},
],
errors: [{ messageId: 'missingAccessibility' }],
output: `
export class XXXX {
public constructor(readonly samosa: string) {}
}
`,
output: null,
},
{
filename: 'test.ts',
Expand All @@ -426,11 +414,7 @@ class Test {
},
],
errors: [{ messageId: 'missingAccessibility' }],
output: `
class Test {
public constructor(readonly foo: string) {}
}
`,
output: null,
},
{
filename: 'test.ts',
Expand All @@ -453,14 +437,7 @@ class Test {
column: 3,
},
],
output: `
class Test {
x: number;
public getX() {
return this.x;
}
}
`,
output: null,
},
{
filename: 'test.ts',
Expand All @@ -483,14 +460,7 @@ class Test {
column: 3,
},
],
output: `
class Test {
private x: number;
getX() {
return this.x;
}
}
`,
output: null,
},
{
filename: 'test.ts',
Expand Down Expand Up @@ -522,14 +492,7 @@ class Test {
column: 3,
},
],
output: `
class Test {
x?: number;
getX?() {
return this.x;
}
}
`,
output: null,
},
{
filename: 'test.ts',
Expand Down Expand Up @@ -658,20 +621,7 @@ class Test {
},
],
options: [{ overrides: { constructors: 'no-public' } }],
output: `
class Test {
private x: number;
constructor(x: number) {
this.x = x;
}
get internalValue() {
return this.x;
}
set internalValue(value: number) {
this.x = value;
}
}
`,
output: null,
},
{
filename: 'test.ts',
Expand Down Expand Up @@ -706,20 +656,7 @@ class Test {
column: 3,
},
],
output: `
class Test {
private x: number;
constructor(x: number) {
this.x = x;
}
get internalValue() {
return this.x;
}
set internalValue(value: number) {
this.x = value;
}
}
`,
output: null,
},
{
filename: 'test.ts',
Expand All @@ -743,14 +680,7 @@ class Test {
overrides: { parameterProperties: 'no-public' },
},
],
output: `
class Test {
constructor(public x: number) {}
public foo(): string {
return 'foo';
}
}
`,
output: null,
},
{
filename: 'test.ts',
Expand All @@ -766,11 +696,7 @@ class Test {
column: 3,
},
],
output: `
class Test {
constructor(public x: number) {}
}
`,
output: null,
},
{
filename: 'test.ts',
Expand Down Expand Up @@ -818,11 +744,7 @@ class Test {
column: 3,
},
],
output: `
class Test {
x = 2;
}
`,
output: null,
},
{
filename: 'test.ts',
Expand Down Expand Up @@ -866,11 +788,7 @@ class Test {
column: 3,
},
],
output: `
class Test {
constructor(public ...x: any[]) {}
}
`,
output: null,
},
{
filename: 'test.ts',
Expand Down
38 changes: 7 additions & 31 deletions packages/eslint-plugin/tests/rules/no-dynamic-delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ const container: { [i: string]: 0 } = {};
delete container['aa' + 'b'];
`,
errors: [{ messageId: 'dynamicDelete' }],
output: `
const container: { [i: string]: 0 } = {};
delete container['aa' + 'b'];
`,
output: null,
},
{
code: `
Expand All @@ -90,32 +87,23 @@ const container: { [i: string]: 0 } = {};
delete container[-Infinity];
`,
errors: [{ messageId: 'dynamicDelete' }],
output: `
const container: { [i: string]: 0 } = {};
delete container[-Infinity];
`,
output: null,
},
{
code: `
const container: { [i: string]: 0 } = {};
delete container[+Infinity];
`,
errors: [{ messageId: 'dynamicDelete' }],
output: `
const container: { [i: string]: 0 } = {};
delete container[+Infinity];
`,
output: null,
},
{
code: `
const container: { [i: string]: 0 } = {};
delete container[NaN];
`,
errors: [{ messageId: 'dynamicDelete' }],
output: `
const container: { [i: string]: 0 } = {};
delete container[NaN];
`,
output: null,
},
{
code: `
Expand All @@ -135,23 +123,15 @@ const name = 'name';
delete container[name];
`,
errors: [{ messageId: 'dynamicDelete' }],
output: `
const container: { [i: string]: 0 } = {};
const name = 'name';
delete container[name];
`,
output: null,
},
{
code: `
const container: { [i: string]: 0 } = {};
const getName = () => 'aaa';
delete container[getName()];
`,
output: `
const container: { [i: string]: 0 } = {};
const getName = () => 'aaa';
delete container[getName()];
`,
output: null,
errors: [{ messageId: 'dynamicDelete' }],
},
{
Expand All @@ -160,11 +140,7 @@ const container: { [i: string]: 0 } = {};
const name = { foo: { bar: 'bar' } };
delete container[name.foo.bar];
`,
output: `
const container: { [i: string]: 0 } = {};
const name = { foo: { bar: 'bar' } };
delete container[name.foo.bar];
`,
output: null,
errors: [{ messageId: 'dynamicDelete' }],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,7 @@ declare module FooBar {
},
],
// output matches input because a suggestion was made
output: `
declare module FooBar {
type Baz = typeof baz;
export interface Bar extends Baz {}
}
`.trimRight(),
output: null,
},
],
});
6 changes: 3 additions & 3 deletions packages/eslint-plugin/tests/rules/prefer-as-const.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ruleTester.run('prefer-as-const', rule, {
},
{
code: "let []: 'bar' = 'bar';",
output: "let []: 'bar' = 'bar';",
output: null,
errors: [
{
messageId: 'variableConstAssertion',
Expand All @@ -73,7 +73,7 @@ ruleTester.run('prefer-as-const', rule, {
},
{
code: "let foo: 'bar' = 'bar';",
output: "let foo: 'bar' = 'bar';",
output: null,
errors: [
{
messageId: 'variableConstAssertion',
Expand All @@ -90,7 +90,7 @@ ruleTester.run('prefer-as-const', rule, {
},
{
code: 'let foo: 2 = 2;',
output: 'let foo: 2 = 2;',
output: null,
errors: [
{
messageId: 'variableConstAssertion',
Expand Down