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

tests: add dependency constraints to eslint-plugin tests #5916

Merged
merged 13 commits into from Nov 17, 2022
Merged
21 changes: 21 additions & 0 deletions packages/eslint-plugin/tests/rules/consistent-type-exports.test.ts
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
25 changes: 20 additions & 5 deletions packages/eslint-plugin/tests/rules/consistent-type-imports.test.ts
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 @@ -118,11 +122,16 @@ ruleTester.run('consistent-type-imports', rule, {
`,
options: [{ prefer: 'no-type-imports' }],
},
`
import { type A, B } from 'foo';
type T = A;
const b = B;
`,
{
code: `
import { type A, B } from 'foo';
type T = A;
const b = B;
`,
dependencyConstraints: {
typescript: '4.5',
},
},
// exports
`
import Type from 'foo';
Expand Down Expand Up @@ -1804,6 +1813,9 @@ import { A, B } from 'foo';
type T = A;
const b = B;
`,
dependencyConstraints: {
typescript: '4.5',
},
options: [{ prefer: 'no-type-imports' }],
errors: [
{
Expand All @@ -1824,6 +1836,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
24 changes: 24 additions & 0 deletions packages/eslint-plugin/tests/rules/member-ordering.test.ts
Expand Up @@ -1250,6 +1250,9 @@ class Foo {
f = 1;
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [{ default: ['static-initialization', 'method', 'field'] }],
},
{
Expand All @@ -1260,6 +1263,9 @@ class Foo {
static {}
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [{ default: ['method', 'field', 'static-initialization'] }],
},
{
Expand All @@ -1270,6 +1276,9 @@ class Foo {
m() {}
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [{ default: ['field', 'static-initialization', 'method'] }],
},
`
Expand Down Expand Up @@ -4029,6 +4038,9 @@ class Foo {
f = 1;
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [{ default: ['method', 'field', 'static-initialization'] }],
errors: [
{
Expand Down Expand Up @@ -4059,6 +4071,9 @@ class Foo {
static {}
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [{ default: ['static-initialization', 'method', 'field'] }],
errors: [
{
Expand All @@ -4080,6 +4095,9 @@ class Foo {
m() {}
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [{ default: ['static-initialization', 'field', 'method'] }],
errors: [
{
Expand All @@ -4101,6 +4119,9 @@ class Foo {
m() {}
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [{ default: ['field', 'static-initialization', 'method'] }],
errors: [
{
Expand All @@ -4124,6 +4145,9 @@ class Foo {
md() {}
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [
{ default: ['decorated-method', 'static-initialization', 'method'] },
],
Expand Down
Expand Up @@ -499,6 +499,9 @@ class Foo {
static {}
}
`,
dependencyConstraints: {
typescript: '4.4',
},
options: [
{
default: {
Expand Down
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
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
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
Expand Up @@ -536,6 +536,9 @@ type Foo = {
[K in keyof Other]: \`\${K & number}\`;
};
`,
dependencyConstraints: {
typescript: '4.1',
},
options: [{ ignoreTypeIndexes: true }],
errors: [
{
Expand Down
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