@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.
Files changed (121) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/configs/all.d.ts +2 -0
  4. package/dist/configs/all.js +152 -0
  5. package/dist/configs/all.js.map +1 -0
  6. package/dist/index.d.ts +4 -0
  7. package/dist/index.js +10 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/rules/dt-header.d.ts +2 -0
  10. package/dist/rules/dt-header.js +62 -0
  11. package/dist/rules/dt-header.js.map +1 -0
  12. package/dist/rules/export-just-namespace.d.ts +2 -0
  13. package/dist/rules/export-just-namespace.js +70 -0
  14. package/dist/rules/export-just-namespace.js.map +1 -0
  15. package/dist/rules/index.d.ts +38 -0
  16. package/dist/rules/index.js +61 -0
  17. package/dist/rules/index.js.map +1 -0
  18. package/dist/rules/no-any-union.d.ts +4 -0
  19. package/dist/rules/no-any-union.js +34 -0
  20. package/dist/rules/no-any-union.js.map +1 -0
  21. package/dist/rules/no-bad-reference.d.ts +2 -0
  22. package/dist/rules/no-bad-reference.js +55 -0
  23. package/dist/rules/no-bad-reference.js.map +1 -0
  24. package/dist/rules/no-const-enum.d.ts +4 -0
  25. package/dist/rules/no-const-enum.js +30 -0
  26. package/dist/rules/no-const-enum.js.map +1 -0
  27. package/dist/rules/no-dead-reference.d.ts +2 -0
  28. package/dist/rules/no-dead-reference.js +44 -0
  29. package/dist/rules/no-dead-reference.js.map +1 -0
  30. package/dist/rules/no-declare-current-package.d.ts +4 -0
  31. package/dist/rules/no-declare-current-package.js +43 -0
  32. package/dist/rules/no-declare-current-package.js.map +1 -0
  33. package/dist/rules/no-import-default-of-export-equals.d.ts +4 -0
  34. package/dist/rules/no-import-default-of-export-equals.js +87 -0
  35. package/dist/rules/no-import-default-of-export-equals.js.map +1 -0
  36. package/dist/rules/no-outside-dependencies.d.ts +2 -0
  37. package/dist/rules/no-outside-dependencies.js +41 -0
  38. package/dist/rules/no-outside-dependencies.js.map +1 -0
  39. package/dist/rules/no-self-import.d.ts +4 -0
  40. package/dist/rules/no-self-import.js +38 -0
  41. package/dist/rules/no-self-import.js.map +1 -0
  42. package/dist/rules/no-single-element-tuple-type.d.ts +5 -0
  43. package/dist/rules/no-single-element-tuple-type.js +30 -0
  44. package/dist/rules/no-single-element-tuple-type.js.map +1 -0
  45. package/dist/rules/no-unnecessary-generics.d.ts +8 -0
  46. package/dist/rules/no-unnecessary-generics.js +135 -0
  47. package/dist/rules/no-unnecessary-generics.js.map +1 -0
  48. package/dist/rules/no-useless-files.d.ts +2 -0
  49. package/dist/rules/no-useless-files.js +53 -0
  50. package/dist/rules/no-useless-files.js.map +1 -0
  51. package/dist/rules/prefer-declare-function.d.ts +5 -0
  52. package/dist/rules/prefer-declare-function.js +35 -0
  53. package/dist/rules/prefer-declare-function.js.map +1 -0
  54. package/dist/rules/redundant-undefined.d.ts +4 -0
  55. package/dist/rules/redundant-undefined.js +53 -0
  56. package/dist/rules/redundant-undefined.js.map +1 -0
  57. package/dist/rules/trim-file.d.ts +2 -0
  58. package/dist/rules/trim-file.js +43 -0
  59. package/dist/rules/trim-file.js.map +1 -0
  60. package/dist/util.d.ts +4 -0
  61. package/dist/util.js +38 -0
  62. package/dist/util.js.map +1 -0
  63. package/docs/rules/dt-header.md +88 -0
  64. package/docs/rules/export-just-namespace.md +29 -0
  65. package/docs/rules/no-any-union.md +27 -0
  66. package/docs/rules/no-bad-reference.md +28 -0
  67. package/docs/rules/no-const-enum.md +16 -0
  68. package/docs/rules/no-dead-reference.md +17 -0
  69. package/docs/rules/no-declare-current-package.md +35 -0
  70. package/docs/rules/no-import-default-of-export-equals.md +22 -0
  71. package/docs/rules/no-outside-dependencies.md +23 -0
  72. package/docs/rules/no-self-import.md +27 -0
  73. package/docs/rules/no-single-element-tuple-type.md +15 -0
  74. package/docs/rules/no-unnecessary-generics.md +69 -0
  75. package/docs/rules/no-useless-files.md +14 -0
  76. package/docs/rules/prefer-declare-function.md +15 -0
  77. package/docs/rules/redundant-undefined.md +15 -0
  78. package/docs/rules/trim-file.md +17 -0
  79. package/package.json +45 -0
  80. package/src/configs/all.ts +151 -0
  81. package/src/index.ts +6 -0
  82. package/src/rules/dt-header.ts +74 -0
  83. package/src/rules/export-just-namespace.ts +83 -0
  84. package/src/rules/index.ts +35 -0
  85. package/src/rules/no-any-union.ts +34 -0
  86. package/src/rules/no-bad-reference.ts +62 -0
  87. package/src/rules/no-const-enum.ts +30 -0
  88. package/src/rules/no-dead-reference.ts +46 -0
  89. package/src/rules/no-declare-current-package.ts +45 -0
  90. package/src/rules/no-import-default-of-export-equals.ts +68 -0
  91. package/src/rules/no-outside-dependencies.ts +42 -0
  92. package/src/rules/no-self-import.ts +40 -0
  93. package/src/rules/no-single-element-tuple-type.ts +31 -0
  94. package/src/rules/no-unnecessary-generics.ts +126 -0
  95. package/src/rules/no-useless-files.ts +58 -0
  96. package/src/rules/prefer-declare-function.ts +37 -0
  97. package/src/rules/redundant-undefined.ts +62 -0
  98. package/src/rules/trim-file.ts +45 -0
  99. package/src/util.ts +41 -0
  100. package/test/dt-header.test.ts +189 -0
  101. package/test/export-just-namespace.test.ts +70 -0
  102. package/test/no-any-union.test.ts +22 -0
  103. package/test/no-bad-reference.test.ts +66 -0
  104. package/test/no-const-enum.test.ts +22 -0
  105. package/test/no-dead-reference.test.ts +66 -0
  106. package/test/no-declare-current-package.test.ts +61 -0
  107. package/test/no-import-default-of-export-equals.test.ts +49 -0
  108. package/test/no-self-import.test.ts +47 -0
  109. package/test/no-single-element-tuple-type.test.ts +28 -0
  110. package/test/no-unnecessary-generics.test.ts +152 -0
  111. package/test/no-useless-files.test.ts +42 -0
  112. package/test/prefer-declare-function.test.ts +66 -0
  113. package/test/redundant-undefined.test.ts +39 -0
  114. package/test/trim-file.test.ts +46 -0
  115. package/test/tsconfig.json +10 -0
  116. package/test/tsconfig.no-declare-current-package.json +11 -0
  117. package/test/tsconfig.no-declare-current-package2.json +11 -0
  118. package/test/tsconfig.no-import-default-of-export-equals.json +11 -0
  119. package/test/tsconfig.no-self-import.json +7 -0
  120. package/tsconfig.json +9 -0
  121. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ const util_1 = require("../util");
3
+ const utils_1 = require("@typescript-eslint/utils");
4
+ const rule = (0, util_1.createRule)({
5
+ name: "redundant-undefined",
6
+ defaultOptions: [],
7
+ meta: {
8
+ type: "problem",
9
+ docs: {
10
+ description: "Forbids optional parameters from including an explicit `undefined` in their type; requires it in optional properties.",
11
+ recommended: "error",
12
+ },
13
+ messages: {
14
+ redundantUndefined: `Parameter is optional, so no need to include \`undefined\` in the type.`,
15
+ },
16
+ schema: [],
17
+ },
18
+ create(context) {
19
+ return {
20
+ // eslint-disable-next-line @typescript-eslint/naming-convention
21
+ TSUnionType(node) {
22
+ const hasUndefinedType = node.types.some((t) => t.type === utils_1.AST_NODE_TYPES.TSUndefinedKeyword);
23
+ if (node.parent.type === utils_1.AST_NODE_TYPES.TSTypeAnnotation &&
24
+ isParameter(node.parent.parent) &&
25
+ node.parent.parent.optional &&
26
+ isFunctionLike(node.parent.parent.parent) &&
27
+ hasUndefinedType) {
28
+ context.report({
29
+ messageId: "redundantUndefined",
30
+ node,
31
+ });
32
+ }
33
+ },
34
+ };
35
+ },
36
+ });
37
+ function isFunctionLike(node) {
38
+ return (node.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression ||
39
+ node.type === utils_1.AST_NODE_TYPES.FunctionDeclaration ||
40
+ node.type === utils_1.AST_NODE_TYPES.FunctionExpression ||
41
+ node.type === utils_1.AST_NODE_TYPES.TSDeclareFunction ||
42
+ node.type === utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression);
43
+ }
44
+ /** Note: Does not include parameter properties because those can't be optional */
45
+ function isParameter(node) {
46
+ return (node.type === utils_1.AST_NODE_TYPES.ArrayPattern ||
47
+ node.type === utils_1.AST_NODE_TYPES.AssignmentPattern ||
48
+ node.type === utils_1.AST_NODE_TYPES.Identifier ||
49
+ node.type === utils_1.AST_NODE_TYPES.ObjectPattern ||
50
+ node.type === utils_1.AST_NODE_TYPES.RestElement);
51
+ }
52
+ module.exports = rule;
53
+ //# sourceMappingURL=redundant-undefined.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redundant-undefined.js","sourceRoot":"","sources":["../../src/rules/redundant-undefined.ts"],"names":[],"mappings":";AAAA,kCAAqC;AACrC,oDAA0D;AAG1D,MAAM,IAAI,GAAG,IAAA,iBAAU,EAAC;IACtB,IAAI,EAAE,qBAAqB;IAC3B,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EACT,uHAAuH;YACzH,WAAW,EAAE,OAAO;SACrB;QACD,QAAQ,EAAE;YACR,kBAAkB,EAAE,yEAAyE;SAC9F;QACD,MAAM,EAAE,EAAE;KACX;IACD,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,gEAAgE;YAChE,WAAW,CAAC,IAAI;gBACd,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,sBAAc,CAAC,kBAAkB,CAAC,CAAC;gBAC9F,IACE,IAAI,CAAC,MAAO,CAAC,IAAI,KAAK,sBAAc,CAAC,gBAAgB;oBACrD,WAAW,CAAC,IAAI,CAAC,MAAO,CAAC,MAAO,CAAC;oBACjC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ;oBAC3B,cAAc,CAAC,IAAI,CAAC,MAAO,CAAC,MAAO,CAAC,MAAO,CAAC;oBAC5C,gBAAgB,EAChB;oBACA,OAAO,CAAC,MAAM,CAAC;wBACb,SAAS,EAAE,oBAAoB;wBAC/B,IAAI;qBACL,CAAC,CAAC;iBACJ;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,SAAS,cAAc,CAAC,IAAmB;IACzC,OAAO,CACL,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,uBAAuB;QACpD,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,mBAAmB;QAChD,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,kBAAkB;QAC/C,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,iBAAiB;QAC9C,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,6BAA6B,CAC3D,CAAC;AACJ,CAAC;AACD,kFAAkF;AAClF,SAAS,WAAW,CAAC,IAAmB;IACtC,OAAO,CACL,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,YAAY;QACzC,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,iBAAiB;QAC9C,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,UAAU;QACvC,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,aAAa;QAC1C,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,WAAW,CACzC,CAAC;AACJ,CAAC;AAED,iBAAS,IAAI,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare const rule: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"leadingBlankLine" | "trailingBlankLine", never[], {}>;
2
+ export = rule;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ const util_1 = require("../util");
3
+ const rule = (0, util_1.createRule)({
4
+ name: "trim-file",
5
+ defaultOptions: [],
6
+ meta: {
7
+ type: "layout",
8
+ docs: {
9
+ description: "Forbids leading/trailing blank lines in a file. Allows file to end in '\n'",
10
+ recommended: "error",
11
+ },
12
+ messages: {
13
+ leadingBlankLine: "File should not begin with a blank line.",
14
+ trailingBlankLine: "File should not end with a blank line. (Ending in one newline OK, ending in two newlines not OK.)",
15
+ },
16
+ schema: [],
17
+ },
18
+ create(context) {
19
+ const { lines, text } = context.getSourceCode();
20
+ if (text.startsWith("\r") || text.startsWith("\n")) {
21
+ context.report({
22
+ messageId: "leadingBlankLine",
23
+ loc: {
24
+ start: { line: 1, column: 0 },
25
+ end: { line: 1, column: 0 },
26
+ },
27
+ });
28
+ }
29
+ if (text.endsWith("\n\n") || text.endsWith("\r\n\r\n")) {
30
+ const line = lines.length;
31
+ context.report({
32
+ messageId: "trailingBlankLine",
33
+ loc: {
34
+ start: { line, column: 0 },
35
+ end: { line, column: 0 },
36
+ },
37
+ });
38
+ }
39
+ return {};
40
+ },
41
+ });
42
+ module.exports = rule;
43
+ //# sourceMappingURL=trim-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trim-file.js","sourceRoot":"","sources":["../../src/rules/trim-file.ts"],"names":[],"mappings":";AAAA,kCAAqC;AAErC,MAAM,IAAI,GAAG,IAAA,iBAAU,EAAC;IACtB,IAAI,EAAE,WAAW;IACjB,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE;YACJ,WAAW,EAAE,4EAA4E;YACzF,WAAW,EAAE,OAAO;SACrB;QACD,QAAQ,EAAE;YACR,gBAAgB,EAAE,0CAA0C;YAC5D,iBAAiB,EACf,mGAAmG;SACtG;QACD,MAAM,EAAE,EAAE;KACX;IACD,MAAM,CAAC,OAAO;QACZ,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAChD,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YAClD,OAAO,CAAC,MAAM,CAAC;gBACb,SAAS,EAAE,kBAAkB;gBAC7B,GAAG,EAAE;oBACH,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;oBAC7B,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;iBAC5B;aACF,CAAC,CAAC;SACJ;QACD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;YACtD,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC;YAC1B,OAAO,CAAC,MAAM,CAAC;gBACb,SAAS,EAAE,mBAAmB;gBAC9B,GAAG,EAAE;oBACH,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE;oBAC1B,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE;iBACzB;aACF,CAAC,CAAC;SACJ;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAC,CAAC;AAEH,iBAAS,IAAI,CAAC"}
package/dist/util.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { ESLintUtils } from "@typescript-eslint/utils";
2
+ export declare const createRule: <TOptions extends readonly unknown[], TMessageIds extends string, TRuleListener extends import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener = import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>({ name, meta, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<TOptions, TMessageIds, TRuleListener>>) => import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<TMessageIds, TOptions, TRuleListener>;
3
+ export declare function getCommonDirectoryName(files: readonly string[]): string;
4
+ export declare function isMainFile(fileName: string, allowNested: boolean): boolean;
package/dist/util.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isMainFile = exports.getCommonDirectoryName = exports.createRule = void 0;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ const path_1 = require("path");
6
+ exports.createRule = utils_1.ESLintUtils.RuleCreator((name) => `https://github.com/microsoft/DefinitelyTyped-tools/tree/master/packages/eslint-plugin/docs/rules/${name}.md`);
7
+ function getCommonDirectoryName(files) {
8
+ let minLen = 999;
9
+ let minDir = "";
10
+ for (const file of files) {
11
+ const dir = (0, path_1.dirname)(file);
12
+ if (dir.length < minLen) {
13
+ minDir = dir;
14
+ minLen = dir.length;
15
+ }
16
+ }
17
+ return (0, path_1.basename)(minDir);
18
+ }
19
+ exports.getCommonDirectoryName = getCommonDirectoryName;
20
+ function isMainFile(fileName, allowNested) {
21
+ // Linter may be run with cwd of the package. We want `index.d.ts` but not `submodule/index.d.ts` to match.
22
+ if (fileName === "index.d.ts") {
23
+ return true;
24
+ }
25
+ if ((0, path_1.basename)(fileName) !== "index.d.ts") {
26
+ return false;
27
+ }
28
+ let parent = (0, path_1.dirname)(fileName);
29
+ // May be a directory for an older version, e.g. `v0`.
30
+ // Note a types redirect `foo/ts3.1` should not have its own header.
31
+ if (allowNested && /^v(0\.)?\d+$/.test((0, path_1.basename)(parent))) {
32
+ parent = (0, path_1.dirname)(parent);
33
+ }
34
+ // Allow "types/foo/index.d.ts", not "types/foo/utils/index.d.ts"
35
+ return (0, path_1.basename)((0, path_1.dirname)(parent)) === "types";
36
+ }
37
+ exports.isMainFile = isMainFile;
38
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AAAA,oDAAuD;AACvD,+BAAyC;AAE5B,QAAA,UAAU,GAAG,mBAAW,CAAC,WAAW,CAC/C,CAAC,IAAI,EAAE,EAAE,CACP,oGAAoG,IAAI,KAAK,CAChH,CAAC;AAEF,SAAgB,sBAAsB,CAAC,KAAwB;IAC7D,IAAI,MAAM,GAAG,GAAG,CAAC;IACjB,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,MAAM,GAAG,GAAG,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE;YACvB,MAAM,GAAG,GAAG,CAAC;YACb,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;SACrB;KACF;IACD,OAAO,IAAA,eAAQ,EAAC,MAAM,CAAC,CAAC;AAC1B,CAAC;AAXD,wDAWC;AAED,SAAgB,UAAU,CAAC,QAAgB,EAAE,WAAoB;IAC/D,2GAA2G;IAC3G,IAAI,QAAQ,KAAK,YAAY,EAAE;QAC7B,OAAO,IAAI,CAAC;KACb;IAED,IAAI,IAAA,eAAQ,EAAC,QAAQ,CAAC,KAAK,YAAY,EAAE;QACvC,OAAO,KAAK,CAAC;KACd;IAED,IAAI,MAAM,GAAG,IAAA,cAAO,EAAC,QAAQ,CAAC,CAAC;IAC/B,sDAAsD;IACtD,oEAAoE;IACpE,IAAI,WAAW,IAAI,cAAc,CAAC,IAAI,CAAC,IAAA,eAAQ,EAAC,MAAM,CAAC,CAAC,EAAE;QACxD,MAAM,GAAG,IAAA,cAAO,EAAC,MAAM,CAAC,CAAC;KAC1B;IAED,iEAAiE;IACjE,OAAO,IAAA,eAAQ,EAAC,IAAA,cAAO,EAAC,MAAM,CAAC,CAAC,KAAK,OAAO,CAAC;AAC/C,CAAC;AAnBD,gCAmBC"}
@@ -0,0 +1,88 @@
1
+ # dt-header
2
+
3
+ (This rule is specific to DefinitelyTyped.)
4
+
5
+ Checks the format of DefinitelyTyped header comments.
6
+
7
+ ---
8
+
9
+ **Bad**:
10
+
11
+ ```ts
12
+ // Type definitions for foo v1.2.3
13
+ ```
14
+
15
+ * Don't include `v`
16
+ * Don't include a patch version
17
+
18
+ **Good**:
19
+
20
+ ```ts
21
+ // Type definitions for foo 1.2
22
+ ```
23
+
24
+ ---
25
+
26
+ **Bad**:
27
+
28
+ ```ts
29
+ // Definitions by: My Name <http://geocities.com/myname>
30
+ ```
31
+
32
+ **Good**:
33
+
34
+ ```ts
35
+ // Definitions by: My Name <https://github.com/myname>
36
+ ```
37
+
38
+ * Prefer a GitHub username, not a personal web site.
39
+
40
+ ---
41
+
42
+ **Bad**:
43
+
44
+ `foo/index.d.ts`:
45
+
46
+ ```ts
47
+ // Type definitions for abs 1.2
48
+ // Project: https://github.com/foo/foo
49
+ // Definitions by: My Name <https://github.com/myname>
50
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
51
+ export { f } from "./subModule";
52
+ ```
53
+
54
+ `foo/subModule.d.ts`:
55
+
56
+ ```ts
57
+ // Type definitions for abs 1.2
58
+ // Project: https://github.com/foo/foo
59
+ // Definitions by: My Name <https://github.com/myname>
60
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
61
+ export function f(): number;
62
+ ```
63
+
64
+ `foo/ts3.1/index.d.ts`:
65
+ ```ts
66
+ // Type definitions for abs 1.2
67
+ // Project: https://github.com/foo/foo
68
+ // Definitions by: My Name <https://github.com/myname>
69
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
70
+ export function f(): number;
71
+ ```
72
+
73
+
74
+ **Good**:
75
+
76
+ `foo/index.d.ts`: Same
77
+
78
+ `foo/subModule.d.ts`:
79
+ ```ts
80
+ export function f(): number;
81
+ ```
82
+
83
+ `foo/ts3.1/index.d.ts`:
84
+ ```ts
85
+ export function f(): number;
86
+ ```
87
+
88
+ Don't repeat the header -- only do it in the index of the root.
@@ -0,0 +1,29 @@
1
+ # export-just-namespace
2
+
3
+ Declaring a namespace is unnecessary if that is the module's only content; just use ES6 export syntax instead.
4
+
5
+ **Bad**:
6
+
7
+ ```ts
8
+ namespace MyLib {
9
+ export function f(): number;
10
+ }
11
+ export = MyLib;
12
+ ```
13
+
14
+ **Good**:
15
+
16
+ ```ts
17
+ export function f(): number;
18
+ ```
19
+
20
+ **Also good**:
21
+
22
+ ```ts
23
+ namespace MyLib {
24
+ export function f(): number;
25
+ }
26
+ function MyLib(): number;
27
+ export = MyLib;
28
+ ```
29
+
@@ -0,0 +1,27 @@
1
+ # no-any-union
2
+
3
+ Forbids to include `any` in a union. When `any` is used in a union type, the resulting type is still `any`.
4
+
5
+ **Bad**:
6
+
7
+ ```ts
8
+ function f(x: string | any): void;
9
+ ```
10
+
11
+ **Good**:
12
+
13
+ ```ts
14
+ function f(x: string): void;
15
+ ```
16
+
17
+ Or:
18
+ ```ts
19
+ function f(x: any): void;
20
+ ```
21
+
22
+ Or:
23
+ ```ts
24
+ function f(x: string | object): void;
25
+ ```
26
+
27
+ While the `string` portion of this type annotation may _look_ useful, it in fact offers no additional typechecking over simply using `any`.
@@ -0,0 +1,28 @@
1
+ # no-bad-reference
2
+
3
+ (This rule is specific to DefinitelyTyped.)
4
+ Avoid using `<reference path>`.
5
+
6
+ **Bad**:
7
+
8
+ ```ts
9
+ /// <reference path="../node_modules/@types/foo/index.d.ts" />
10
+ import * as foo from "foo";
11
+ ```
12
+
13
+ **Good**:
14
+
15
+ If "foo" is written in external module style (see `no-single-declare-module`), the import alone should work thanks to [module resolution](http://www.typescriptlang.org/docs/handbook/module-resolution.html):
16
+
17
+ ```ts
18
+ // TypeScript will look for a definition for "foo" using module resolution
19
+ import * as foo from "foo";
20
+ ```
21
+
22
+ If not, use `<reference types>` instead:
23
+
24
+ ```ts
25
+ /// <reference types="foo" />
26
+ ```
27
+
28
+ The only time `<reference path>` should be necessary if for global (not module) libraries that are separated into multiple files; the index file must include references to the others to bring them into the compilation.
@@ -0,0 +1,16 @@
1
+ # no-const-enum
2
+
3
+ Avoid using `const enum`s. These can't be used by JavaScript users or by TypeScript users with [`--isolatedModules`](https://www.typescriptlang.org/docs/handbook/compiler-options.html) enabled.
4
+
5
+ **Bad**:
6
+
7
+ ```ts
8
+ const enum Bit { Off, On }
9
+ export function f(b: Bit): void;
10
+ ```
11
+
12
+ **Good**:
13
+
14
+ ```ts
15
+ export function f(b: 0 | 1): void;
16
+ ```
@@ -0,0 +1,17 @@
1
+ # no-dead-reference
2
+
3
+ A `<reference>` comment should go at the top of a file -- otherwise it is just a normal comment.
4
+
5
+ **Bad**:
6
+
7
+ ```ts
8
+ console.log("Hello world!");
9
+ /// <reference types="jquery" />
10
+ ```
11
+
12
+ **Good**:
13
+
14
+ ```ts
15
+ /// <reference types="jquery" />
16
+ console.log("Hello world!");
17
+ ```
@@ -0,0 +1,35 @@
1
+ # no-declare-current-package
2
+
3
+ Avoid using `declare module`, and prefer to declare module contents in a file.
4
+
5
+ **Bad**:
6
+
7
+ ```ts
8
+ // foo/index.d.ts
9
+ declare module "foo" {
10
+ export const x = 0;
11
+ }
12
+ ```
13
+
14
+ **Good**:
15
+
16
+ ```ts
17
+ // foo/index.d.ts
18
+ export const x = 0;
19
+ ```
20
+
21
+ **Bad**:
22
+
23
+ ```ts
24
+ // foo/index.d.ts
25
+ declare module "foo/bar" {
26
+ export const x = 0;
27
+ }
28
+ ```
29
+
30
+ **Good**:
31
+
32
+ ```ts
33
+ // foo/bar.d.ts
34
+ export const x = 0;
35
+ ```
@@ -0,0 +1,22 @@
1
+ # no-import-default-of-export-equals
2
+
3
+ Don't use a default import of a package that uses `export =`.
4
+ Users who do not have `--allowSyntheticDefaultExports` or `--esModuleInterop` will get different behavior.
5
+ This rule only applies to definition files -- for test files you can use a default import if you prefer.
6
+
7
+ **Bad**:
8
+
9
+ ```ts
10
+ // foo/index.d.ts
11
+ declare interface I {}
12
+ export = I;
13
+
14
+ // bar/index.d.ts
15
+ import I from "foo";
16
+ ```
17
+
18
+ **Good**:
19
+
20
+ ```ts
21
+ import I = require("foo");
22
+ ```
@@ -0,0 +1,23 @@
1
+ # no-outside-dependencies
2
+
3
+ Don't import from `DefinitelyTyped/node_modules`.
4
+
5
+ **Bad**:
6
+
7
+ ```ts
8
+ import * as x from "x";
9
+ // where 'x' is defined only in `DefinitelyTyped/node_modules`
10
+ ```
11
+
12
+ **Good**:
13
+
14
+ Add a `package.json`:
15
+
16
+ ```ts
17
+ {
18
+ "private": true,
19
+ "dependencies": {
20
+ "x": "^1.2.3"
21
+ }
22
+ }
23
+ ```
@@ -0,0 +1,27 @@
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
+ ```
@@ -0,0 +1,15 @@
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
+ ```
@@ -0,0 +1,69 @@
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
+ ```
@@ -0,0 +1,14 @@
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
+ ```
@@ -0,0 +1,15 @@
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
+ ```
@@ -0,0 +1,15 @@
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
+ ```
@@ -0,0 +1,17 @@
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
+ ```
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@definitelytyped/eslint-plugin",
3
+ "version": "0.0.166-next.4",
4
+ "description": "ESLint rules for DefinitelyTyped",
5
+ "main": "./dist/index.js",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "contributors": [
10
+ "Nathan Shively-Sanders <nathansa@microsoft.com> (https://github.com/sandersn)",
11
+ "Andy Hanson <andy-ms@microsoft.com> (https://github.com/andy-ms)",
12
+ "Dan Vanderkam <danvdk@gmail.com> (https://github.com/danvk)",
13
+ "Remco Haszing <remcohaszing@gmail.com> (https://github.com/remcohaszing)"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/microsoft/DefinitelyTyped-tools.git",
18
+ "directory": "packages/eslint-plugin"
19
+ },
20
+ "scripts": {
21
+ "build": "tsc -b .",
22
+ "test": "../../node_modules/.bin/jest --config ../../jest.config.js packages/dtslint"
23
+ },
24
+ "dependencies": {
25
+ "@definitelytyped/header-parser": "^0.0.166-next.1",
26
+ "@typescript-eslint/types": "^5.56.0",
27
+ "@typescript-eslint/utils": "^5.55.0"
28
+ },
29
+ "peerDependencies": {
30
+ "@typescript-eslint/eslint-plugin": "^5.0.0",
31
+ "@typescript-eslint/parser": "^5.0.0",
32
+ "eslint": "^8.0.0",
33
+ "eslint-plugin-jsdoc": "^44.0.0",
34
+ "typescript": ">= 3.0.0-dev || >= 3.1.0-dev || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.7.0-dev || >= 3.8.0-dev || >= 3.9.0-dev || >= 4.0.0-dev || >=5.0.0-dev"
35
+ },
36
+ "devDependencies": {
37
+ "@types/eslint": "^8.4.2",
38
+ "typescript": "^5.0.2"
39
+ },
40
+ "engines": {
41
+ "node": ">=10.0.0"
42
+ },
43
+ "license": "MIT",
44
+ "gitHead": "bf315c7ade6b5d9c57e52b7948bd53af5cbc0c08"
45
+ }