@definitelytyped/eslint-plugin 0.0.180 → 0.0.181

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 (43) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/rules/index.d.ts +4 -4
  3. package/dist/rules/index.js +4 -4
  4. package/dist/rules/index.js.map +1 -1
  5. package/dist/rules/no-bad-reference.d.ts +1 -1
  6. package/dist/rules/no-bad-reference.js +7 -9
  7. package/dist/rules/no-bad-reference.js.map +1 -1
  8. package/dist/rules/no-import-of-dev-dependencies.d.ts +2 -0
  9. package/dist/rules/no-import-of-dev-dependencies.js +89 -0
  10. package/dist/rules/no-import-of-dev-dependencies.js.map +1 -0
  11. package/dist/rules/no-old-dt-header.d.ts +2 -0
  12. package/dist/rules/no-old-dt-header.js +37 -0
  13. package/dist/rules/no-old-dt-header.js.map +1 -0
  14. package/dist/rules/no-self-import.d.ts +1 -1
  15. package/dist/rules/no-self-import.js +8 -1
  16. package/dist/rules/no-self-import.js.map +1 -1
  17. package/dist/rules/no-useless-files.js +2 -8
  18. package/dist/rules/no-useless-files.js.map +1 -1
  19. package/dist/util.d.ts +3 -1
  20. package/dist/util.js +9 -1
  21. package/dist/util.js.map +1 -1
  22. package/package.json +3 -3
  23. package/src/rules/index.ts +4 -4
  24. package/src/rules/no-bad-reference.ts +9 -13
  25. package/src/rules/no-import-of-dev-dependencies.ts +84 -0
  26. package/src/rules/no-old-dt-header.ts +40 -0
  27. package/src/rules/no-self-import.ts +8 -2
  28. package/src/rules/no-useless-files.ts +3 -9
  29. package/src/util.ts +13 -2
  30. package/test/no-bad-reference.test.ts +68 -0
  31. package/test/no-import-of-dev-dependencies.test.ts +72 -0
  32. package/test/no-old-dt-header.test.ts +71 -0
  33. package/test/no-self-import.test.ts +68 -0
  34. package/tsconfig.tsbuildinfo +1 -1
  35. package/dist/rules/dt-header.d.ts +0 -2
  36. package/dist/rules/dt-header.js +0 -62
  37. package/dist/rules/dt-header.js.map +0 -1
  38. package/dist/rules/no-outside-dependencies.d.ts +0 -2
  39. package/dist/rules/no-outside-dependencies.js +0 -41
  40. package/dist/rules/no-outside-dependencies.js.map +0 -1
  41. package/src/rules/dt-header.ts +0 -74
  42. package/src/rules/no-outside-dependencies.ts +0 -42
  43. package/test/dt-header.test.ts +0 -189
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @definitelytyped/eslint-plugin
2
2
 
3
+ ## 0.0.181
4
+
5
+ ### Patch Changes
6
+
7
+ - 024c3e73: Update @definitelytyped for Definitely Typed's monorepo upgrade
8
+ - Updated dependencies [024c3e73]
9
+ - Updated dependencies [9fffa8ff]
10
+ - @definitelytyped/header-parser@0.0.179
11
+ - @definitelytyped/utils@0.0.179
12
+
3
13
  ## 0.0.180
4
14
 
5
15
  ### Patch Changes
@@ -1,15 +1,13 @@
1
1
  export declare const rules: {
2
- "dt-header": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"definitionsBy" | "minimumTypeScriptVersion" | "parseError" | "typeDefinitionsFor" | "typescriptVersion", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
3
2
  "export-just-namespace": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"useTheBody", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
4
3
  "no-any-union": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"anyUnion", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
5
- "no-bad-reference": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"referencePathPackage" | "referencePathTest", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
4
+ "no-bad-reference": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"referencePathPackage" | "referencePathTest" | "referencePathOldVersion", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
6
5
  "no-const-enum": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"constEnum", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
7
6
  "no-dead-reference": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"referenceAtTop", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
8
7
  "no-declare-current-package": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"noDeclareCurrentPackage", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
9
8
  "no-import-default-of-export-equals": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"noImportDefaultOfExportEquals", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
10
- "no-outside-dependencies": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"noOutsideDependencies", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
11
9
  "no-relative-import-in-test": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"useGlobalImport", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
12
- "no-self-import": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"useRelativeImport", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
10
+ "no-self-import": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"useRelativeImport" | "useOnlyCurrentVersion", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
13
11
  "no-single-element-tuple-type": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"singleElementTupleType", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
14
12
  "no-unnecessary-generics": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"never" | "sole", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
15
13
  "no-useless-files": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"noContent", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
@@ -17,4 +15,6 @@ export declare const rules: {
17
15
  "redundant-undefined": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"redundantUndefined", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
18
16
  "strict-export-declare-modifiers": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"missingExplicitExport" | "redundantDeclare" | "redundantExport", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
19
17
  "no-single-declare-module": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"oneModuleDeclaration", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
18
+ "no-old-dt-header": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"noOldDTHeader", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
19
+ "no-import-of-dev-dependencies": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"noImportOfDevDependencies" | "noReferenceOfDevDependencies", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
20
20
  };
@@ -24,7 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.rules = void 0;
27
- const dtHeader = __importStar(require("./dt-header"));
28
27
  const exportJustNamespace = __importStar(require("./export-just-namespace"));
29
28
  const noAnyUnion = __importStar(require("./no-any-union"));
30
29
  const noBadReference = __importStar(require("./no-bad-reference"));
@@ -32,7 +31,6 @@ const noConstEnum = __importStar(require("./no-const-enum"));
32
31
  const noDeadReference = __importStar(require("./no-dead-reference"));
33
32
  const noDeclareCurrentPackage = __importStar(require("./no-declare-current-package"));
34
33
  const noImportDefaultOfExportEquals = __importStar(require("./no-import-default-of-export-equals"));
35
- const noOutsideDependencies = __importStar(require("./no-outside-dependencies"));
36
34
  const noRelativeImportInTest = __importStar(require("./no-relative-import-in-test"));
37
35
  const noSelfImport = __importStar(require("./no-self-import"));
38
36
  const noSingleElementTupleType = __importStar(require("./no-single-element-tuple-type"));
@@ -42,8 +40,9 @@ const preferDeclareFunction = __importStar(require("./prefer-declare-function"))
42
40
  const redundantUndefined = __importStar(require("./redundant-undefined"));
43
41
  const strictExportDeclareModifiers = __importStar(require("./strict-export-declare-modifiers"));
44
42
  const noSingleDeclareModule = __importStar(require("./no-single-declare-module"));
43
+ const noOldDTHeader = __importStar(require("./no-old-dt-header"));
44
+ const noImportOfDevDependencies = __importStar(require("./no-import-of-dev-dependencies"));
45
45
  exports.rules = {
46
- "dt-header": dtHeader,
47
46
  "export-just-namespace": exportJustNamespace,
48
47
  "no-any-union": noAnyUnion,
49
48
  "no-bad-reference": noBadReference,
@@ -51,7 +50,6 @@ exports.rules = {
51
50
  "no-dead-reference": noDeadReference,
52
51
  "no-declare-current-package": noDeclareCurrentPackage,
53
52
  "no-import-default-of-export-equals": noImportDefaultOfExportEquals,
54
- "no-outside-dependencies": noOutsideDependencies,
55
53
  "no-relative-import-in-test": noRelativeImportInTest,
56
54
  "no-self-import": noSelfImport,
57
55
  "no-single-element-tuple-type": noSingleElementTupleType,
@@ -61,5 +59,7 @@ exports.rules = {
61
59
  "redundant-undefined": redundantUndefined,
62
60
  "strict-export-declare-modifiers": strictExportDeclareModifiers,
63
61
  "no-single-declare-module": noSingleDeclareModule,
62
+ "no-old-dt-header": noOldDTHeader,
63
+ "no-import-of-dev-dependencies": noImportOfDevDependencies,
64
64
  };
65
65
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAwC;AACxC,6EAA+D;AAC/D,2DAA6C;AAC7C,mEAAqD;AACrD,6DAA+C;AAC/C,qEAAuD;AACvD,sFAAwE;AACxE,oGAAsF;AACtF,iFAAmE;AAC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AoC,EAAE,6BAA6B;IACnE,4BAA4B,EAAE,sBAAsB;IACpD,gBAAgB,EAAE,YAAY;IAC9B,8BAA8B,EAAE,wBAAwB;IACxD,yBAAyB,EAAE,qBAAqB;IAChD,kBAAkB,EAAE,cAAc;IAClC,yBAAyB,EAAE,qBAAqB;IAChD,qBAAqB,EAAE,kBAAkB;IACzC,iCAAiC,EAAE,4BAA4B;IAC/D,0BAA0B,EAAE,qBAAqB;IACjD,kBAAkB,EAAE,aAAa;IACjC,+BAA+B,EAAE,yBAAyB;CAC3D,CAAC"}
@@ -1,2 +1,2 @@
1
- declare const rule: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"referencePathPackage" | "referencePathTest", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
1
+ declare const rule: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"referencePathPackage" | "referencePathTest" | "referencePathOldVersion", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
2
2
  export = rule;
@@ -6,33 +6,31 @@ const rule = (0, util_1.createRule)({
6
6
  meta: {
7
7
  type: "problem",
8
8
  docs: {
9
- description: `Forbids <reference path="../etc"/> in any file, and forbid <reference path> in test files.`,
9
+ description: `Forbids <reference path="./vNN"/> in all files, <reference path="../etc"/> in declaration files, and all <reference path> in test files.`,
10
10
  recommended: "error",
11
11
  },
12
12
  messages: {
13
13
  referencePathPackage: "Don't use <reference path> to reference another package. Use an import or <reference types> instead.",
14
14
  referencePathTest: "Don't use <reference path> in test files. Use <reference types> or include the file in 'tsconfig.json'.",
15
+ referencePathOldVersion: "Don't use <reference path> to reference an old version of the current package.",
15
16
  },
16
17
  schema: [],
17
18
  },
18
19
  create(context) {
19
- var _a;
20
- const { comments } = context.getSourceCode().ast;
21
20
  const isDeclarationFile = context.getFilename().endsWith(".d.ts");
22
- for (const comment of comments) {
23
- const referenceMatch = (_a = comment.value.match(/<reference\s+path\s*=\s*"(.+)"\s*\/>/)) === null || _a === void 0 ? void 0 : _a[1];
24
- if (!referenceMatch) {
25
- continue;
21
+ (0, util_1.commentsMatching)(context.getSourceCode(), /<reference\s+path\s*=\s*"(.+)"\s*\/>/, (ref, comment) => {
22
+ if (ref.match(/^\.\/v\d+(?:\.\d+)?(?:\/.*)?$/)) {
23
+ report(comment, "referencePathOldVersion");
26
24
  }
27
25
  if (isDeclarationFile) {
28
- if (referenceMatch.startsWith("..")) {
26
+ if (ref.startsWith("..")) {
29
27
  report(comment, "referencePathPackage");
30
28
  }
31
29
  }
32
30
  else {
33
31
  report(comment, "referencePathTest");
34
32
  }
35
- }
33
+ });
36
34
  return {};
37
35
  function report(comment, messageId) {
38
36
  context.report({
@@ -1 +1 @@
1
- {"version":3,"file":"no-bad-reference.js","sourceRoot":"","sources":["../../src/rules/no-bad-reference.ts"],"names":[],"mappings":";AACA,kCAAqC;AAIrC,MAAM,IAAI,GAAG,IAAA,iBAAU,EAAC;IACtB,IAAI,EAAE,kBAAkB;IACxB,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,4FAA4F;YACzG,WAAW,EAAE,OAAO;SACrB;QACD,QAAQ,EAAE;YACR,oBAAoB,EAClB,sGAAsG;YACxG,iBAAiB,EACf,yGAAyG;SAC5G;QACD,MAAM,EAAE,EAAE;KACX;IACD,MAAM,CAAC,OAAO;;QACZ,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,GAAG,CAAC;QACjD,MAAM,iBAAiB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAElE,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC9B,MAAM,cAAc,GAAG,MAAA,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,sCAAsC,CAAC,0CAAG,CAAC,CAAC,CAAC;YACxF,IAAI,CAAC,cAAc,EAAE;gBACnB,SAAS;aACV;YAED,IAAI,iBAAiB,EAAE;gBACrB,IAAI,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;oBACnC,MAAM,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC;iBACzC;aACF;iBAAM;gBACL,MAAM,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;aACtC;SACF;QAED,OAAO,EAAE,CAAC;QAEV,SAAS,MAAM,CAAC,OAAyB,EAAE,SAAoB;YAC7D,OAAO,CAAC,MAAM,CAAC;gBACb,GAAG,EAAE;oBACH,GAAG,EAAE;wBACH,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC;wBACtC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI;qBAC3B;oBACD,KAAK,EAAE;wBACL,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;wBACtC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI;qBAC7B;iBACF;gBACD,SAAS;aACV,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF,CAAC,CAAC;AAEH,iBAAS,IAAI,CAAC"}
1
+ {"version":3,"file":"no-bad-reference.js","sourceRoot":"","sources":["../../src/rules/no-bad-reference.ts"],"names":[],"mappings":";AACA,kCAAuD;AAGvD,MAAM,IAAI,GAAG,IAAA,iBAAU,EAAC;IACtB,IAAI,EAAE,kBAAkB;IACxB,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,0IAA0I;YACvJ,WAAW,EAAE,OAAO;SACrB;QACD,QAAQ,EAAE;YACR,oBAAoB,EAClB,sGAAsG;YACxG,iBAAiB,EACf,yGAAyG;YAC3G,uBAAuB,EAAE,gFAAgF;SAC1G;QACD,MAAM,EAAE,EAAE;KACX;IACD,MAAM,CAAC,OAAO;QACZ,MAAM,iBAAiB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAClE,IAAA,uBAAgB,EAAC,OAAO,CAAC,aAAa,EAAE,EAAE,sCAAsC,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;YACjG,IAAI,GAAG,CAAC,KAAK,CAAC,+BAA+B,CAAC,EAAE;gBAC9C,MAAM,CAAC,OAAO,EAAE,yBAAyB,CAAC,CAAC;aAC5C;YACD,IAAI,iBAAiB,EAAE;gBACrB,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;oBACxB,MAAM,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC;iBACzC;aACF;iBAAM;gBACL,MAAM,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;aACtC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,EAAE,CAAC;QAEV,SAAS,MAAM,CAAC,OAAyB,EAAE,SAAoB;YAC7D,OAAO,CAAC,MAAM,CAAC;gBACb,GAAG,EAAE;oBACH,GAAG,EAAE;wBACH,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC;wBACtC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI;qBAC3B;oBACD,KAAK,EAAE;wBACL,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;wBACtC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI;qBAC7B;iBACF;gBACD,SAAS;aACV,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF,CAAC,CAAC;AAEH,iBAAS,IAAI,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare const rule: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"noImportOfDevDependencies" | "noReferenceOfDevDependencies", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
2
+ export = rule;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const util_1 = require("../util");
6
+ const fs_1 = __importDefault(require("fs"));
7
+ const path_1 = __importDefault(require("path"));
8
+ const rule = (0, util_1.createRule)({
9
+ name: "no-import-of-dev-dependencies",
10
+ defaultOptions: [],
11
+ meta: {
12
+ type: "problem",
13
+ docs: {
14
+ description: "Forbid imports and references to devDependencies inside .d.ts files.",
15
+ recommended: "error",
16
+ },
17
+ messages: {
18
+ noImportOfDevDependencies: `.d.ts files may not import packages in devDependencies.`,
19
+ noReferenceOfDevDependencies: `.d.ts files may not triple-slash reference packages in devDependencies.`,
20
+ },
21
+ schema: [],
22
+ },
23
+ create(context) {
24
+ var _a, _b;
25
+ const packageName = (0, util_1.getTypesPackageForDeclarationFile)(context.getFilename());
26
+ if (context.getFilename().endsWith(".d.ts")) {
27
+ const packageJson = getPackageJson((_b = (_a = context.getPhysicalFilename) === null || _a === void 0 ? void 0 : _a.call(context)) !== null && _b !== void 0 ? _b : context.getFilename());
28
+ const devdeps = packageJson
29
+ ? Object.keys(packageJson.devDependencies).map((dep) => dep.replace(/@types\//, ""))
30
+ : [];
31
+ (0, util_1.commentsMatching)(context.getSourceCode(), /<reference\s+types\s*=\s*"(.+)"\s*\/>/, (ref, comment) => {
32
+ if (devdeps.includes(ref) && ref !== packageName) {
33
+ report(comment, "noReferenceOfDevDependencies");
34
+ }
35
+ });
36
+ return {
37
+ // eslint-disable-next-line @typescript-eslint/naming-convention
38
+ ImportDeclaration(node) {
39
+ if (devdeps.includes(node.source.value) && node.source.value !== packageName) {
40
+ context.report({
41
+ messageId: "noImportOfDevDependencies",
42
+ node,
43
+ });
44
+ }
45
+ },
46
+ };
47
+ }
48
+ else {
49
+ return {};
50
+ }
51
+ function report(comment, messageId) {
52
+ context.report({
53
+ loc: {
54
+ end: {
55
+ column: comment.value.lastIndexOf(`"`),
56
+ line: comment.loc.end.line,
57
+ },
58
+ start: {
59
+ column: comment.value.indexOf(`"`) + 1,
60
+ line: comment.loc.start.line,
61
+ },
62
+ },
63
+ messageId,
64
+ });
65
+ }
66
+ },
67
+ });
68
+ function getPackageJson(sourceFile) {
69
+ let dir = path_1.default.dirname(sourceFile);
70
+ let text;
71
+ while (dir !== "/") {
72
+ try {
73
+ text = fs_1.default.readFileSync(path_1.default.join(dir, "package.json"), "utf8");
74
+ break;
75
+ }
76
+ catch {
77
+ // presumably because file does not exist, so continue
78
+ }
79
+ dir = path_1.default.dirname(dir);
80
+ }
81
+ if (!text)
82
+ return undefined;
83
+ const json = JSON.parse(text);
84
+ if ("devDependencies" in json)
85
+ return json;
86
+ return undefined;
87
+ }
88
+ module.exports = rule;
89
+ //# sourceMappingURL=no-import-of-dev-dependencies.js.map
@@ -0,0 +1 @@
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,4CAAoB;AACpB,gDAAwB;AAGxB,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;YACnF,WAAW,EAAE,OAAO;SACrB;QACD,QAAQ,EAAE;YACR,yBAAyB,EAAE,yDAAyD;YACpF,4BAA4B,EAAE,yEAAyE;SACxG;QACD,MAAM,EAAE,EAAE;KACX;IACD,MAAM,CAAC,OAAO;;QACZ,MAAM,WAAW,GAAG,IAAA,wCAAiC,EAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;QAC7E,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAC3C,MAAM,WAAW,GAAG,cAAc,CAAC,M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AAO,CAAC,GAAG,CAAC,GAAG,CAAC;wBACtC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI;qBAC7B;iBACF;gBACD,SAAS;aACV,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF,CAAC,CAAC;AACH,SAAS,cAAc,CAAC,UAAkB;IACxC,IAAI,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACnC,IAAI,IAAwB,CAAC;IAC7B,OAAO,GAAG,KAAK,GAAG,EAAE;QAClB,IAAI;YACF,IAAI,GAAG,YAAE,CAAC,YAAY,CAAC,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC;YAC/D,MAAM;SACP;QAAC,MAAM;YACN,sDAAsD;SACvD;QACD,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;KACzB;IACD,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,iBAAiB,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IAC3C,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,iBAAS,IAAI,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare const rule: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"noOldDTHeader", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
2
+ export = rule;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ const util_1 = require("../util");
3
+ const rule = (0, util_1.createRule)({
4
+ name: "no-bad-reference",
5
+ defaultOptions: [],
6
+ meta: {
7
+ type: "problem",
8
+ docs: {
9
+ description: `Forbids <reference path="./vNN"/> in all files, <reference path="../etc"/> in declaration files, and all <reference path> in test files.`,
10
+ recommended: "error",
11
+ },
12
+ messages: {
13
+ noOldDTHeader: "Specify package metadata in package.json. Do not use a header like `// Type definitions for foo 1.2`",
14
+ },
15
+ schema: [],
16
+ },
17
+ create(context) {
18
+ const text = context.getSourceCode().text;
19
+ if (context.getFilename().endsWith(".d.ts") &&
20
+ text.indexOf("// Type definitions for ") === 0 &&
21
+ text.indexOf("// Definitions by: ") > 0) {
22
+ context.report({
23
+ messageId: "noOldDTHeader",
24
+ loc: {
25
+ start: { column: 0, line: 1 },
26
+ end: {
27
+ column: "// Type definitions for ".length,
28
+ line: 1,
29
+ },
30
+ },
31
+ });
32
+ }
33
+ return {};
34
+ },
35
+ });
36
+ module.exports = rule;
37
+ //# sourceMappingURL=no-old-dt-header.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-old-dt-header.js","sourceRoot":"","sources":["../../src/rules/no-old-dt-header.ts"],"names":[],"mappings":";AAAA,kCAAqC;AAErC,MAAM,IAAI,GAAG,IAAA,iBAAU,EAAC;IACtB,IAAI,EAAE,kBAAkB;IACxB,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,0IAA0I;YACvJ,WAAW,EAAE,OAAO;SACrB;QACD,QAAQ,EAAE;YACR,aAAa,EACX,sGAAsG;SACzG;QACD,MAAM,EAAE,EAAE;KACX;IACD,MAAM,CAAC,OAAO;QACZ,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC;QAC1C,IACE,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;YACvC,IAAI,CAAC,OAAO,CAAC,0BAA0B,CAAC,KAAK,CAAC;YAC9C,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,GAAG,CAAC,EACvC;YACA,OAAO,CAAC,MAAM,CAAC;gBACb,SAAS,EAAE,eAAe;gBAC1B,GAAG,EAAE;oBACH,KAAK,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE;oBAC7B,GAAG,EAAE;wBACH,MAAM,EAAE,0BAA0B,CAAC,MAAM;wBACzC,IAAI,EAAE,CAAC;qBACR;iBACF;aACF,CAAC,CAAC;SACJ;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAC,CAAC;AAEH,iBAAS,IAAI,CAAC"}
@@ -1,2 +1,2 @@
1
- declare const rule: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"useRelativeImport", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
1
+ declare const rule: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"useRelativeImport" | "useOnlyCurrentVersion", never[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
2
2
  export = rule;
@@ -6,11 +6,12 @@ const rule = (0, util_1.createRule)({
6
6
  meta: {
7
7
  type: "problem",
8
8
  docs: {
9
- description: "Forbids declaration files to import the current package using a global import.",
9
+ description: "Forbids declaration files to import the current package using a global import or old versions with a relative import.",
10
10
  recommended: "error",
11
11
  },
12
12
  messages: {
13
13
  useRelativeImport: "Declaration file should not use a global import of itself. Use a relative import.",
14
+ useOnlyCurrentVersion: "Don't import an old version of the current package.",
14
15
  },
15
16
  schema: [],
16
17
  },
@@ -25,6 +26,12 @@ const rule = (0, util_1.createRule)({
25
26
  node,
26
27
  });
27
28
  }
29
+ else if (node.source.value.match(/^\.\/v\d+(?:\.\d+)?(?:\/.*)?$/)) {
30
+ context.report({
31
+ messageId: "useOnlyCurrentVersion",
32
+ node,
33
+ });
34
+ }
28
35
  },
29
36
  };
30
37
  },
@@ -1 +1 @@
1
- {"version":3,"file":"no-self-import.js","sourceRoot":"","sources":["../../src/rules/no-self-import.ts"],"names":[],"mappings":";AAAA,kCAAwE;AAExE,MAAM,IAAI,GAAG,IAAA,iBAAU,EAAC;IACtB,IAAI,EAAE,gBAAgB;IACtB,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,E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,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"}
@@ -15,7 +15,6 @@ const rule = (0, util_1.createRule)({
15
15
  schema: [],
16
16
  },
17
17
  create(context) {
18
- var _a;
19
18
  const { ast: { tokens, comments }, } = context.getSourceCode();
20
19
  if (tokens.length === 0) {
21
20
  if (comments.length === 0) {
@@ -24,14 +23,9 @@ const rule = (0, util_1.createRule)({
24
23
  else {
25
24
  const referenceRegExp = /^\/\s*<reference\s*(types|path)\s*=\s*["|'](.*)["|']/;
26
25
  let noReferenceFound = true;
27
- for (const comment of comments) {
28
- const referenceMatch = (_a = comment.value.match(referenceRegExp)) === null || _a === void 0 ? void 0 : _a[1];
29
- if (!referenceMatch) {
30
- continue;
31
- }
26
+ (0, util_1.commentsMatching)(context.getSourceCode(), referenceRegExp, () => {
32
27
  noReferenceFound = false;
33
- break;
34
- }
28
+ });
35
29
  if (noReferenceFound) {
36
30
  reportNoContent();
37
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"no-useless-files.js","sourceRoot":"","sources":["../../src/rules/no-useless-files.ts"],"names":[],"mappings":";AAAA,kCAAqC;AAErC,MAAM,IAAI,GAAG,IAAA,iBAAU,EAAC;IACtB,IAAI,EAAE,kBAAkB;IACxB,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IA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.d.ts CHANGED
@@ -1,5 +1,7 @@
1
+ import { TSESTree } from "@typescript-eslint/utils";
1
2
  import { RuleWithMetaAndName } from "@typescript-eslint/utils/dist/eslint-utils";
2
- import { RuleListener, RuleModule } from "@typescript-eslint/utils/dist/ts-eslint";
3
+ import { RuleListener, RuleModule, SourceCode } from "@typescript-eslint/utils/dist/ts-eslint";
3
4
  export declare const createRule: <TOptions extends readonly unknown[], TMessageIds extends string>(opts: Readonly<RuleWithMetaAndName<TOptions, TMessageIds, RuleListener>>) => RuleModule<TMessageIds, TOptions>;
4
5
  export declare function getTypesPackageForDeclarationFile(file: string): string | undefined;
5
6
  export declare function isMainFile(fileName: string, allowNested: boolean): boolean;
7
+ export declare function commentsMatching(sourceFile: Readonly<SourceCode>, regex: RegExp, f: (match: string, c: TSESTree.Comment) => void): void;
package/dist/util.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isMainFile = exports.getTypesPackageForDeclarationFile = exports.createRule = void 0;
3
+ exports.commentsMatching = exports.isMainFile = exports.getTypesPackageForDeclarationFile = exports.createRule = void 0;
4
4
  const utils_1 = require("@definitelytyped/utils");
5
5
  const utils_2 = require("@typescript-eslint/utils");
6
6
  const path_1 = require("path");
@@ -37,4 +37,12 @@ function isMainFile(fileName, allowNested) {
37
37
  return (0, path_1.basename)((0, path_1.dirname)(parent)) === "types";
38
38
  }
39
39
  exports.isMainFile = isMainFile;
40
+ function commentsMatching(sourceFile, regex, f) {
41
+ for (const comment of sourceFile.ast.comments) {
42
+ const m = comment.value.match(regex);
43
+ if (m)
44
+ f(m[1], comment);
45
+ }
46
+ }
47
+ exports.commentsMatching = commentsMatching;
40
48
  //# 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,kDAA+D;AAC/D,oDAAuD;AAGvD,+BAAyC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C,MAAM,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC;YAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;KACzB;AACH,CAAC;AATD,4CASC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@definitelytyped/eslint-plugin",
3
- "version": "0.0.180",
3
+ "version": "0.0.181",
4
4
  "description": "ESLint rules for DefinitelyTyped",
5
5
  "main": "./dist/index.js",
6
6
  "publishConfig": {
@@ -20,8 +20,8 @@
20
20
  "dependencies": {
21
21
  "@typescript-eslint/types": "^5.56.0",
22
22
  "@typescript-eslint/utils": "^5.55.0",
23
- "@definitelytyped/header-parser": "0.0.178",
24
- "@definitelytyped/utils": "0.0.178"
23
+ "@definitelytyped/header-parser": "0.0.179",
24
+ "@definitelytyped/utils": "0.0.179"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@typescript-eslint/eslint-plugin": "^5.0.0",
@@ -1,4 +1,3 @@
1
- import * as dtHeader from "./dt-header";
2
1
  import * as exportJustNamespace from "./export-just-namespace";
3
2
  import * as noAnyUnion from "./no-any-union";
4
3
  import * as noBadReference from "./no-bad-reference";
@@ -6,7 +5,6 @@ import * as noConstEnum from "./no-const-enum";
6
5
  import * as noDeadReference from "./no-dead-reference";
7
6
  import * as noDeclareCurrentPackage from "./no-declare-current-package";
8
7
  import * as noImportDefaultOfExportEquals from "./no-import-default-of-export-equals";
9
- import * as noOutsideDependencies from "./no-outside-dependencies";
10
8
  import * as noRelativeImportInTest from "./no-relative-import-in-test";
11
9
  import * as noSelfImport from "./no-self-import";
12
10
  import * as noSingleElementTupleType from "./no-single-element-tuple-type";
@@ -16,9 +14,10 @@ import * as preferDeclareFunction from "./prefer-declare-function";
16
14
  import * as redundantUndefined from "./redundant-undefined";
17
15
  import * as strictExportDeclareModifiers from "./strict-export-declare-modifiers";
18
16
  import * as noSingleDeclareModule from "./no-single-declare-module";
17
+ import * as noOldDTHeader from "./no-old-dt-header";
18
+ import * as noImportOfDevDependencies from "./no-import-of-dev-dependencies";
19
19
 
20
20
  export const rules = {
21
- "dt-header": dtHeader,
22
21
  "export-just-namespace": exportJustNamespace,
23
22
  "no-any-union": noAnyUnion,
24
23
  "no-bad-reference": noBadReference,
@@ -26,7 +25,6 @@ export const rules = {
26
25
  "no-dead-reference": noDeadReference,
27
26
  "no-declare-current-package": noDeclareCurrentPackage,
28
27
  "no-import-default-of-export-equals": noImportDefaultOfExportEquals,
29
- "no-outside-dependencies": noOutsideDependencies,
30
28
  "no-relative-import-in-test": noRelativeImportInTest,
31
29
  "no-self-import": noSelfImport,
32
30
  "no-single-element-tuple-type": noSingleElementTupleType,
@@ -36,4 +34,6 @@ export const rules = {
36
34
  "redundant-undefined": redundantUndefined,
37
35
  "strict-export-declare-modifiers": strictExportDeclareModifiers,
38
36
  "no-single-declare-module": noSingleDeclareModule,
37
+ "no-old-dt-header": noOldDTHeader,
38
+ "no-import-of-dev-dependencies": noImportOfDevDependencies,
39
39
  };
@@ -1,15 +1,14 @@
1
1
  import { TSESTree } from "@typescript-eslint/utils";
2
- import { createRule } from "../util";
3
-
4
- type MessageId = "referencePathPackage" | "referencePathTest";
2
+ import { commentsMatching, createRule } from "../util";
5
3
 
4
+ type MessageId = "referencePathPackage" | "referencePathTest" | "referencePathOldVersion";
6
5
  const rule = createRule({
7
6
  name: "no-bad-reference",
8
7
  defaultOptions: [],
9
8
  meta: {
10
9
  type: "problem",
11
10
  docs: {
12
- description: `Forbids <reference path="../etc"/> in any file, and forbid <reference path> in test files.`,
11
+ description: `Forbids <reference path="./vNN"/> in all files, <reference path="../etc"/> in declaration files, and all <reference path> in test files.`,
13
12
  recommended: "error",
14
13
  },
15
14
  messages: {
@@ -17,27 +16,24 @@ const rule = createRule({
17
16
  "Don't use <reference path> to reference another package. Use an import or <reference types> instead.",
18
17
  referencePathTest:
19
18
  "Don't use <reference path> in test files. Use <reference types> or include the file in 'tsconfig.json'.",
19
+ referencePathOldVersion: "Don't use <reference path> to reference an old version of the current package.",
20
20
  },
21
21
  schema: [],
22
22
  },
23
23
  create(context) {
24
- const { comments } = context.getSourceCode().ast;
25
24
  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;
25
+ commentsMatching(context.getSourceCode(), /<reference\s+path\s*=\s*"(.+)"\s*\/>/, (ref, comment) => {
26
+ if (ref.match(/^\.\/v\d+(?:\.\d+)?(?:\/.*)?$/)) {
27
+ report(comment, "referencePathOldVersion");
31
28
  }
32
-
33
29
  if (isDeclarationFile) {
34
- if (referenceMatch.startsWith("..")) {
30
+ if (ref.startsWith("..")) {
35
31
  report(comment, "referencePathPackage");
36
32
  }
37
33
  } else {
38
34
  report(comment, "referencePathTest");
39
35
  }
40
- }
36
+ });
41
37
 
42
38
  return {};
43
39
 
@@ -0,0 +1,84 @@
1
+ import { TSESTree } from "@typescript-eslint/utils";
2
+ import { createRule, commentsMatching, getTypesPackageForDeclarationFile } from "../util";
3
+ import fs from "fs";
4
+ import path from "path";
5
+
6
+ type MessageId = "noImportOfDevDependencies" | "noReferenceOfDevDependencies";
7
+ const rule = createRule({
8
+ name: "no-import-of-dev-dependencies",
9
+ defaultOptions: [],
10
+ meta: {
11
+ type: "problem",
12
+ docs: {
13
+ description: "Forbid imports and references to devDependencies inside .d.ts files.",
14
+ recommended: "error",
15
+ },
16
+ messages: {
17
+ noImportOfDevDependencies: `.d.ts files may not import packages in devDependencies.`,
18
+ noReferenceOfDevDependencies: `.d.ts files may not triple-slash reference packages in devDependencies.`,
19
+ },
20
+ schema: [],
21
+ },
22
+ create(context) {
23
+ const packageName = getTypesPackageForDeclarationFile(context.getFilename());
24
+ if (context.getFilename().endsWith(".d.ts")) {
25
+ const packageJson = getPackageJson(context.getPhysicalFilename?.() ?? context.getFilename());
26
+ const devdeps = packageJson
27
+ ? Object.keys(packageJson.devDependencies).map((dep) => dep.replace(/@types\//, ""))
28
+ : [];
29
+ commentsMatching(context.getSourceCode(), /<reference\s+types\s*=\s*"(.+)"\s*\/>/, (ref, comment) => {
30
+ if (devdeps.includes(ref) && ref !== packageName) {
31
+ report(comment, "noReferenceOfDevDependencies");
32
+ }
33
+ });
34
+
35
+ return {
36
+ // eslint-disable-next-line @typescript-eslint/naming-convention
37
+ ImportDeclaration(node) {
38
+ if (devdeps.includes(node.source.value) && node.source.value !== packageName) {
39
+ context.report({
40
+ messageId: "noImportOfDevDependencies",
41
+ node,
42
+ });
43
+ }
44
+ },
45
+ };
46
+ } else {
47
+ return {};
48
+ }
49
+ function report(comment: TSESTree.Comment, messageId: MessageId) {
50
+ context.report({
51
+ loc: {
52
+ end: {
53
+ column: comment.value.lastIndexOf(`"`),
54
+ line: comment.loc.end.line,
55
+ },
56
+ start: {
57
+ column: comment.value.indexOf(`"`) + 1,
58
+ line: comment.loc.start.line,
59
+ },
60
+ },
61
+ messageId,
62
+ });
63
+ }
64
+ },
65
+ });
66
+ function getPackageJson(sourceFile: string): { devDependencies: Record<string, string> } | undefined {
67
+ let dir = path.dirname(sourceFile);
68
+ let text: string | undefined;
69
+ while (dir !== "/") {
70
+ try {
71
+ text = fs.readFileSync(path.join(dir, "package.json"), "utf8");
72
+ break;
73
+ } catch {
74
+ // presumably because file does not exist, so continue
75
+ }
76
+ dir = path.dirname(dir);
77
+ }
78
+ if (!text) return undefined;
79
+ const json = JSON.parse(text);
80
+ if ("devDependencies" in json) return json;
81
+ return undefined;
82
+ }
83
+
84
+ export = rule;