Skip to content

Commit

Permalink
tests: add dependency constraints to eslint-plugin tests (#5916)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Nov 17, 2022
1 parent 5f7ce69 commit 4d46e65
Show file tree
Hide file tree
Showing 17 changed files with 287 additions and 112 deletions.
21 changes: 21 additions & 0 deletions packages/eslint-plugin/tests/rules/consistent-type-exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ export { type T, T };
type T = 1;
export type { T, T };
`,
dependencyConstraints: {
typescript: '4.5',
},
errors: [
{
messageId: 'typeOverValue',
Expand All @@ -283,6 +286,9 @@ export { type/* */T, type /* */T, T };
type T = 1;
export type { /* */T, /* */T, T };
`,
dependencyConstraints: {
typescript: '4.5',
},
errors: [
{
messageId: 'typeOverValue',
Expand All @@ -303,6 +309,9 @@ const x = 1;
export type { T, T };
export { x };
`,
dependencyConstraints: {
typescript: '4.5',
},
errors: [
{
messageId: 'singleExportIsType',
Expand All @@ -322,6 +331,9 @@ type T = 1;
const x = 1;
export { type T, x };
`,
dependencyConstraints: {
typescript: '4.5',
},
options: [{ fixMixedExportsWithInlineTypeSpecifier: true }],
errors: [
{
Expand All @@ -340,6 +352,9 @@ export { type T, T };
type T = 1;
export type { T, T };
`,
dependencyConstraints: {
typescript: '4.5',
},
options: [{ fixMixedExportsWithInlineTypeSpecifier: true }],
errors: [
{
Expand All @@ -362,6 +377,9 @@ export {
export type { AnalyzeOptions, Definition as Foo, BlockScope as BScope } from '@typescript-eslint/scope-manager';
export { CatchScope as CScope } from '@typescript-eslint/scope-manager';
`,
dependencyConstraints: {
typescript: '4.5',
},
options: [{ fixMixedExportsWithInlineTypeSpecifier: false }],
errors: [
{
Expand All @@ -388,6 +406,9 @@ export {
CatchScope as CScope,
} from '@typescript-eslint/scope-manager';
`,
dependencyConstraints: {
typescript: '4.5',
},
options: [{ fixMixedExportsWithInlineTypeSpecifier: true }],
errors: [
{
Expand Down
13 changes: 13 additions & 0 deletions packages/eslint-plugin/tests/rules/consistent-type-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const ruleTester = new RuleTester({
ecmaVersion: 2020,
sourceType: 'module',
},
// type-only imports were first added in TS3.8
dependencyConstraints: {
typescript: '3.8',
},
});

const withMetaParserOptions = {
Expand Down Expand Up @@ -191,6 +195,9 @@ ruleTester.run('consistent-type-imports', rule, {
const b = B;
`,
options: [{ prefer: 'no-type-imports', fixStyle: 'inline-type-imports' }],
dependencyConstraints: {
typescript: '4.5',
},
},
// exports
`
Expand Down Expand Up @@ -1891,6 +1898,9 @@ import { A, B } from 'foo';
type T = A;
const b = B;
`,
dependencyConstraints: {
typescript: '4.5',
},
options: [{ prefer: 'no-type-imports' }],
errors: [
{
Expand All @@ -1911,6 +1921,9 @@ import { B, type C } from 'foo';
type T = A | C;
const b = B;
`,
dependencyConstraints: {
typescript: '4.5',
},
options: [{ prefer: 'type-imports' }],
errors: [
{
Expand Down
27 changes: 27 additions & 0 deletions packages/eslint-plugin/tests/rules/member-ordering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ interface Foo {
}
`,
{
dependencyConstraints: {
typescript: '4.5',
},
code: `
// no accessibility === public
interface Foo {
Expand Down Expand Up @@ -1250,6 +1253,9 @@ class Foo {
f = 1;
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [{ default: ['static-initialization', 'method', 'field'] }],
},
{
Expand All @@ -1260,6 +1266,9 @@ class Foo {
static {}
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [{ default: ['method', 'field', 'static-initialization'] }],
},
{
Expand All @@ -1270,6 +1279,9 @@ class Foo {
m() {}
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [{ default: ['field', 'static-initialization', 'method'] }],
},
`
Expand Down Expand Up @@ -4029,6 +4041,9 @@ class Foo {
f = 1;
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [{ default: ['method', 'field', 'static-initialization'] }],
errors: [
{
Expand Down Expand Up @@ -4059,6 +4074,9 @@ class Foo {
static {}
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [{ default: ['static-initialization', 'method', 'field'] }],
errors: [
{
Expand All @@ -4080,6 +4098,9 @@ class Foo {
m() {}
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [{ default: ['static-initialization', 'field', 'method'] }],
errors: [
{
Expand All @@ -4101,6 +4122,9 @@ class Foo {
m() {}
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [{ default: ['field', 'static-initialization', 'method'] }],
errors: [
{
Expand All @@ -4124,6 +4148,9 @@ class Foo {
md() {}
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [
{ default: ['decorated-method', 'static-initialization', 'method'] },
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ class Foo {
static {}
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [
{
default: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,9 @@ class Foo {
static {}
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [
{
default: {
Expand Down
44 changes: 36 additions & 8 deletions packages/eslint-plugin/tests/rules/method-signature-style.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,42 @@ interface Test {
'f!': </* a */>(/* b */ x: any /* c */) => void;
}
`,
`
{
code: `
interface Test {
get f(): number;
}
`,
`
`,
dependencyConstraints: {
typescript: '4.3',
},
},
{
code: `
interface Test {
set f(value: number): void;
}
`,
`,
dependencyConstraints: {
typescript: '4.3',
},
},
'type Test = { readonly f: (a: string) => number };',
"type Test = { ['f']?: (a: boolean) => void };",
'type Test = { readonly f?: <T>(a?: T) => T };',
"type Test = { readonly ['f']?: <T>(a: T, b: T) => T };",
'type Test = { get f(): number };',
'type Test = { set f(value: number): void };',
{
code: 'type Test = { get f(): number };',
dependencyConstraints: {
typescript: '4.3',
},
},
{
code: 'type Test = { set f(value: number): void };',
dependencyConstraints: {
typescript: '4.3',
},
},
...batchedSingleLineTests({
options: ['method'],
code: noFormat`
Expand All @@ -56,15 +76,23 @@ interface Test {
interface Test { f<T>(a: T): T }
interface Test { ['f']<T extends {}>(a: T, b: T): T }
interface Test { 'f!'</* a */>(/* b */ x: any /* c */): void }
interface Test { get f(): number }
interface Test { set f(value: number): void }
type Test = { readonly f(a: string): number }
type Test = { ['f']?(a: boolean): void }
type Test = { readonly f?<T>(a?: T): T }
type Test = { readonly ['f']?<T>(a: T, b: T): T }
`,
}),
...batchedSingleLineTests({
options: ['method'],
code: noFormat`
interface Test { get f(): number }
interface Test { set f(value: number): void }
type Test = { get f(): number }
type Test = { set f(value: number): void }
`,
dependencyConstraints: {
typescript: '4.3',
},
}),
],
invalid: [
Expand Down
6 changes: 6 additions & 0 deletions packages/eslint-plugin/tests/rules/no-empty-function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class Foo extends Base {
override foo() {}
}
`,
dependencyConstraints: {
typescript: '4.3',
},
options: [{ allow: ['overrideMethods'] }],
},
],
Expand Down Expand Up @@ -206,6 +209,9 @@ class Foo extends Base {
override foo() {}
}
`,
dependencyConstraints: {
typescript: '4.3',
},
errors: [
{
messageId: 'unexpected',
Expand Down
3 changes: 3 additions & 0 deletions packages/eslint-plugin/tests/rules/no-magic-numbers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,9 @@ type Foo = {
[K in keyof Other]: \`\${K & number}\`;
};
`,
dependencyConstraints: {
typescript: '4.1',
},
options: [{ ignoreTypeIndexes: true }],
errors: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,21 @@ ruleTester.run('no-redundant-type-constituents', rule, {
type B = string;
type T = B & null;
`,
'type T = `${string}` & null;',
`
type B = \`\${string}\`;
type T = B & null;
`,
{
code: 'type T = `${string}` & null;',
dependencyConstraints: {
typescript: '4.1',
},
},
{
code: `
type B = \`\${string}\`;
type T = B & null;
`,
dependencyConstraints: {
typescript: '4.1',
},
},
],

invalid: [
Expand Down Expand Up @@ -442,6 +452,9 @@ ruleTester.run('no-redundant-type-constituents', rule, {
},
{
code: 'type T = `a${number}c` | string;',
dependencyConstraints: {
typescript: '4.1',
},
errors: [
{
column: 10,
Expand All @@ -458,6 +471,9 @@ ruleTester.run('no-redundant-type-constituents', rule, {
type B = \`a\${number}c\`;
type T = B | string;
`,
dependencyConstraints: {
typescript: '4.1',
},
errors: [
{
column: 18,
Expand All @@ -471,6 +487,9 @@ ruleTester.run('no-redundant-type-constituents', rule, {
},
{
code: 'type T = `${number}` | string;',
dependencyConstraints: {
typescript: '4.1',
},
errors: [
{
column: 10,
Expand Down
Loading

0 comments on commit 4d46e65

Please sign in to comment.