@definitelytyped/eslint-plugin 0.0.166-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/configs/all.d.ts +2 -0
- package/dist/configs/all.js +152 -0
- package/dist/configs/all.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/rules/dt-header.d.ts +2 -0
- package/dist/rules/dt-header.js +62 -0
- package/dist/rules/dt-header.js.map +1 -0
- package/dist/rules/export-just-namespace.d.ts +2 -0
- package/dist/rules/export-just-namespace.js +70 -0
- package/dist/rules/export-just-namespace.js.map +1 -0
- package/dist/rules/index.d.ts +38 -0
- package/dist/rules/index.js +61 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/no-any-union.d.ts +4 -0
- package/dist/rules/no-any-union.js +34 -0
- package/dist/rules/no-any-union.js.map +1 -0
- package/dist/rules/no-bad-reference.d.ts +2 -0
- package/dist/rules/no-bad-reference.js +55 -0
- package/dist/rules/no-bad-reference.js.map +1 -0
- package/dist/rules/no-const-enum.d.ts +4 -0
- package/dist/rules/no-const-enum.js +30 -0
- package/dist/rules/no-const-enum.js.map +1 -0
- package/dist/rules/no-dead-reference.d.ts +2 -0
- package/dist/rules/no-dead-reference.js +44 -0
- package/dist/rules/no-dead-reference.js.map +1 -0
- package/dist/rules/no-declare-current-package.d.ts +4 -0
- package/dist/rules/no-declare-current-package.js +43 -0
- package/dist/rules/no-declare-current-package.js.map +1 -0
- package/dist/rules/no-import-default-of-export-equals.d.ts +4 -0
- package/dist/rules/no-import-default-of-export-equals.js +87 -0
- package/dist/rules/no-import-default-of-export-equals.js.map +1 -0
- package/dist/rules/no-outside-dependencies.d.ts +2 -0
- package/dist/rules/no-outside-dependencies.js +41 -0
- package/dist/rules/no-outside-dependencies.js.map +1 -0
- package/dist/rules/no-self-import.d.ts +4 -0
- package/dist/rules/no-self-import.js +38 -0
- package/dist/rules/no-self-import.js.map +1 -0
- package/dist/rules/no-single-element-tuple-type.d.ts +5 -0
- package/dist/rules/no-single-element-tuple-type.js +30 -0
- package/dist/rules/no-single-element-tuple-type.js.map +1 -0
- package/dist/rules/no-unnecessary-generics.d.ts +8 -0
- package/dist/rules/no-unnecessary-generics.js +135 -0
- package/dist/rules/no-unnecessary-generics.js.map +1 -0
- package/dist/rules/no-useless-files.d.ts +2 -0
- package/dist/rules/no-useless-files.js +53 -0
- package/dist/rules/no-useless-files.js.map +1 -0
- package/dist/rules/prefer-declare-function.d.ts +5 -0
- package/dist/rules/prefer-declare-function.js +35 -0
- package/dist/rules/prefer-declare-function.js.map +1 -0
- package/dist/rules/redundant-undefined.d.ts +4 -0
- package/dist/rules/redundant-undefined.js +53 -0
- package/dist/rules/redundant-undefined.js.map +1 -0
- package/dist/rules/trim-file.d.ts +2 -0
- package/dist/rules/trim-file.js +43 -0
- package/dist/rules/trim-file.js.map +1 -0
- package/dist/util.d.ts +4 -0
- package/dist/util.js +38 -0
- package/dist/util.js.map +1 -0
- package/docs/rules/dt-header.md +88 -0
- package/docs/rules/export-just-namespace.md +29 -0
- package/docs/rules/no-any-union.md +27 -0
- package/docs/rules/no-bad-reference.md +28 -0
- package/docs/rules/no-const-enum.md +16 -0
- package/docs/rules/no-dead-reference.md +17 -0
- package/docs/rules/no-declare-current-package.md +35 -0
- package/docs/rules/no-import-default-of-export-equals.md +22 -0
- package/docs/rules/no-outside-dependencies.md +23 -0
- package/docs/rules/no-self-import.md +27 -0
- package/docs/rules/no-single-element-tuple-type.md +15 -0
- package/docs/rules/no-unnecessary-generics.md +69 -0
- package/docs/rules/no-useless-files.md +14 -0
- package/docs/rules/prefer-declare-function.md +15 -0
- package/docs/rules/redundant-undefined.md +15 -0
- package/docs/rules/trim-file.md +17 -0
- package/package.json +45 -0
- package/src/configs/all.ts +151 -0
- package/src/index.ts +6 -0
- package/src/rules/dt-header.ts +74 -0
- package/src/rules/export-just-namespace.ts +83 -0
- package/src/rules/index.ts +35 -0
- package/src/rules/no-any-union.ts +34 -0
- package/src/rules/no-bad-reference.ts +62 -0
- package/src/rules/no-const-enum.ts +30 -0
- package/src/rules/no-dead-reference.ts +46 -0
- package/src/rules/no-declare-current-package.ts +45 -0
- package/src/rules/no-import-default-of-export-equals.ts +68 -0
- package/src/rules/no-outside-dependencies.ts +42 -0
- package/src/rules/no-self-import.ts +40 -0
- package/src/rules/no-single-element-tuple-type.ts +31 -0
- package/src/rules/no-unnecessary-generics.ts +126 -0
- package/src/rules/no-useless-files.ts +58 -0
- package/src/rules/prefer-declare-function.ts +37 -0
- package/src/rules/redundant-undefined.ts +62 -0
- package/src/rules/trim-file.ts +45 -0
- package/src/util.ts +41 -0
- package/test/dt-header.test.ts +189 -0
- package/test/export-just-namespace.test.ts +70 -0
- package/test/no-any-union.test.ts +22 -0
- package/test/no-bad-reference.test.ts +66 -0
- package/test/no-const-enum.test.ts +22 -0
- package/test/no-dead-reference.test.ts +66 -0
- package/test/no-declare-current-package.test.ts +61 -0
- package/test/no-import-default-of-export-equals.test.ts +49 -0
- package/test/no-self-import.test.ts +47 -0
- package/test/no-single-element-tuple-type.test.ts +28 -0
- package/test/no-unnecessary-generics.test.ts +152 -0
- package/test/no-useless-files.test.ts +42 -0
- package/test/prefer-declare-function.test.ts +66 -0
- package/test/redundant-undefined.test.ts +39 -0
- package/test/trim-file.test.ts +46 -0
- package/test/tsconfig.json +10 -0
- package/test/tsconfig.no-declare-current-package.json +11 -0
- package/test/tsconfig.no-declare-current-package2.json +11 -0
- package/test/tsconfig.no-import-default-of-export-equals.json +11 -0
- package/test/tsconfig.no-self-import.json +7 -0
- package/tsconfig.json +9 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
import * as noAnyUnion from "../src/rules/no-any-union";
|
|
4
|
+
|
|
5
|
+
const ruleTester = new ESLintUtils.RuleTester({
|
|
6
|
+
parser: "@typescript-eslint/parser",
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
ruleTester.run("@definitelytyped/no-any-union", noAnyUnion, {
|
|
10
|
+
invalid: [
|
|
11
|
+
{
|
|
12
|
+
code: `export const y: string | any;`,
|
|
13
|
+
errors: [
|
|
14
|
+
{
|
|
15
|
+
line: 1,
|
|
16
|
+
messageId: "anyUnion",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
valid: [`export const x: any;`],
|
|
22
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
import * as noBadReference from "../src/rules/no-bad-reference";
|
|
4
|
+
|
|
5
|
+
const ruleTester = new ESLintUtils.RuleTester({
|
|
6
|
+
parser: "@typescript-eslint/parser",
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
ruleTester.run("@definitelytyped/no-bad-reference", noBadReference, {
|
|
10
|
+
invalid: [
|
|
11
|
+
{
|
|
12
|
+
code: `/// <reference path="../other" />`,
|
|
13
|
+
errors: [
|
|
14
|
+
{
|
|
15
|
+
column: 20,
|
|
16
|
+
endColumn: 28,
|
|
17
|
+
line: 1,
|
|
18
|
+
messageId: "referencePathTest",
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
filename: "types.ts",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
code: `/// <reference path="other" />`,
|
|
25
|
+
errors: [
|
|
26
|
+
{
|
|
27
|
+
column: 20,
|
|
28
|
+
endColumn: 25,
|
|
29
|
+
line: 1,
|
|
30
|
+
messageId: "referencePathTest",
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
filename: "types.ts",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
code: `/// <reference path="../other" />`,
|
|
37
|
+
errors: [
|
|
38
|
+
{
|
|
39
|
+
column: 20,
|
|
40
|
+
endColumn: 28,
|
|
41
|
+
line: 1,
|
|
42
|
+
messageId: "referencePathPackage",
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
filename: "types.d.ts",
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
valid: [
|
|
49
|
+
``,
|
|
50
|
+
`// unrelated comment`,
|
|
51
|
+
`/// similar (reference path) comment`,
|
|
52
|
+
{
|
|
53
|
+
code: `/// <reference path="other" />`,
|
|
54
|
+
filename: "types.d.ts",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
code: `/// <reference path="./other" />`,
|
|
58
|
+
filename: "types.d.ts",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
code: `/// <reference path="other" />
|
|
62
|
+
/// <reference path="other2" />`,
|
|
63
|
+
filename: "types.d.ts",
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
import * as noConstEnum from "../src/rules/no-const-enum";
|
|
4
|
+
|
|
5
|
+
const ruleTester = new ESLintUtils.RuleTester({
|
|
6
|
+
parser: "@typescript-eslint/parser",
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
ruleTester.run("@definitelytyped/no-const-enum", noConstEnum, {
|
|
10
|
+
invalid: [
|
|
11
|
+
{
|
|
12
|
+
code: ` const enum E { } `,
|
|
13
|
+
errors: [
|
|
14
|
+
{
|
|
15
|
+
line: 1,
|
|
16
|
+
messageId: "constEnum",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
valid: [` enum F {}`],
|
|
22
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
import * as noDeadReference from "../src/rules/no-dead-reference";
|
|
4
|
+
|
|
5
|
+
const ruleTester = new ESLintUtils.RuleTester({
|
|
6
|
+
parser: "@typescript-eslint/parser",
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
ruleTester.run("@definitelytyped/no-dead-reference", noDeadReference, {
|
|
10
|
+
invalid: [
|
|
11
|
+
{
|
|
12
|
+
code: `
|
|
13
|
+
export class C { }
|
|
14
|
+
/// <reference types="terms" />
|
|
15
|
+
`,
|
|
16
|
+
errors: [
|
|
17
|
+
{
|
|
18
|
+
line: 3,
|
|
19
|
+
messageId: "referenceAtTop",
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
code: `
|
|
25
|
+
export class C { }
|
|
26
|
+
/// <reference types="terms" />
|
|
27
|
+
/// <reference types="multiple" />
|
|
28
|
+
`,
|
|
29
|
+
errors: [
|
|
30
|
+
{
|
|
31
|
+
line: 3,
|
|
32
|
+
messageId: "referenceAtTop",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
line: 4,
|
|
36
|
+
messageId: "referenceAtTop",
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
code: `
|
|
42
|
+
export class C { }
|
|
43
|
+
/// <reference types="terms" />
|
|
44
|
+
export class D { }
|
|
45
|
+
/// <reference types="multiple" />
|
|
46
|
+
export class E { }
|
|
47
|
+
`,
|
|
48
|
+
errors: [
|
|
49
|
+
{
|
|
50
|
+
line: 3,
|
|
51
|
+
messageId: "referenceAtTop",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
line: 5,
|
|
55
|
+
messageId: "referenceAtTop",
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
valid: [
|
|
61
|
+
`
|
|
62
|
+
/// <reference types="tones" />
|
|
63
|
+
export class K {}
|
|
64
|
+
`,
|
|
65
|
+
],
|
|
66
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
import * as noDeclareCurrentPackage from "../src/rules/no-declare-current-package";
|
|
4
|
+
|
|
5
|
+
const ruleTester = new ESLintUtils.RuleTester({
|
|
6
|
+
parser: "@typescript-eslint/parser",
|
|
7
|
+
parserOptions: {
|
|
8
|
+
ecmaVersion: 2018,
|
|
9
|
+
tsconfigRootDir: __dirname,
|
|
10
|
+
project: "./tsconfig.no-declare-current-package.json",
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
ruleTester.run("@definitelytyped/no-declare-current-package", noDeclareCurrentPackage, {
|
|
15
|
+
invalid: [
|
|
16
|
+
{
|
|
17
|
+
filename: "index.d.ts",
|
|
18
|
+
code: `module "test" { }`,
|
|
19
|
+
errors: [
|
|
20
|
+
{
|
|
21
|
+
line: 1,
|
|
22
|
+
messageId: "noDeclareCurrentPackage",
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
valid: [
|
|
28
|
+
{
|
|
29
|
+
filename: "index.d.ts",
|
|
30
|
+
code: `module "foo" { }
|
|
31
|
+
module "foo/bar/baz" { }
|
|
32
|
+
`,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
// needed because you can only test one non-file.ts file per tsconfig
|
|
37
|
+
// (and tsconfig is required for typed-based rules)
|
|
38
|
+
const ruleTester2 = new ESLintUtils.RuleTester({
|
|
39
|
+
parser: "@typescript-eslint/parser",
|
|
40
|
+
parserOptions: {
|
|
41
|
+
ecmaVersion: 2018,
|
|
42
|
+
tsconfigRootDir: __dirname,
|
|
43
|
+
project: "./tsconfig.no-declare-current-package2.json",
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
ruleTester2.run("no-declare-current-package", noDeclareCurrentPackage, {
|
|
48
|
+
invalid: [
|
|
49
|
+
{
|
|
50
|
+
filename: "deep/import.d.ts",
|
|
51
|
+
code: `module "test/deep/import" { }`,
|
|
52
|
+
errors: [
|
|
53
|
+
{
|
|
54
|
+
line: 1,
|
|
55
|
+
messageId: "noDeclareCurrentPackage",
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
valid: [],
|
|
61
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
import * as noImportDefaultOfExportEquals from "../src/rules/no-import-default-of-export-equals";
|
|
4
|
+
|
|
5
|
+
const ruleTester = new ESLintUtils.RuleTester({
|
|
6
|
+
parser: "@typescript-eslint/parser",
|
|
7
|
+
parserOptions: {
|
|
8
|
+
ecmaVersion: 2018,
|
|
9
|
+
tsconfigRootDir: __dirname,
|
|
10
|
+
project: "./tsconfig.no-import-default-of-export-equals.json",
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
ruleTester.run("@definitelytyped/no-import-default-of-export-equals", noImportDefaultOfExportEquals, {
|
|
15
|
+
invalid: [
|
|
16
|
+
{
|
|
17
|
+
filename: "index.d.ts",
|
|
18
|
+
code: `declare module "a" {
|
|
19
|
+
interface I {}
|
|
20
|
+
export = I;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare module "b" {
|
|
24
|
+
import a from "a";
|
|
25
|
+
}`,
|
|
26
|
+
errors: [
|
|
27
|
+
{
|
|
28
|
+
line: 7,
|
|
29
|
+
messageId: "noImportDefaultOfExportEquals",
|
|
30
|
+
data: { moduleName: "a", importName: "a" },
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
valid: [
|
|
36
|
+
{
|
|
37
|
+
filename: "index.d.ts",
|
|
38
|
+
code: `declare module "a" {
|
|
39
|
+
interface I {}
|
|
40
|
+
export default I;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare module "b" {
|
|
44
|
+
import a from "a";
|
|
45
|
+
}
|
|
46
|
+
`,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
import * as dtHeader from "../src/rules/no-self-import";
|
|
5
|
+
|
|
6
|
+
const ruleTester = new ESLintUtils.RuleTester({
|
|
7
|
+
parser: "@typescript-eslint/parser",
|
|
8
|
+
parserOptions: {
|
|
9
|
+
tsconfigRootDir: __dirname,
|
|
10
|
+
project: "./tsconfig.no-self-import.json",
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
ruleTester.run("@definitelytyped/no-self-import", dtHeader, {
|
|
15
|
+
invalid: [
|
|
16
|
+
{
|
|
17
|
+
code: `import myself from "this-package";`,
|
|
18
|
+
errors: [
|
|
19
|
+
{
|
|
20
|
+
line: 1,
|
|
21
|
+
messageId: "useRelativeImport",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
filename: "this-package/index.d.ts",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
code: `import abc from "this-package/abc.d.ts";`,
|
|
28
|
+
errors: [
|
|
29
|
+
{
|
|
30
|
+
line: 1,
|
|
31
|
+
messageId: "useRelativeImport",
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
filename: "this-package/index.d.ts",
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
valid: [
|
|
38
|
+
{
|
|
39
|
+
code: `import other from "other-package";`,
|
|
40
|
+
filename: "this-package/index.d.ts",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
code: `import other from "other-package/this-package";`,
|
|
44
|
+
filename: "this-package/index.d.ts",
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
import * as noDeclareCurrentPackage from "../src/rules/no-single-element-tuple-type";
|
|
4
|
+
|
|
5
|
+
const ruleTester = new ESLintUtils.RuleTester({
|
|
6
|
+
parser: "@typescript-eslint/parser",
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
ruleTester.run("@definitelytyped/no-single-element-tuple-type", noDeclareCurrentPackage, {
|
|
10
|
+
invalid: [
|
|
11
|
+
{
|
|
12
|
+
code: `type Test<T> = [T];`,
|
|
13
|
+
errors: [
|
|
14
|
+
{
|
|
15
|
+
line: 1,
|
|
16
|
+
messageId: "singleElementTupleType",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
valid: [
|
|
22
|
+
`type Test = number[];`,
|
|
23
|
+
`type Test<T> = T;`,
|
|
24
|
+
`type Test<T> = T[];`,
|
|
25
|
+
`type Test<T> = [T, number];`,
|
|
26
|
+
`type Test<T> = [T, T];`,
|
|
27
|
+
],
|
|
28
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
import * as rule from "../src/rules/no-unnecessary-generics";
|
|
4
|
+
|
|
5
|
+
const ruleTester = new ESLintUtils.RuleTester({
|
|
6
|
+
parserOptions: {
|
|
7
|
+
ecmaVersion: 2018,
|
|
8
|
+
tsconfigRootDir: __dirname,
|
|
9
|
+
project: "./tsconfig.json",
|
|
10
|
+
},
|
|
11
|
+
parser: "@typescript-eslint/parser",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
ruleTester.run("@definitelytyped/no-unnecessary-generics", rule, {
|
|
15
|
+
invalid: [
|
|
16
|
+
{
|
|
17
|
+
code: `
|
|
18
|
+
const f2 = <T>(): T => {};
|
|
19
|
+
`,
|
|
20
|
+
errors: [
|
|
21
|
+
{
|
|
22
|
+
line: 2,
|
|
23
|
+
column: 19,
|
|
24
|
+
messageId: "sole",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
code: `
|
|
30
|
+
class C {
|
|
31
|
+
constructor<T>(x: T) {}
|
|
32
|
+
}
|
|
33
|
+
`,
|
|
34
|
+
errors: [
|
|
35
|
+
{
|
|
36
|
+
line: 3,
|
|
37
|
+
column: 21,
|
|
38
|
+
messageId: "sole",
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
code: `
|
|
44
|
+
function f<T>(): T { }
|
|
45
|
+
`,
|
|
46
|
+
errors: [
|
|
47
|
+
{
|
|
48
|
+
line: 2,
|
|
49
|
+
column: 18,
|
|
50
|
+
messageId: "sole",
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
code: `
|
|
56
|
+
function f<T>(x: { T: number }): void;
|
|
57
|
+
`,
|
|
58
|
+
errors: [
|
|
59
|
+
{
|
|
60
|
+
line: 2,
|
|
61
|
+
column: 12,
|
|
62
|
+
messageId: "never",
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
code: `
|
|
68
|
+
function f<T, U extends T>(u: U): U;
|
|
69
|
+
`,
|
|
70
|
+
errors: [
|
|
71
|
+
{
|
|
72
|
+
line: 2,
|
|
73
|
+
column: 25,
|
|
74
|
+
messageId: "sole",
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
code: `
|
|
80
|
+
const f = function<T>(): T {};
|
|
81
|
+
`,
|
|
82
|
+
errors: [
|
|
83
|
+
{
|
|
84
|
+
line: 2,
|
|
85
|
+
column: 26,
|
|
86
|
+
messageId: "sole",
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
code: `
|
|
92
|
+
interface I {
|
|
93
|
+
<T>(value: T): void;
|
|
94
|
+
}
|
|
95
|
+
`,
|
|
96
|
+
errors: [
|
|
97
|
+
{
|
|
98
|
+
line: 3,
|
|
99
|
+
column: 14,
|
|
100
|
+
messageId: "sole",
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
code: `
|
|
106
|
+
interface I {
|
|
107
|
+
m<T>(x: T): void;
|
|
108
|
+
}
|
|
109
|
+
`,
|
|
110
|
+
errors: [
|
|
111
|
+
{
|
|
112
|
+
line: 3,
|
|
113
|
+
column: 11,
|
|
114
|
+
messageId: "sole",
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
code: `
|
|
120
|
+
type Fn = <T>() => T;
|
|
121
|
+
`,
|
|
122
|
+
errors: [
|
|
123
|
+
{
|
|
124
|
+
line: 2,
|
|
125
|
+
column: 20,
|
|
126
|
+
messageId: "sole",
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
code: `
|
|
132
|
+
type Ctr = new<T>() => T;
|
|
133
|
+
`,
|
|
134
|
+
errors: [
|
|
135
|
+
{
|
|
136
|
+
line: 2,
|
|
137
|
+
column: 24,
|
|
138
|
+
messageId: "sole",
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
valid: [
|
|
144
|
+
`function example(a: string): string;`,
|
|
145
|
+
`function example<T>(a: T): T;`,
|
|
146
|
+
`function example<T>(a: T[]): T;`,
|
|
147
|
+
`function example<T>(a: Set<T>): T;`,
|
|
148
|
+
`function example<T>(a: Set<T>, b: T[]): void;`,
|
|
149
|
+
`function example<T>(a: Map<T, T>): void;`,
|
|
150
|
+
`function example<T, U extends T>(t: T, u: U): U;`,
|
|
151
|
+
],
|
|
152
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
import * as noUselessFiles from "../src/rules/no-useless-files";
|
|
3
|
+
|
|
4
|
+
const ruleTester = new ESLintUtils.RuleTester({
|
|
5
|
+
parser: "@typescript-eslint/parser",
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
ruleTester.run("@definitelytyped/no-useless-files", noUselessFiles, {
|
|
9
|
+
invalid: [
|
|
10
|
+
{
|
|
11
|
+
code: `// I am useless`,
|
|
12
|
+
errors: [
|
|
13
|
+
{
|
|
14
|
+
column: 1,
|
|
15
|
+
line: 1,
|
|
16
|
+
messageId: "noContent",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
code: ``,
|
|
22
|
+
errors: [
|
|
23
|
+
{
|
|
24
|
+
column: 1,
|
|
25
|
+
line: 1,
|
|
26
|
+
messageId: "noContent",
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
code: `/// <reference lib="baz" />`,
|
|
32
|
+
errors: [
|
|
33
|
+
{
|
|
34
|
+
column: 1,
|
|
35
|
+
line: 1,
|
|
36
|
+
messageId: "noContent",
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
valid: [`export default "I am useful";`, `/// <reference path="foo" />`, `/// <reference types="bar" />`],
|
|
42
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
import * as preferDeclareFunction from "../src/rules/prefer-declare-function";
|
|
4
|
+
|
|
5
|
+
const ruleTester = new ESLintUtils.RuleTester({
|
|
6
|
+
parser: "@typescript-eslint/parser",
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
ruleTester.run("@definitelytyped/prefer-declare-function", preferDeclareFunction, {
|
|
10
|
+
invalid: [
|
|
11
|
+
{
|
|
12
|
+
filename: "index.d.ts",
|
|
13
|
+
code: `export const example: () => void;`,
|
|
14
|
+
errors: [
|
|
15
|
+
{
|
|
16
|
+
column: 14,
|
|
17
|
+
endColumn: 33,
|
|
18
|
+
line: 1,
|
|
19
|
+
messageId: "variableFunction",
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
filename: "index.d.ts",
|
|
25
|
+
code: `
|
|
26
|
+
namespace N {
|
|
27
|
+
export const example: () => void;
|
|
28
|
+
}
|
|
29
|
+
`,
|
|
30
|
+
errors: [
|
|
31
|
+
{
|
|
32
|
+
column: 26,
|
|
33
|
+
endColumn: 45,
|
|
34
|
+
line: 3,
|
|
35
|
+
messageId: "variableFunction",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
filename: "index.d.ts",
|
|
41
|
+
code: `
|
|
42
|
+
namespace N {
|
|
43
|
+
const example: () => void;
|
|
44
|
+
}
|
|
45
|
+
`,
|
|
46
|
+
errors: [
|
|
47
|
+
{
|
|
48
|
+
column: 19,
|
|
49
|
+
endColumn: 38,
|
|
50
|
+
line: 3,
|
|
51
|
+
messageId: "variableFunction",
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
valid: [
|
|
57
|
+
{
|
|
58
|
+
filename: "index.d.ts",
|
|
59
|
+
code: `function example(): void`,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
filename: "test.ts",
|
|
63
|
+
code: `export const example: () => void;`,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
import * as redundantUndefined from "../src/rules/redundant-undefined";
|
|
4
|
+
|
|
5
|
+
const ruleTester = new ESLintUtils.RuleTester({
|
|
6
|
+
parser: "@typescript-eslint/parser",
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
ruleTester.run("@definitelytyped/redundant-undefined", redundantUndefined, {
|
|
10
|
+
invalid: [
|
|
11
|
+
{
|
|
12
|
+
code: `function f(s?: string | undefined): void {}`,
|
|
13
|
+
errors: [
|
|
14
|
+
{
|
|
15
|
+
line: 1,
|
|
16
|
+
messageId: "redundantUndefined",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
code: `function f([a, b]?: [number, number] | undefined): void {}`,
|
|
22
|
+
errors: [
|
|
23
|
+
{
|
|
24
|
+
line: 1,
|
|
25
|
+
messageId: "redundantUndefined",
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
valid: [
|
|
31
|
+
`
|
|
32
|
+
interface I {
|
|
33
|
+
ok?: string | undefined;
|
|
34
|
+
s?: string;
|
|
35
|
+
almost?: number | string;
|
|
36
|
+
}
|
|
37
|
+
`,
|
|
38
|
+
],
|
|
39
|
+
});
|