@definitelytyped/eslint-plugin 0.0.192 → 0.0.193

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 (42) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/index.d.ts +10 -3
  3. package/dist/index.js +12 -6
  4. package/dist/index.js.map +1 -1
  5. package/dist/rules/no-import-of-dev-dependencies.js +17 -6
  6. package/dist/rules/no-import-of-dev-dependencies.js.map +1 -1
  7. package/dist/rules/no-relative-import-in-test.js +31 -17
  8. package/dist/rules/no-relative-import-in-test.js.map +1 -1
  9. package/dist/rules/no-self-import.js +23 -12
  10. package/dist/rules/no-self-import.js.map +1 -1
  11. package/dist/util.d.ts +1 -0
  12. package/dist/util.js +13 -1
  13. package/dist/util.js.map +1 -1
  14. package/package.json +1 -1
  15. package/src/index.ts +16 -4
  16. package/src/rules/no-import-of-dev-dependencies.ts +20 -7
  17. package/src/rules/no-relative-import-in-test.ts +37 -20
  18. package/src/rules/no-self-import.ts +26 -12
  19. package/src/util.ts +18 -0
  20. package/test/__file_snapshots__/types/no-import-of-dev-dependencies/bad.d.ts.lint +16 -1
  21. package/test/__file_snapshots__/types/no-import-of-dev-dependencies/index.d.ts.lint +10 -1
  22. package/test/__file_snapshots__/types/no-import-of-dev-dependencies/no-import-of-dev-dependencies-tests.ts.lint +16 -1
  23. package/test/__file_snapshots__/types/no-relative-import-in-test/index.d.ts.lint +2 -7
  24. package/test/__file_snapshots__/types/no-relative-import-in-test/no-relative-import-in-test-tests3.ts.lint +10 -0
  25. package/test/__file_snapshots__/types/no-relative-references/index.d.ts.lint +7 -1
  26. package/test/__file_snapshots__/types/no-relative-references/v1/index.d.ts.lint +7 -1
  27. package/test/__file_snapshots__/types/no-self-import/bad.d.ts.lint +38 -8
  28. package/test/__file_snapshots__/types/no-self-import/index.d.ts.lint +8 -0
  29. package/test/__file_snapshots__/types/no-self-import/no-self-import-tests.ts.lint +16 -1
  30. package/test/__file_snapshots__/types/scoped__no-relative-references/index.d.ts.lint +7 -1
  31. package/test/__file_snapshots__/types/scoped__no-relative-references/v1/index.d.ts.lint +7 -1
  32. package/test/eslint.test.ts +1 -1
  33. package/test/fixtures/types/no-import-of-dev-dependencies/bad.d.ts +3 -0
  34. package/test/fixtures/types/no-import-of-dev-dependencies/index.d.ts +3 -0
  35. package/test/fixtures/types/no-import-of-dev-dependencies/no-import-of-dev-dependencies-tests.ts +6 -0
  36. package/test/fixtures/types/no-relative-import-in-test/index.d.ts +1 -0
  37. package/test/fixtures/types/no-relative-import-in-test/no-relative-import-in-test-tests3.ts +1 -0
  38. package/test/fixtures/types/no-relative-import-in-test/tsconfig.json +1 -0
  39. package/test/fixtures/types/no-self-import/bad.d.ts +9 -0
  40. package/test/fixtures/types/no-self-import/index.d.ts +8 -0
  41. package/test/fixtures/types/no-self-import/no-self-import-tests.ts +6 -0
  42. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @definitelytyped/eslint-plugin
2
2
 
3
+ ## 0.0.193
4
+
5
+ ### Patch Changes
6
+
7
+ - 0a3c2d5b: Fully type eslint plugin export and add metadata
8
+ - 7af66e7d: Handle `import = require()` in lint rules
9
+
3
10
  ## 0.0.192
4
11
 
5
12
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,4 +1,11 @@
1
- export { rules } from "./rules/index";
2
- export declare const configs: {
3
- all: import("eslint").Linter.BaseConfig<import("eslint").Linter.RulesRecord, import("eslint").Linter.RulesRecord>;
1
+ declare const plugin: {
2
+ meta: {
3
+ name: any;
4
+ version: any;
5
+ };
6
+ configs: {
7
+ all: import("eslint").Linter.BaseConfig<import("eslint").Linter.RulesRecord, import("eslint").Linter.RulesRecord>;
8
+ };
9
+ rules: any;
4
10
  };
11
+ export = plugin;
package/dist/index.js CHANGED
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configs = exports.rules = void 0;
4
2
  const all_1 = require("./configs/all");
5
- var index_1 = require("./rules/index");
6
- Object.defineProperty(exports, "rules", { enumerable: true, get: function () { return index_1.rules; } });
7
- exports.configs = {
8
- all: all_1.all,
3
+ const index_1 = require("./rules/index");
4
+ const packageJson = require("../package.json");
5
+ const plugin = {
6
+ meta: {
7
+ name: packageJson.name,
8
+ version: packageJson.version,
9
+ },
10
+ configs: {
11
+ all: all_1.all,
12
+ },
13
+ rules: index_1.rules,
9
14
  };
15
+ module.exports = plugin;
10
16
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,uCAAsC;AAA7B,8FAAA,KAAK,OAAA;AAED,QAAA,OAAO,GAAG;IACrB,GAAG,EAAH,SAAG;CACJ,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,uCAAoC;AACpC,yCAAsC;AAEtC,MAAM,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE/C,MAAM,MAAM,GAAG;IACb,IAAI,EAAE;QACJ,IAAI,EAAE,WAAW,CAAC,IAAI;QACtB,OAAO,EAAE,WAAW,CAAC,OAAO;KAC7B;IACD,OAAO,EAAE;QACP,GAAG,EAAH,SAAG;KACJ;IACD,KAAK,EAAE,aAAY;CACI,CAAC;AAE1B,iBAAS,MAAM,CAAC"}
@@ -40,15 +40,26 @@ const rule = (0, util_1.createRule)({
40
40
  report(comment, "noReferenceOfDevDependencies");
41
41
  }
42
42
  });
43
+ function lint(node) {
44
+ const source = (0, util_1.getImportSource)(node);
45
+ if (!source) {
46
+ return;
47
+ }
48
+ if (devDeps.includes(source.value)) {
49
+ context.report({
50
+ messageId: "noImportOfDevDependencies",
51
+ node,
52
+ });
53
+ }
54
+ }
43
55
  return {
44
56
  // eslint-disable-next-line @typescript-eslint/naming-convention
45
57
  ImportDeclaration(node) {
46
- if (devDeps.includes(node.source.value)) {
47
- context.report({
48
- messageId: "noImportOfDevDependencies",
49
- node,
50
- });
51
- }
58
+ lint(node);
59
+ },
60
+ // eslint-disable-next-line @typescript-eslint/naming-convention
61
+ TSImportEqualsDeclaration(node) {
62
+ lint(node);
52
63
  },
53
64
  };
54
65
  function report(comment, messageId) {
@@ -1 +1 @@
1
- {"version":3,"file":"no-import-of-dev-dependencies.js","sourceRoot":"","sources":["../../src/rules/no-import-of-dev-dependencies.ts"],"names":[],"mappings":";AACA,kCAAyE;AACzE,kDAA2G;AAG3G,MAAM,IAAI,GAAG,IAAA,iBAAU,EAAC;IACtB,IAAI,EAAE,+BAA+B;IACrC,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,sEAAsE;SACpF;QACD,QAAQ,EAAE;YACR,yBAAyB,EAAE,yDAAyD;YACpF,4BAA4B,EAAE,yEAAyE;SACxG;QACD,MAAM,EAAE,EAAE;KACX;IACD,MAAM,CAAC,OAAO;QACZ,IAAI,CAAC,IAAA,yBAAiB,EAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YACxC,OAAO,EAAE,CAAC;SACX;QAED,MAAM,IAAI,GAAG,IAAA,uBAAgB,EAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,EAAE;YACT,OAAO,EAAE,CAAC;SACX;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACrC,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE;YAChC,OAAO,EAAE,CAAC;SACX;QAED,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC;aACrD,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YACX,IAAI,IAAA,0BAAkB,EAAC,GAAG,CAAC,EAAE;gBAC3B,OAAO,IAAA,kCAA0B,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AC;AAEH,iBAAS,IAAI,CAAC"}
1
+ {"version":3,"file":"no-import-of-dev-dependencies.js","sourceRoot":"","sources":["../../src/rules/no-import-of-dev-dependencies.ts"],"names":[],"mappings":";AACA,kCAA0F;AAC1F,kDAA2G;AAG3G,MAAM,IAAI,GAAG,IAAA,iBAAU,EAAC;IACtB,IAAI,EAAE,+BAA+B;IACrC,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,sEAAsE;SACpF;QACD,QAAQ,EAAE;YACR,yBAAyB,EAAE,yDAAyD;YACpF,4BAA4B,EAAE,yEAAyE;SACxG;QACD,MAAM,EAAE,EAAE;KACX;IACD,MAAM,CAAC,OAAO;QACZ,IAAI,CAAC,IAAA,yBAAiB,EAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YACxC,OAAO,EAAE,CAAC;SACX;QAED,MAAM,IAAI,GAAG,IAAA,uBAAgB,EAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,EAAE;YACT,OAAO,EAAE,CAAC;SACX;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACrC,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE;YAChC,OAAO,EAAE,CAAC;SACX;QAED,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC;aACrD,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YACX,IAAI,IAAA,0BAAkB,EAAC,GAAG,CAAC,EAAE;gBAC3B,OAAO,IAAA,kCAA0B,EAAC,GAAG,CAAC,CAAC;aACxC;YACD,OAAO,GAAG,CAAC;QACb,CAAC,CAAC;aACD,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,WAAC,OAAA,GAAG,KAAK,IAAI,CAAC,QAAQ,IAAI,CAAA,MAAA,WAAW,CAAC,YAAY,0CAAG,GAAG,CAAC,MAAK,SAA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CAAC;QACL,CAAC;IACH,CAAC;CACF,CAAC,CAAC;AAEH,iBAAS,IAAI,CAAC"}
@@ -45,26 +45,40 @@ const rule = (0, util_1.createRule)({
45
45
  }
46
46
  const services = utils_1.ESLintUtils.getParserServices(context);
47
47
  const checker = services.program.getTypeChecker();
48
+ function lint(node) {
49
+ const source = (0, util_1.getImportSource)(node);
50
+ if (!source) {
51
+ return;
52
+ }
53
+ if (!source.value.startsWith(".")) {
54
+ return;
55
+ }
56
+ const moduleSymbol = checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(source));
57
+ if (!moduleSymbol) {
58
+ // TODO(jakebailey): generally speaking, this should be an error; you can't import a non-module.
59
+ return;
60
+ }
61
+ if (!moduleSymbol.declarations) {
62
+ return;
63
+ }
64
+ for (const declaration of moduleSymbol.declarations) {
65
+ if (ts.isSourceFile(declaration) && declaration.isDeclarationFile) {
66
+ context.report({
67
+ messageId: "useGlobalImport",
68
+ node: source,
69
+ });
70
+ return;
71
+ }
72
+ }
73
+ }
48
74
  return {
49
75
  // eslint-disable-next-line @typescript-eslint/naming-convention
50
76
  ImportDeclaration(node) {
51
- const { source } = node;
52
- if (!source.value.startsWith(".")) {
53
- return;
54
- }
55
- const moduleSymbol = checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(source));
56
- if (!(moduleSymbol === null || moduleSymbol === void 0 ? void 0 : moduleSymbol.declarations)) {
57
- return;
58
- }
59
- for (const declaration of moduleSymbol.declarations) {
60
- if (ts.isSourceFile(declaration) && declaration.isDeclarationFile) {
61
- context.report({
62
- messageId: "useGlobalImport",
63
- node: source,
64
- });
65
- return;
66
- }
67
- }
77
+ lint(node);
78
+ },
79
+ // eslint-disable-next-line @typescript-eslint/naming-convention
80
+ TSImportEqualsDeclaration(node) {
81
+ lint(node);
68
82
  },
69
83
  };
70
84
  },
@@ -1 +1 @@
1
- {"version":3,"file":"no-relative-import-in-test.js","sourceRoot":"","sources":["../../src/rules/no-relative-import-in-test.ts"],"names":[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EAAE,MAAM;yBACb,CAAC,CAAC;wBACH,OAAO;qBACR;iBACF;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,iBAAS,IAAI,CAAC"}
1
+ {"version":3,"file":"no-relative-import-in-test.js","sourceRoot":"","sources":["../../src/rules/no-relative-import-in-test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAiE;AACjE,+CAAiC;AACjC,kCAAsD;AACtD,kDAA2D;AAE3D,MAAM,IAAI,GAAG,IAAA,iBAAU,EAAC;IACtB,IAAI,EAAE,4BAA4B;IAClC,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,+DAA+D;SAC7E;QACD,QAAQ,EAAE;YACR,eAAe,EACb,wGAAwG;SAC3G;QACD,MAAM,EAAE,EAAE;KACX;IACD,MAAM,CAAC,OAAO;QACZ,IAAI,IAAA,yBAAiB,EAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YACvC,OAAO,EAAE,CAAC;SACX;QAED,MAAM,QAAQ,GAAG,mBAAW,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACxD,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;QAElD,SAAS,IAAI,CAAC,IAAqE;YACjF,MAAM,MAAM,GAAG,IAAA,sBAAe,EAAC,IAAI,CAAC,CAAC;YACrC,IAAI,CAAC,MAAM,EAAE;gBACX,OAAO;aACR;YAED,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;gBACjC,OAAO;aACR;YAED,MAAM,YAAY,GAAG,OAAO,CAAC,mBAAmB,CAAC,QAAQ,CAAC,qBAAqB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;YAC7F,IAAI,CAAC,YAAY,EAAE;gBACjB,gGAAgG;gBAChG,OAAO;aACR;YAED,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE;gBAC9B,OAAO;aACR;YAED,KAAK,MAAM,WAAW,IAAI,YAAY,CAAC,YAAY,EAAE;gBACnD,IAAI,EAAE,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC,iBAAiB,EAAE;oBACjE,OAAO,CAAC,MAAM,CAAC;wBACb,SAAS,EAAE,iBAAiB;wBAC5B,IAAI,EAAE,MAAM;qBACb,CAAC,CAAC;oBACH,OAAO;iBACR;aACF;QACH,CAAC;QAED,OAAO;YACL,gEAAgE;YAChE,iBAAiB,CAAC,IAAI;gBACpB,IAAI,CAAC,IAAI,CAAC,CAAC;YACb,CAAC;YACD,gEAAgE;YAChE,yBAAyB,CAAC,IAAI;gBAC5B,IAAI,CAAC,IAAI,CAAC,CAAC;YACb,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,iBAAS,IAAI,CAAC"}
@@ -19,21 +19,32 @@ const rule = (0, util_1.createRule)({
19
19
  if (!packageName) {
20
20
  return {};
21
21
  }
22
+ function lint(node) {
23
+ const source = (0, util_1.getImportSource)(node);
24
+ if (!source) {
25
+ return;
26
+ }
27
+ if (source.value === packageName || source.value.startsWith(packageName + "/")) {
28
+ context.report({
29
+ messageId: "useRelativeImport",
30
+ node,
31
+ });
32
+ }
33
+ else if (source.value.match(/^\.\/v\d+(?:\.\d+)?(?:\/.*)?$/)) {
34
+ context.report({
35
+ messageId: "useOnlyCurrentVersion",
36
+ node,
37
+ });
38
+ }
39
+ }
22
40
  return {
23
41
  // eslint-disable-next-line @typescript-eslint/naming-convention
24
42
  ImportDeclaration(node) {
25
- if (node.source.value === packageName || node.source.value.startsWith(packageName + "/")) {
26
- context.report({
27
- messageId: "useRelativeImport",
28
- node,
29
- });
30
- }
31
- else if (node.source.value.match(/^\.\/v\d+(?:\.\d+)?(?:\/.*)?$/)) {
32
- context.report({
33
- messageId: "useOnlyCurrentVersion",
34
- node,
35
- });
36
- }
43
+ lint(node);
44
+ },
45
+ // eslint-disable-next-line @typescript-eslint/naming-convention
46
+ TSImportEqualsDeclaration(node) {
47
+ lint(node);
37
48
  },
38
49
  };
39
50
  },
@@ -1 +1 @@
1
- {"version":3,"file":"no-self-import.js","sourceRoot":"","sources":["../../src/rules/no-self-import.ts"],"names":[],"mappings":";AAAA,kCAAwE;AACxE,MAAM,IAAI,GAAG,IAAA,iBAAU,EAAC;IACtB,IAAI,EAAE,gBAAgB;IACtB,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EACT,uHAAuH;SAC1H;QACD,QAAQ,EAAE;YACR,iBAAiB,EAAE,mFAAmF;YACtG,qBAAqB,EAAE,qDAAqD;SAC7E;QACD,MAAM,EAAE,EAAE;KACX;IACD,MAAM,CAAC,OAAO;QACZ,MAAM,WAAW,GAAG,IAAA,wCAAiC,EAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACxE,IAAI,CAAC,WAAW,EAAE;YAChB,OAAO,EAAE,CAAC;SACX;QAED,OAAO;YACL,gEAAgE;YAChE,iBAAiB,CAAC,IAAI;gBACpB,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,WAAW,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,GAAG,GAAG,CAAC,EAAE;oBACxF,OAAO,CAAC,MAAM,CAAC;wBACb,SAAS,EAAE,mBAAmB;wBAC9B,IAAI;qBACL,CAAC,CAAC;iBACJ;qBAAM,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,+BAA+B,CAAC,EAAE;oBACnE,OAAO,CAAC,MAAM,CAAC;wBACb,SAAS,EAAE,uBAAuB;wBAClC,IAAI;qBACL,CAAC,CAAC;iBACJ;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,iBAAS,IAAI,CAAC"}
1
+ {"version":3,"file":"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CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,iBAAS,IAAI,CAAC"}
package/dist/util.d.ts CHANGED
@@ -18,3 +18,4 @@ export interface PackageJSON {
18
18
  devDependencies?: Record<string, string | undefined>;
19
19
  }
20
20
  export declare function findTypesPackage(file: string): TypesPackageInfo | undefined;
21
+ export declare function getImportSource(node: TSESTree.ImportDeclaration | TSESTree.TSImportEqualsDeclaration): TSESTree.StringLiteral | undefined;
package/dist/util.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.findTypesPackage = exports.commentsMatching = exports.getTypesPackageForDeclarationFile = exports.createRule = void 0;
6
+ exports.getImportSource = exports.findTypesPackage = exports.commentsMatching = exports.getTypesPackageForDeclarationFile = exports.createRule = void 0;
7
7
  const utils_1 = require("@definitelytyped/utils");
8
8
  const utils_2 = require("@typescript-eslint/utils");
9
9
  const path_1 = __importDefault(require("path"));
@@ -66,4 +66,16 @@ function findTypesPackage(file) {
66
66
  });
67
67
  }
68
68
  exports.findTypesPackage = findTypesPackage;
69
+ function getImportSource(node) {
70
+ if (node.type === "ImportDeclaration") {
71
+ return node.source;
72
+ }
73
+ if (node.moduleReference.type === "TSExternalModuleReference" &&
74
+ node.moduleReference.expression.type === "Literal" &&
75
+ typeof node.moduleReference.expression.value === "string") {
76
+ return node.moduleReference.expression;
77
+ }
78
+ return undefined;
79
+ }
80
+ exports.getImportSource = getImportSource;
69
81
  //# sourceMappingURL=util.js.map
package/dist/util.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAuF;AACvF,oDAA2E;AAC3E,gDAAwB;AACxB,4CAAoB;AASP,QAAA,UAAU,GAEkB,mBAAW,CAAC,WAAW,CAC9D,CAAC,I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D,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE;YACnC,OAAO,SAAS,CAAC;SAClB;QAED,MAAM,mBAAmB,GAAG,YAAE,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;QACrE,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACpD,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE;YAChC,OAAO,SAAS,CAAC;SAClB;QACD,OAAO;YACL,GAAG,EAAE,CAAC;YACN,WAAW;YACX,QAAQ,EAAE,IAAA,kCAA0B,EAAC,WAAW,CAAC,IAAI,CAAC;SACvD,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAlBD,4CAkBC;AAED,SAAgB,eAAe,CAC7B,IAAqE;IAErE,IAAI,IAAI,CAAC,IAAI,KAAK,mBAAmB,EAAE;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC;KACpB;IAED,IACE,IAAI,CAAC,eAAe,CAAC,IAAI,KAAK,2BAA2B;QACzD,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,KAAK,SAAS;QAClD,OAAO,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,KAAK,KAAK,QAAQ,EACzD;QACA,OAAO,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC;KACxC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAhBD,0CAgBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@definitelytyped/eslint-plugin",
3
- "version": "0.0.192",
3
+ "version": "0.0.193",
4
4
  "description": "ESLint rules for DefinitelyTyped",
5
5
  "main": "./dist/index.js",
6
6
  "publishConfig": {
package/src/index.ts CHANGED
@@ -1,6 +1,18 @@
1
+ import { ESLint } from "eslint";
1
2
  import { all } from "./configs/all";
2
- export { rules } from "./rules/index";
3
+ import { rules } from "./rules/index";
3
4
 
4
- export const configs = {
5
- all,
6
- };
5
+ const packageJson = require("../package.json");
6
+
7
+ const plugin = {
8
+ meta: {
9
+ name: packageJson.name,
10
+ version: packageJson.version,
11
+ },
12
+ configs: {
13
+ all,
14
+ },
15
+ rules: rules as any,
16
+ } satisfies ESLint.Plugin;
17
+
18
+ export = plugin;
@@ -1,5 +1,5 @@
1
1
  import { TSESTree } from "@typescript-eslint/utils";
2
- import { createRule, commentsMatching, findTypesPackage } from "../util";
2
+ import { createRule, commentsMatching, findTypesPackage, getImportSource } from "../util";
3
3
  import { isDeclarationPath, isTypesPackageName, typesPackageNameToRealName } from "@definitelytyped/utils";
4
4
 
5
5
  type MessageId = "noImportOfDevDependencies" | "noReferenceOfDevDependencies";
@@ -47,15 +47,28 @@ const rule = createRule({
47
47
  }
48
48
  });
49
49
 
50
+ function lint(node: TSESTree.ImportDeclaration | TSESTree.TSImportEqualsDeclaration) {
51
+ const source = getImportSource(node);
52
+ if (!source) {
53
+ return;
54
+ }
55
+
56
+ if (devDeps.includes(source.value)) {
57
+ context.report({
58
+ messageId: "noImportOfDevDependencies",
59
+ node,
60
+ });
61
+ }
62
+ }
63
+
50
64
  return {
51
65
  // eslint-disable-next-line @typescript-eslint/naming-convention
52
66
  ImportDeclaration(node) {
53
- if (devDeps.includes(node.source.value)) {
54
- context.report({
55
- messageId: "noImportOfDevDependencies",
56
- node,
57
- });
58
- }
67
+ lint(node);
68
+ },
69
+ // eslint-disable-next-line @typescript-eslint/naming-convention
70
+ TSImportEqualsDeclaration(node) {
71
+ lint(node);
59
72
  },
60
73
  };
61
74
 
@@ -1,6 +1,6 @@
1
- import { ESLintUtils } from "@typescript-eslint/utils";
1
+ import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
2
2
  import * as ts from "typescript";
3
- import { createRule } from "../util";
3
+ import { createRule, getImportSource } from "../util";
4
4
  import { isDeclarationPath } from "@definitelytyped/utils";
5
5
 
6
6
  const rule = createRule({
@@ -25,28 +25,45 @@ const rule = createRule({
25
25
  const services = ESLintUtils.getParserServices(context);
26
26
  const checker = services.program.getTypeChecker();
27
27
 
28
- return {
29
- // eslint-disable-next-line @typescript-eslint/naming-convention
30
- ImportDeclaration(node) {
31
- const { source } = node;
32
- if (!source.value.startsWith(".")) {
33
- return;
34
- }
28
+ function lint(node: TSESTree.ImportDeclaration | TSESTree.TSImportEqualsDeclaration) {
29
+ const source = getImportSource(node);
30
+ if (!source) {
31
+ return;
32
+ }
33
+
34
+ if (!source.value.startsWith(".")) {
35
+ return;
36
+ }
37
+
38
+ const moduleSymbol = checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(source));
39
+ if (!moduleSymbol) {
40
+ // TODO(jakebailey): generally speaking, this should be an error; you can't import a non-module.
41
+ return;
42
+ }
43
+
44
+ if (!moduleSymbol.declarations) {
45
+ return;
46
+ }
35
47
 
36
- const moduleSymbol = checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(source));
37
- if (!moduleSymbol?.declarations) {
48
+ for (const declaration of moduleSymbol.declarations) {
49
+ if (ts.isSourceFile(declaration) && declaration.isDeclarationFile) {
50
+ context.report({
51
+ messageId: "useGlobalImport",
52
+ node: source,
53
+ });
38
54
  return;
39
55
  }
56
+ }
57
+ }
40
58
 
41
- for (const declaration of moduleSymbol.declarations) {
42
- if (ts.isSourceFile(declaration) && declaration.isDeclarationFile) {
43
- context.report({
44
- messageId: "useGlobalImport",
45
- node: source,
46
- });
47
- return;
48
- }
49
- }
59
+ return {
60
+ // eslint-disable-next-line @typescript-eslint/naming-convention
61
+ ImportDeclaration(node) {
62
+ lint(node);
63
+ },
64
+ // eslint-disable-next-line @typescript-eslint/naming-convention
65
+ TSImportEqualsDeclaration(node) {
66
+ lint(node);
50
67
  },
51
68
  };
52
69
  },
@@ -1,4 +1,5 @@
1
- import { createRule, getTypesPackageForDeclarationFile } from "../util";
1
+ import { TSESTree } from "@typescript-eslint/utils";
2
+ import { createRule, getImportSource, getTypesPackageForDeclarationFile } from "../util";
2
3
  const rule = createRule({
3
4
  name: "no-self-import",
4
5
  defaultOptions: [],
@@ -20,20 +21,33 @@ const rule = createRule({
20
21
  return {};
21
22
  }
22
23
 
24
+ function lint(node: TSESTree.ImportDeclaration | TSESTree.TSImportEqualsDeclaration) {
25
+ const source = getImportSource(node);
26
+ if (!source) {
27
+ return;
28
+ }
29
+
30
+ if (source.value === packageName || source.value.startsWith(packageName + "/")) {
31
+ context.report({
32
+ messageId: "useRelativeImport",
33
+ node,
34
+ });
35
+ } else if (source.value.match(/^\.\/v\d+(?:\.\d+)?(?:\/.*)?$/)) {
36
+ context.report({
37
+ messageId: "useOnlyCurrentVersion",
38
+ node,
39
+ });
40
+ }
41
+ }
42
+
23
43
  return {
24
44
  // eslint-disable-next-line @typescript-eslint/naming-convention
25
45
  ImportDeclaration(node) {
26
- if (node.source.value === packageName || node.source.value.startsWith(packageName + "/")) {
27
- context.report({
28
- messageId: "useRelativeImport",
29
- node,
30
- });
31
- } else if (node.source.value.match(/^\.\/v\d+(?:\.\d+)?(?:\/.*)?$/)) {
32
- context.report({
33
- messageId: "useOnlyCurrentVersion",
34
- node,
35
- });
36
- }
46
+ lint(node);
47
+ },
48
+ // eslint-disable-next-line @typescript-eslint/naming-convention
49
+ TSImportEqualsDeclaration(node) {
50
+ lint(node);
37
51
  },
38
52
  };
39
53
  },
package/src/util.ts CHANGED
@@ -98,3 +98,21 @@ export function findTypesPackage(file: string): TypesPackageInfo | undefined {
98
98
  };
99
99
  });
100
100
  }
101
+
102
+ export function getImportSource(
103
+ node: TSESTree.ImportDeclaration | TSESTree.TSImportEqualsDeclaration,
104
+ ): TSESTree.StringLiteral | undefined {
105
+ if (node.type === "ImportDeclaration") {
106
+ return node.source;
107
+ }
108
+
109
+ if (
110
+ node.moduleReference.type === "TSExternalModuleReference" &&
111
+ node.moduleReference.expression.type === "Literal" &&
112
+ typeof node.moduleReference.expression.value === "string"
113
+ ) {
114
+ return node.moduleReference.expression;
115
+ }
116
+
117
+ return undefined;
118
+ }
@@ -1,22 +1,30 @@
1
1
  types/no-import-of-dev-dependencies/bad.d.ts
2
+ 1:1 error Do not use a triple slash reference for devdep, use `import` style instead @typescript-eslint/triple-slash-reference
2
3
  1:1 error Do not use a triple slash reference for devdep, use `import` style instead @typescript-eslint/triple-slash-reference
3
4
  1:21 error .d.ts files may not triple-slash reference packages in devDependencies @definitelytyped/no-import-of-dev-dependencies
4
5
  2:1 error Do not use a triple slash reference for otherdevdep, use `import` style instead @typescript-eslint/triple-slash-reference
6
+ 2:1 error Do not use a triple slash reference for otherdevdep, use `import` style instead @typescript-eslint/triple-slash-reference
5
7
  2:21 error .d.ts files may not triple-slash reference packages in devDependencies @definitelytyped/no-import-of-dev-dependencies
6
8
  4:1 error .d.ts files may not import packages in devDependencies @definitelytyped/no-import-of-dev-dependencies
7
9
  5:1 error .d.ts files may not import packages in devDependencies @definitelytyped/no-import-of-dev-dependencies
10
+ 7:1 error .d.ts files may not import packages in devDependencies @definitelytyped/no-import-of-dev-dependencies
11
+ 8:1 error .d.ts files may not import packages in devDependencies @definitelytyped/no-import-of-dev-dependencies
8
12
 
9
- 6 problems (6 errors, 0 warnings)
13
+ 10 problems (10 errors, 0 warnings)
10
14
 
11
15
  ==== types/no-import-of-dev-dependencies/bad.d.ts ====
12
16
 
13
17
  /// <reference types="devdep"/>
14
18
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19
+ !!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for devdep, use `import` style instead.
20
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15
21
  !!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for devdep, use `import` style instead.
16
22
  ~~~~~~
17
23
  !!! @definitelytyped/no-import-of-dev-dependencies: .d.ts files may not triple-slash reference packages in devDependencies.
18
24
  /// <reference types="otherdevdep"/>
19
25
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26
+ !!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for otherdevdep, use `import` style instead.
27
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20
28
  !!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for otherdevdep, use `import` style instead.
21
29
  ~~~~~~~~~~~
22
30
  !!! @definitelytyped/no-import-of-dev-dependencies: .d.ts files may not triple-slash reference packages in devDependencies.
@@ -27,3 +35,10 @@ types/no-import-of-dev-dependencies/bad.d.ts
27
35
  import * as otherdevdep from "otherdevdep";
28
36
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29
37
  !!! @definitelytyped/no-import-of-dev-dependencies: .d.ts files may not import packages in devDependencies.
38
+
39
+ import devdep2 = require("devdep");
40
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41
+ !!! @definitelytyped/no-import-of-dev-dependencies: .d.ts files may not import packages in devDependencies.
42
+ import otherdevdep2 = require("otherdevdep");
43
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
+ !!! @definitelytyped/no-import-of-dev-dependencies: .d.ts files may not import packages in devDependencies.
@@ -1,16 +1,25 @@
1
1
  types/no-import-of-dev-dependencies/index.d.ts
2
+ 1:1 error Do not use a triple slash reference for other, use `import` style instead @typescript-eslint/triple-slash-reference
2
3
  1:1 error Do not use a triple slash reference for other, use `import` style instead @typescript-eslint/triple-slash-reference
3
4
  4:1 error Declaration file should not use a global import of itself. Use a relative import @definitelytyped/no-self-import
5
+ 7:1 error Declaration file should not use a global import of itself. Use a relative import @definitelytyped/no-self-import
4
6
 
5
- 2 problems (2 errors, 0 warnings)
7
+ 4 problems (4 errors, 0 warnings)
6
8
 
7
9
  ==== types/no-import-of-dev-dependencies/index.d.ts ====
8
10
 
9
11
  /// <reference types="other"/>
10
12
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11
13
  !!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for other, use `import` style instead.
14
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15
+ !!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for other, use `import` style instead.
12
16
 
13
17
  import other from "other";
14
18
  import self from "no-import-of-dev-dependencies";
15
19
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16
20
  !!! @definitelytyped/no-self-import: Declaration file should not use a global import of itself. Use a relative import.
21
+
22
+ import other2 = require("other");
23
+ import self2 = require("no-import-of-dev-dependencies");
24
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25
+ !!! @definitelytyped/no-self-import: Declaration file should not use a global import of itself. Use a relative import.
@@ -1,24 +1,39 @@
1
1
  types/no-import-of-dev-dependencies/no-import-of-dev-dependencies-tests.ts
2
2
  1:1 error Do not use a triple slash reference for devdep, use `import` style instead @typescript-eslint/triple-slash-reference
3
+ 1:1 error Do not use a triple slash reference for devdep, use `import` style instead @typescript-eslint/triple-slash-reference
4
+ 2:1 error Do not use a triple slash reference for otherdevdep, use `import` style instead @typescript-eslint/triple-slash-reference
3
5
  2:1 error Do not use a triple slash reference for otherdevdep, use `import` style instead @typescript-eslint/triple-slash-reference
4
6
  3:1 error Do not use a triple slash reference for other, use `import` style instead @typescript-eslint/triple-slash-reference
7
+ 3:1 error Do not use a triple slash reference for other, use `import` style instead @typescript-eslint/triple-slash-reference
5
8
 
6
- 3 problems (3 errors, 0 warnings)
9
+ 6 problems (6 errors, 0 warnings)
7
10
 
8
11
  ==== types/no-import-of-dev-dependencies/no-import-of-dev-dependencies-tests.ts ====
9
12
 
10
13
  /// <reference types="devdep"/>
11
14
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15
+ !!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for devdep, use `import` style instead.
16
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12
17
  !!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for devdep, use `import` style instead.
13
18
  /// <reference types="otherdevdep"/>
14
19
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20
+ !!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for otherdevdep, use `import` style instead.
21
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15
22
  !!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for otherdevdep, use `import` style instead.
16
23
  /// <reference types="other"/>
17
24
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18
25
  !!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for other, use `import` style instead.
26
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27
+ !!! @typescript-eslint/triple-slash-reference: Do not use a triple slash reference for other, use `import` style instead.
19
28
 
20
29
  import other from "other";
21
30
  import self from "no-import-of-dev-dependencies";
22
31
 
23
32
  import devdep from "devdep";
24
33
  import * as otherdevdep from "otherdevdep";
34
+
35
+ import other2 = require("other");
36
+ import self2 = require("no-import-of-dev-dependencies");
37
+
38
+ import devdep2 = require("devdep");
39
+ import otherdevdep2 = require("otherdevdep");
@@ -1,10 +1,5 @@
1
- types/no-relative-import-in-test/index.d.ts
2
- 1:1 error File has no content @definitelytyped/no-useless-files
3
-
4
- ✖ 1 problem (1 error, 0 warnings)
1
+ No errors
5
2
 
6
3
  ==== types/no-relative-import-in-test/index.d.ts ====
7
4
 
8
-
9
- ~
10
- !!! @definitelytyped/no-useless-files: File has no content.
5
+ export function getFoo(): "foo";
@@ -0,0 +1,10 @@
1
+ types/no-relative-import-in-test/no-relative-import-in-test-tests3.ts
2
+ 1:23 error Test file should not use a relative import. Use a global import as if this were a user of the package @definitelytyped/no-relative-import-in-test
3
+
4
+ ✖ 1 problem (1 error, 0 warnings)
5
+
6
+ ==== types/no-relative-import-in-test/no-relative-import-in-test-tests3.ts ====
7
+
8
+ import util = require('./');
9
+ ~~~~
10
+ !!! @definitelytyped/no-relative-import-in-test: Test file should not use a relative import. Use a global import as if this were a user of the package.