@definitelytyped/dtslint 0.0.166-next.3 → 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.
Files changed (109) hide show
  1. package/dist/lint.js +1 -3
  2. package/dist/lint.js.map +1 -1
  3. package/dist/util.d.ts +0 -4
  4. package/dist/util.js +1 -23
  5. package/dist/util.js.map +1 -1
  6. package/package.json +2 -2
  7. package/src/lint.ts +1 -3
  8. package/src/util.ts +0 -25
  9. package/tsconfig.tsbuildinfo +1 -1
  10. package/dist/rules/dt-header.d.ts +0 -2
  11. package/dist/rules/dt-header.js +0 -62
  12. package/dist/rules/dt-header.js.map +0 -1
  13. package/dist/rules/export-just-namespace.d.ts +0 -2
  14. package/dist/rules/export-just-namespace.js +0 -70
  15. package/dist/rules/export-just-namespace.js.map +0 -1
  16. package/dist/rules/no-any-union.d.ts +0 -4
  17. package/dist/rules/no-any-union.js +0 -34
  18. package/dist/rules/no-any-union.js.map +0 -1
  19. package/dist/rules/no-bad-reference.d.ts +0 -2
  20. package/dist/rules/no-bad-reference.js +0 -55
  21. package/dist/rules/no-bad-reference.js.map +0 -1
  22. package/dist/rules/no-const-enum.d.ts +0 -4
  23. package/dist/rules/no-const-enum.js +0 -30
  24. package/dist/rules/no-const-enum.js.map +0 -1
  25. package/dist/rules/no-dead-reference.d.ts +0 -2
  26. package/dist/rules/no-dead-reference.js +0 -44
  27. package/dist/rules/no-dead-reference.js.map +0 -1
  28. package/dist/rules/no-declare-current-package.d.ts +0 -4
  29. package/dist/rules/no-declare-current-package.js +0 -43
  30. package/dist/rules/no-declare-current-package.js.map +0 -1
  31. package/dist/rules/no-import-default-of-export-equals.d.ts +0 -4
  32. package/dist/rules/no-import-default-of-export-equals.js +0 -87
  33. package/dist/rules/no-import-default-of-export-equals.js.map +0 -1
  34. package/dist/rules/no-outside-dependencies.d.ts +0 -2
  35. package/dist/rules/no-outside-dependencies.js +0 -41
  36. package/dist/rules/no-outside-dependencies.js.map +0 -1
  37. package/dist/rules/no-self-import.d.ts +0 -4
  38. package/dist/rules/no-self-import.js +0 -38
  39. package/dist/rules/no-self-import.js.map +0 -1
  40. package/dist/rules/no-single-element-tuple-type.d.ts +0 -5
  41. package/dist/rules/no-single-element-tuple-type.js +0 -30
  42. package/dist/rules/no-single-element-tuple-type.js.map +0 -1
  43. package/dist/rules/no-unnecessary-generics.d.ts +0 -8
  44. package/dist/rules/no-unnecessary-generics.js +0 -135
  45. package/dist/rules/no-unnecessary-generics.js.map +0 -1
  46. package/dist/rules/no-useless-files.d.ts +0 -2
  47. package/dist/rules/no-useless-files.js +0 -53
  48. package/dist/rules/no-useless-files.js.map +0 -1
  49. package/dist/rules/prefer-declare-function.d.ts +0 -5
  50. package/dist/rules/prefer-declare-function.js +0 -35
  51. package/dist/rules/prefer-declare-function.js.map +0 -1
  52. package/dist/rules/redundant-undefined.d.ts +0 -4
  53. package/dist/rules/redundant-undefined.js +0 -53
  54. package/dist/rules/redundant-undefined.js.map +0 -1
  55. package/dist/rules/trim-file.d.ts +0 -2
  56. package/dist/rules/trim-file.js +0 -43
  57. package/dist/rules/trim-file.js.map +0 -1
  58. package/docs/dt-header.md +0 -88
  59. package/docs/export-just-namespace.md +0 -29
  60. package/docs/no-any-union.md +0 -27
  61. package/docs/no-bad-reference.md +0 -28
  62. package/docs/no-const-enum.md +0 -16
  63. package/docs/no-dead-reference.md +0 -17
  64. package/docs/no-declare-current-package.md +0 -35
  65. package/docs/no-import-default-of-export-equals.md +0 -22
  66. package/docs/no-outside-dependencies.md +0 -23
  67. package/docs/no-self-import.md +0 -27
  68. package/docs/no-single-element-tuple-type.md +0 -15
  69. package/docs/no-unnecessary-generics.md +0 -69
  70. package/docs/no-useless-files.md +0 -14
  71. package/docs/prefer-declare-function.md +0 -15
  72. package/docs/redundant-undefined.md +0 -15
  73. package/docs/trim-file.md +0 -17
  74. package/src/rules/dt-header.ts +0 -74
  75. package/src/rules/export-just-namespace.ts +0 -83
  76. package/src/rules/no-any-union.ts +0 -34
  77. package/src/rules/no-bad-reference.ts +0 -62
  78. package/src/rules/no-const-enum.ts +0 -30
  79. package/src/rules/no-dead-reference.ts +0 -46
  80. package/src/rules/no-declare-current-package.ts +0 -45
  81. package/src/rules/no-import-default-of-export-equals.ts +0 -68
  82. package/src/rules/no-outside-dependencies.ts +0 -42
  83. package/src/rules/no-self-import.ts +0 -40
  84. package/src/rules/no-single-element-tuple-type.ts +0 -31
  85. package/src/rules/no-unnecessary-generics.ts +0 -126
  86. package/src/rules/no-useless-files.ts +0 -58
  87. package/src/rules/prefer-declare-function.ts +0 -37
  88. package/src/rules/redundant-undefined.ts +0 -62
  89. package/src/rules/trim-file.ts +0 -45
  90. package/test/dt-header.test.ts +0 -189
  91. package/test/export-just-namespace.test.ts +0 -70
  92. package/test/no-any-union.test.ts +0 -22
  93. package/test/no-bad-reference.test.ts +0 -66
  94. package/test/no-const-enum.test.ts +0 -22
  95. package/test/no-dead-reference.test.ts +0 -66
  96. package/test/no-declare-current-package.test.ts +0 -61
  97. package/test/no-import-default-of-export-equals.test.ts +0 -49
  98. package/test/no-self-import.test.ts +0 -47
  99. package/test/no-single-element-tuple-type.test.ts +0 -28
  100. package/test/no-unnecessary-generics.test.ts +0 -152
  101. package/test/no-useless-files.test.ts +0 -42
  102. package/test/prefer-declare-function.test.ts +0 -66
  103. package/test/redundant-undefined.test.ts +0 -39
  104. package/test/trim-file.test.ts +0 -46
  105. package/test/tsconfig.json +0 -10
  106. package/test/tsconfig.no-declare-current-package.json +0 -11
  107. package/test/tsconfig.no-declare-current-package2.json +0 -11
  108. package/test/tsconfig.no-import-default-of-export-equals.json +0 -11
  109. package/test/tsconfig.no-self-import.json +0 -7
@@ -1,27 +0,0 @@
1
- # no-self-import
2
-
3
- A package should not import components of itself using a globally-qualified name; it should use relative imports instead.
4
-
5
- **Bad**:
6
-
7
- ```ts
8
- import foo from "this-package/foo.d.ts";
9
- ```
10
-
11
- **Good**:
12
-
13
- ```ts
14
- import foo from "./foo.d.ts";
15
- ```
16
-
17
- **Bad**:
18
-
19
- ```ts
20
- import myself from "this-package";
21
- ```
22
-
23
- **Good**:
24
-
25
- ```ts
26
- import myself from ".";
27
- ```
@@ -1,15 +0,0 @@
1
- # no-single-element-tuple-type
2
-
3
- Some users mistakenly write `[T]` when then intend to write an array type `T[]`.
4
-
5
- **Bad**:
6
-
7
- ```ts
8
- export const x: [T];
9
- ```
10
-
11
- **Good**:
12
-
13
- ```ts
14
- export const x: T[];
15
- ```
@@ -1,69 +0,0 @@
1
- # no-unnecessary-generics
2
-
3
- Forbids a function to use a generic type parameter only once.
4
- Generic type parameters allow you to relate the type of one thing to another;
5
- if they are used only once, they can be replaced with their type constraint.
6
-
7
- **Bad**:
8
-
9
- ```ts
10
- function logAnything<T>(x: T): void;
11
- ```
12
-
13
- **Good**:
14
-
15
- ```ts
16
- function logAnything(x: any): void;
17
- ```
18
-
19
- ---
20
-
21
- **Bad**:
22
-
23
- ```ts
24
- function useLogger<T extends Logger>(logger: T): void;
25
- ```
26
-
27
- **Good**:
28
-
29
- ```ts
30
- function useLogger(logger: Logger): void;
31
- ```
32
-
33
- ---
34
-
35
- **Bad**:
36
-
37
- ```ts
38
- function clear<T>(array: T[]): void;
39
- ```
40
-
41
- **Good**:
42
-
43
- ```ts
44
- function clear(array: any[]): void;
45
- ```
46
-
47
- ---
48
-
49
- `getMeAT<T>(): T`:
50
- If a type parameter does not appear in the types of any parameters, you don't really have a generic function, you just have a disguised type assertion.
51
- Prefer to use a real type assertion, e.g. `getMeAT() as number`.
52
- Example where a type parameter is acceptable: `function id<T>(value: T): T;`.
53
- Example where it is not acceptable: `function parseJson<T>(json: string): T;`.
54
- Exception: `new Map<string, number>()` is OK.
55
-
56
- **Bad**:
57
-
58
- ```ts
59
- function parse<T>(): T;
60
- const x = parse<number>();
61
- ```
62
-
63
- **Good**:
64
-
65
-
66
- ```ts
67
- function parse(): {};
68
- const x = parse() as number;
69
- ```
@@ -1,14 +0,0 @@
1
- # no-useless-files
2
-
3
- Don't include empty files.
4
-
5
- **Bad**:
6
-
7
- ```ts
8
- ```
9
-
10
- **Good**:
11
-
12
- ```ts
13
- export function something(): void;
14
- ```
@@ -1,15 +0,0 @@
1
- # prefer-declare-function
2
-
3
- Prefer to declare a function using the `function` keyword instead of a variable of function type.
4
-
5
- **Bad**:
6
-
7
- ```ts
8
- export const f: () => number;
9
- ```
10
-
11
- **Good**:
12
-
13
- ```ts
14
- export function f(): number;
15
- ```
@@ -1,15 +0,0 @@
1
- # redundant-undefined
2
-
3
- Avoid explicitly specifying `undefined` as a type for a parameter which is already optional.
4
-
5
- **Bad**:
6
-
7
- ```ts
8
- function f(s?: string | undefined): void {}
9
- ```
10
-
11
- **Good**:
12
-
13
- ```ts
14
- function f(s?: string): void {}
15
- ```
package/docs/trim-file.md DELETED
@@ -1,17 +0,0 @@
1
- # trim-file
2
-
3
- Don't include blank lines at the beginning or end of a file.
4
-
5
- **Bad**:
6
-
7
- ```ts
8
-
9
- export function f(): number;
10
-
11
- ```
12
-
13
- **Good**:
14
-
15
- ```ts
16
- export function f(): number;
17
- ```
@@ -1,74 +0,0 @@
1
- import { renderExpected, validate } from "@definitelytyped/header-parser";
2
- import { createRule, isMainFile } from "../util";
3
-
4
- type MessageId =
5
- | "definitionsBy"
6
- | "minimumTypeScriptVersion"
7
- | "parseError"
8
- | "typeDefinitionsFor"
9
- | "typescriptVersion";
10
-
11
- const rule = createRule({
12
- name: "dt-header",
13
- defaultOptions: [],
14
- meta: {
15
- type: "problem",
16
- docs: {
17
- description: "Ensure consistency of DefinitelyTyped headers.",
18
- recommended: "error",
19
- },
20
- messages: {
21
- definitionsBy: "Author name should be your name, not the default.",
22
- minimumTypeScriptVersion: "TypeScript version should be specified under header in `index.d.ts`.",
23
- parseError: "Error parsing header. Expected: {{expected}}",
24
- typeDefinitionsFor: "Header should only be in `index.d.ts` of the root.",
25
- typescriptVersion: "Minimum TypeScript version should be specified under header in `index.d.ts`.",
26
- },
27
- schema: [],
28
- },
29
- create(context) {
30
- const sourceCode = context.getSourceCode();
31
- const { lines, text } = sourceCode;
32
-
33
- const lookFor = (search: string, messageId: MessageId) => {
34
- for (let i = 0; i < lines.length; i += 1) {
35
- if (lines[i].startsWith(search)) {
36
- context.report({
37
- loc: {
38
- end: { line: i + 1, column: search.length },
39
- start: { line: i + 1, column: 0 },
40
- },
41
- messageId,
42
- });
43
- }
44
- }
45
- };
46
-
47
- if (!isMainFile(context.getFilename(), /*allowNested*/ true)) {
48
- lookFor("// Type definitions for", "typeDefinitionsFor");
49
- lookFor("// TypeScript Version", "typescriptVersion");
50
- lookFor("// Minimum TypeScript Version", "minimumTypeScriptVersion");
51
- return {};
52
- }
53
-
54
- lookFor("// Definitions by: My Self", "definitionsBy");
55
-
56
- const error = validate(text);
57
- if (error) {
58
- context.report({
59
- data: {
60
- expected: renderExpected(error.expected),
61
- },
62
- loc: {
63
- column: error.column,
64
- line: error.line,
65
- },
66
- messageId: "parseError",
67
- });
68
- }
69
-
70
- return {};
71
- },
72
- });
73
-
74
- export = rule;
@@ -1,83 +0,0 @@
1
- import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/utils";
2
- import { createRule } from "../util";
3
-
4
- interface ExportAssignmentWithIdentifier extends TSESTree.TSExportAssignment {
5
- expression: TSESTree.Identifier;
6
- }
7
-
8
- const rule = createRule({
9
- name: "export-just-namespace",
10
- defaultOptions: [],
11
- meta: {
12
- type: "problem",
13
- docs: {
14
- description:
15
- "Forbids `export = foo` where `foo` is a namespace and isn't merged with a function/class/type/interface.",
16
- recommended: "error",
17
- },
18
- messages: {
19
- useTheBody: "Instead of `export =`-ing a namespace, use the body of the namespace as the module body.",
20
- },
21
- schema: [],
22
- },
23
- create(context) {
24
- const ast = context.getSourceCode().ast;
25
-
26
- const exportEqualsNode = ast.body.find(isExportEqualsWithIdentifier);
27
- if (!exportEqualsNode) {
28
- return {};
29
- }
30
-
31
- if (isJustNamespace(ast.body, exportEqualsNode.expression.name)) {
32
- context.report({
33
- messageId: "useTheBody",
34
- node: exportEqualsNode,
35
- });
36
- }
37
-
38
- return {};
39
- },
40
- });
41
-
42
- /**
43
- * @returns Where there is a namespace but there are no functions/classes/etc. with the same name.
44
- */
45
- function isJustNamespace(statements: TSESTree.ProgramStatement[], exportEqualsName: string): boolean {
46
- let anyNamespace = false;
47
-
48
- for (const statement of statements) {
49
- switch (statement.type) {
50
- case AST_NODE_TYPES.TSModuleDeclaration:
51
- anyNamespace ||= nameMatches(statement.id);
52
- break;
53
- case AST_NODE_TYPES.VariableDeclaration:
54
- if (statement.declarations.some((d) => nameMatches(d.id))) {
55
- // OK. It's merged with a variable.
56
- return false;
57
- }
58
- break;
59
- case AST_NODE_TYPES.ClassDeclaration:
60
- case AST_NODE_TYPES.FunctionDeclaration:
61
- case AST_NODE_TYPES.TSDeclareFunction:
62
- case AST_NODE_TYPES.TSTypeAliasDeclaration:
63
- case AST_NODE_TYPES.TSInterfaceDeclaration:
64
- if (nameMatches(statement.id)) {
65
- // OK. It's merged with a function/class/type/interface.
66
- return false;
67
- }
68
- break;
69
- }
70
- }
71
-
72
- return anyNamespace;
73
-
74
- function nameMatches(nameNode: TSESTree.Node | undefined | null): boolean {
75
- return !!nameNode && nameNode.type === AST_NODE_TYPES.Identifier && nameNode.name === exportEqualsName;
76
- }
77
- }
78
-
79
- function isExportEqualsWithIdentifier(node: TSESTree.Node): node is ExportAssignmentWithIdentifier {
80
- return node.type === AST_NODE_TYPES.TSExportAssignment && node.expression.type === AST_NODE_TYPES.Identifier;
81
- }
82
-
83
- export = rule;
@@ -1,34 +0,0 @@
1
- import { createRule } from "../util";
2
- import { AST_NODE_TYPES } from "@typescript-eslint/utils";
3
-
4
- const rule = createRule({
5
- name: "no-any-union",
6
- defaultOptions: [],
7
- meta: {
8
- type: "problem",
9
- docs: {
10
- description: "Forbid a union to contain `any`",
11
- recommended: "error",
12
- },
13
- messages: {
14
- anyUnion: "Including `any` in a union will override all other members of the union.",
15
- },
16
- schema: [],
17
- },
18
- create(context) {
19
- return {
20
- // eslint-disable-next-line @typescript-eslint/naming-convention
21
- TSUnionType(node) {
22
- const hasAnyType = node.types.some((t) => t.type === AST_NODE_TYPES.TSAnyKeyword);
23
- if (hasAnyType) {
24
- context.report({
25
- messageId: "anyUnion",
26
- node,
27
- });
28
- }
29
- },
30
- };
31
- },
32
- });
33
-
34
- export = rule;
@@ -1,62 +0,0 @@
1
- import { TSESTree } from "@typescript-eslint/utils";
2
- import { createRule } from "../util";
3
-
4
- type MessageId = "referencePathPackage" | "referencePathTest";
5
-
6
- const rule = createRule({
7
- name: "no-bad-reference",
8
- defaultOptions: [],
9
- meta: {
10
- type: "problem",
11
- docs: {
12
- description: `Forbids <reference path="../etc"/> in any file, and forbid <reference path> in test files.`,
13
- recommended: "error",
14
- },
15
- messages: {
16
- referencePathPackage:
17
- "Don't use <reference path> to reference another package. Use an import or <reference types> instead.",
18
- referencePathTest:
19
- "Don't use <reference path> in test files. Use <reference types> or include the file in 'tsconfig.json'.",
20
- },
21
- schema: [],
22
- },
23
- create(context) {
24
- const { comments } = context.getSourceCode().ast;
25
- const isDeclarationFile = context.getFilename().endsWith(".d.ts");
26
-
27
- for (const comment of comments) {
28
- const referenceMatch = comment.value.match(/<reference\s+path\s*=\s*"(.+)"\s*\/>/)?.[1];
29
- if (!referenceMatch) {
30
- continue;
31
- }
32
-
33
- if (isDeclarationFile) {
34
- if (referenceMatch.startsWith("..")) {
35
- report(comment, "referencePathPackage");
36
- }
37
- } else {
38
- report(comment, "referencePathTest");
39
- }
40
- }
41
-
42
- return {};
43
-
44
- function report(comment: TSESTree.Comment, messageId: MessageId) {
45
- context.report({
46
- loc: {
47
- end: {
48
- column: comment.value.lastIndexOf(`"`),
49
- line: comment.loc.end.line,
50
- },
51
- start: {
52
- column: comment.value.indexOf(`"`) + 1,
53
- line: comment.loc.start.line,
54
- },
55
- },
56
- messageId,
57
- });
58
- }
59
- },
60
- });
61
-
62
- export = rule;
@@ -1,30 +0,0 @@
1
- import { createRule } from "../util";
2
-
3
- const rule = createRule({
4
- name: "no-const-enum",
5
- defaultOptions: [],
6
- meta: {
7
- type: "problem",
8
- docs: {
9
- description: "Forbid `const enum`",
10
- recommended: "error",
11
- },
12
- messages: {
13
- constEnum: "Use of `const enum` is forbidden.",
14
- },
15
- schema: [],
16
- },
17
- create(context) {
18
- return {
19
- // eslint-disable-next-line @typescript-eslint/naming-convention
20
- "TSEnumDeclaration[const]"(node) {
21
- context.report({
22
- messageId: "constEnum",
23
- node,
24
- });
25
- },
26
- };
27
- },
28
- });
29
-
30
- export = rule;
@@ -1,46 +0,0 @@
1
- import { createRule } from "../util";
2
-
3
- const rule = createRule({
4
- name: "no-dead-reference",
5
- defaultOptions: [],
6
- meta: {
7
- type: "problem",
8
- docs: {
9
- description: "Ensures that all `/// <reference>` comments go at the top of the file.",
10
- recommended: "error",
11
- },
12
- messages: {
13
- referenceAtTop: "`/// <reference>` directive must be at top of file to take effect.",
14
- },
15
- schema: [],
16
- },
17
- create(context) {
18
- const source = context.getSourceCode();
19
- if (source.ast.body.length) {
20
- // 'm' flag makes it multiline, so `^` matches the beginning of any line.
21
- // 'g' flag lets us set rgx.lastIndex
22
- const rgx = /^\s*(\/\/\/ <reference)/gm;
23
-
24
- // Start search at the first statement. (`/// <reference>` before that is OK.)
25
- rgx.lastIndex = source.ast.body[0].range?.[0] ?? 0;
26
-
27
- // eslint-disable-next-line no-constant-condition
28
- while (true) {
29
- const match = rgx.exec(source.text);
30
- if (match === null) {
31
- break;
32
- }
33
-
34
- const length = match[1].length;
35
- const start = match.index + match[0].length - length;
36
- context.report({
37
- messageId: "referenceAtTop",
38
- loc: source.getLocFromIndex(start),
39
- });
40
- }
41
- }
42
- return {};
43
- },
44
- });
45
-
46
- export = rule;
@@ -1,45 +0,0 @@
1
- import { getCommonDirectoryName, createRule } from "../util";
2
- import { ESLintUtils, AST_NODE_TYPES } from "@typescript-eslint/utils";
3
- const rule = createRule({
4
- name: "no-declare-current-package",
5
- defaultOptions: [],
6
- meta: {
7
- type: "problem",
8
- docs: {
9
- description: "Don't use an ambient module declaration of the current package; use a normal module.",
10
- recommended: "error",
11
- },
12
- messages: {
13
- noDeclareCurrentPackage:
14
- `Instead of declaring a module with \`declare module "{{ text }}"\`, ` +
15
- `write its contents in directly in {{ preferred }}.`,
16
- },
17
- schema: [],
18
- },
19
- create(context) {
20
- if (!context.getFilename().endsWith(".d.ts")) {
21
- return {};
22
- }
23
- const parserServices = ESLintUtils.getParserServices(context);
24
- const packageName = getCommonDirectoryName(parserServices.program.getRootFileNames());
25
- return {
26
- // eslint-disable-next-line @typescript-eslint/naming-convention
27
- TSModuleDeclaration(node) {
28
- if (
29
- node.id.type === AST_NODE_TYPES.Literal &&
30
- (node.id.value === packageName || node.id.value.startsWith(packageName + "/"))
31
- ) {
32
- const text = node.id.value;
33
- const preferred = text === packageName ? '"index.d.ts"' : `"${text}.d.ts" or "${text}/index.d.ts`;
34
- context.report({
35
- messageId: "noDeclareCurrentPackage",
36
- data: { text, preferred },
37
- node,
38
- });
39
- }
40
- },
41
- };
42
- },
43
- });
44
-
45
- export = rule;
@@ -1,68 +0,0 @@
1
- import { createRule } from "../util";
2
- import { ESLintUtils } from "@typescript-eslint/utils";
3
- import * as ts from "typescript";
4
-
5
- const rule = createRule({
6
- name: "no-import-default-of-export-equals",
7
- defaultOptions: [],
8
- meta: {
9
- type: "problem",
10
- docs: {
11
- description: "Forbid a default import to reference an `export =` module.",
12
- recommended: "error",
13
- },
14
- messages: {
15
- noImportDefaultOfExportEquals: `The module {{moduleName}} uses \`export = \`. Import with \`import {{importName}} = require({{moduleName}})\`.`,
16
- },
17
- schema: [],
18
- },
19
- create(context) {
20
- const parserServices = ESLintUtils.getParserServices(context);
21
- const checker = parserServices.program.getTypeChecker();
22
- if (context.getFilename().endsWith(".d.ts")) {
23
- return {
24
- // eslint-disable-next-line @typescript-eslint/naming-convention
25
- ImportDeclaration(node) {
26
- const defaultName = node.specifiers.find((spec) => spec.type === "ImportDefaultSpecifier")?.local;
27
- if (!defaultName) {
28
- return;
29
- }
30
- const importName = defaultName.name;
31
- const source = parserServices.esTreeNodeToTSNodeMap.get(node.source);
32
- const sym = checker.getSymbolAtLocation(source);
33
- if (
34
- sym?.declarations?.some((d) =>
35
- getStatements(d)?.some((s) => ts.isExportAssignment(s) && !!s.isExportEquals)
36
- )
37
- ) {
38
- context.report({
39
- messageId: "noImportDefaultOfExportEquals",
40
- data: { moduleName: node.source.value, importName },
41
- node: defaultName,
42
- });
43
- }
44
- },
45
- };
46
- } else {
47
- return {};
48
- }
49
- },
50
- });
51
-
52
- function getStatements(decl: ts.Declaration): readonly ts.Statement[] | undefined {
53
- return ts.isSourceFile(decl)
54
- ? decl.statements
55
- : ts.isModuleDeclaration(decl)
56
- ? getModuleDeclarationStatements(decl)
57
- : undefined;
58
- }
59
-
60
- function getModuleDeclarationStatements(node: ts.ModuleDeclaration): readonly ts.Statement[] | undefined {
61
- let { body } = node;
62
- while (body && body.kind === ts.SyntaxKind.ModuleDeclaration) {
63
- body = body.body;
64
- }
65
- return body && ts.isModuleBlock(body) ? body.statements : undefined;
66
- }
67
-
68
- export = rule;
@@ -1,42 +0,0 @@
1
- import { createRule, isMainFile } from "../util";
2
- import { ESLintUtils } from "@typescript-eslint/utils";
3
- const rule = createRule({
4
- name: "no-outside-dependencies",
5
- defaultOptions: [],
6
- meta: {
7
- type: "problem",
8
- docs: {
9
- description: "Don't import things in `DefinitelyTyped/node_modules`.",
10
- recommended: "error",
11
- },
12
- messages: {
13
- noOutsideDependencies: `File {{fileName}} comes from a \`node_modules\` but is not declared in this type's \`package.json\`. `,
14
- },
15
- schema: [],
16
- },
17
- create(context) {
18
- if (isMainFile(context.getFilename(), /*allowNested*/ true)) {
19
- const parserServices = ESLintUtils.getParserServices(context);
20
- const hasNodeReference = parserServices.program
21
- .getSourceFiles()
22
- .some((f) => f.typeReferenceDirectives.some((dir) => dir.fileName === "node"));
23
- for (const sourceFile of parserServices.program.getSourceFiles()) {
24
- const fileName = sourceFile.fileName;
25
- if (
26
- fileName.includes("/DefinitelyTyped/node_modules/") &&
27
- !parserServices.program.isSourceFileDefaultLibrary(sourceFile) &&
28
- !(hasNodeReference && fileName.includes("buffer"))
29
- ) {
30
- context.report({
31
- messageId: "noOutsideDependencies",
32
- data: { fileName },
33
- loc: { column: 0, line: 1 },
34
- });
35
- }
36
- }
37
- }
38
- return {};
39
- },
40
- });
41
-
42
- export = rule;