@definitelytyped/eslint-plugin 0.0.192 → 0.0.194
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/configs/all.js +4 -0
- package/dist/configs/all.js.map +1 -1
- package/dist/index.d.ts +10 -3
- package/dist/index.js +12 -6
- package/dist/index.js.map +1 -1
- package/dist/rules/no-import-of-dev-dependencies.js +17 -6
- package/dist/rules/no-import-of-dev-dependencies.js.map +1 -1
- package/dist/rules/no-relative-import-in-test.js +31 -17
- package/dist/rules/no-relative-import-in-test.js.map +1 -1
- package/dist/rules/no-self-import.js +23 -12
- package/dist/rules/no-self-import.js.map +1 -1
- package/dist/util.d.ts +1 -0
- package/dist/util.js +13 -1
- package/dist/util.js.map +1 -1
- package/package.json +1 -1
- package/src/configs/all.ts +4 -0
- package/src/index.ts +16 -4
- package/src/rules/no-import-of-dev-dependencies.ts +20 -7
- package/src/rules/no-relative-import-in-test.ts +37 -20
- package/src/rules/no-self-import.ts +26 -12
- package/src/util.ts +18 -0
- package/test/__file_snapshots__/types/no-import-of-dev-dependencies/bad.d.ts.lint +16 -1
- package/test/__file_snapshots__/types/no-import-of-dev-dependencies/index.d.ts.lint +10 -1
- package/test/__file_snapshots__/types/no-import-of-dev-dependencies/no-import-of-dev-dependencies-tests.ts.lint +16 -1
- package/test/__file_snapshots__/types/no-relative-import-in-test/index.d.ts.lint +2 -7
- package/test/__file_snapshots__/types/no-relative-import-in-test/no-relative-import-in-test-tests3.ts.lint +10 -0
- package/test/__file_snapshots__/types/no-relative-references/index.d.ts.lint +7 -1
- package/test/__file_snapshots__/types/no-relative-references/v1/index.d.ts.lint +7 -1
- package/test/__file_snapshots__/types/no-self-import/bad.d.ts.lint +38 -8
- package/test/__file_snapshots__/types/no-self-import/index.d.ts.lint +8 -0
- package/test/__file_snapshots__/types/no-self-import/no-self-import-tests.ts.lint +16 -1
- package/test/__file_snapshots__/types/scoped__no-relative-references/index.d.ts.lint +7 -1
- package/test/__file_snapshots__/types/scoped__no-relative-references/v1/index.d.ts.lint +7 -1
- package/test/eslint.test.ts +1 -1
- package/test/fixtures/types/no-import-of-dev-dependencies/bad.d.ts +3 -0
- package/test/fixtures/types/no-import-of-dev-dependencies/index.d.ts +3 -0
- package/test/fixtures/types/no-import-of-dev-dependencies/no-import-of-dev-dependencies-tests.ts +6 -0
- package/test/fixtures/types/no-relative-import-in-test/index.d.ts +1 -0
- package/test/fixtures/types/no-relative-import-in-test/no-relative-import-in-test-tests3.ts +1 -0
- package/test/fixtures/types/no-relative-import-in-test/tsconfig.json +1 -0
- package/test/fixtures/types/no-self-import/bad.d.ts +9 -0
- package/test/fixtures/types/no-self-import/index.d.ts +8 -0
- package/test/fixtures/types/no-self-import/no-self-import-tests.ts +6 -0
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @definitelytyped/eslint-plugin
|
|
2
2
|
|
|
3
|
+
## 0.0.194
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 59076828: Remove void-return, switch on no-invalid-void-type
|
|
8
|
+
|
|
9
|
+
## 0.0.193
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 0a3c2d5b: Fully type eslint plugin export and add metadata
|
|
14
|
+
- 7af66e7d: Handle `import = require()` in lint rules
|
|
15
|
+
|
|
3
16
|
## 0.0.192
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/configs/all.js
CHANGED
|
@@ -174,6 +174,10 @@ exports.all = {
|
|
|
174
174
|
"@typescript-eslint/explicit-member-accessibility": ["error", { accessibility: "no-public" }],
|
|
175
175
|
"@typescript-eslint/no-misused-new": "error",
|
|
176
176
|
"@typescript-eslint/consistent-type-definitions": "error",
|
|
177
|
+
"@typescript-eslint/no-invalid-void-type": [
|
|
178
|
+
"error",
|
|
179
|
+
{ allowAsThisParameter: true, allowInGenericTypeArguments: true },
|
|
180
|
+
],
|
|
177
181
|
},
|
|
178
182
|
},
|
|
179
183
|
],
|
package/dist/configs/all.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"all.js","sourceRoot":"","sources":["../../src/configs/all.ts"],"names":[],"mappings":";;;AAAA,oCAAiC;AAGpB,QAAA,GAAG,GAAsB;IACpC,OAAO,EAAE,CAAC,kBAAkB,EAAE,oBAAoB,EAAE,OAAO,CAAC;IAC5D,QAAQ,EAAE;QACR,KAAK,EAAE;YACL,iBAAiB,EAAE;gBACjB,QAAQ,EAAE,UAAU;gBACpB,SAAS,EAAE,WAAW;gBACtB,QAAQ,EAAE,UAAU;gBACpB,MAAM,EAAE,QAAQ;gBAChB,KAAK,EAAE,OAAO;gBACd,MAAM,EAAE,QAAQ;gBAChB,OAAO,EAAE,SAAS;aACnB;SACF;KACF;IACD,KAAK,EAAE;QACL,uBAAuB,EAAE;YACvB,OAAO;YACP;gBACE,kFAAkF;gBAClF,wEAAwE;gBACxE,WAAW,EAAE;oBACX,YAAY;oBACZ,MAAM;oBACN,KAAK;oBACL,QAAQ;oBACR,MAAM;oBACN,OAAO;oBACP,UAAU;oBACV,KAAK;oBACL,WAAW;oBACX,OAAO;oBACP,kBAAkB;oBAClB,kBAAkB;oBAClB,oBAAoB;oBACpB,YAAY;oBACZ,SAAS;oBACT,aAAa;oBACb,eAAe;oBACf,cAAc;oBACd,QAAQ;oBACR,KAAK;oBACL,eAAe;oBACf,cAAc;oBACd,QAAQ;oBACR,QAAQ;oBACR,cAAc;oBACd,SAAS;oBACT,OAAO;oBACP,OAAO;oBACP,OAAO;oBACP,QAAQ;oBACR,KAAK;oBACL,YAAY;oBACZ,QAAQ;oBACR,iBAAiB;oBACjB,QAAQ;oBACR,IAAI;oBACJ,KAAK;oBACL,iBAAiB;oBACjB,OAAO;oBACP,UAAU;oBACV,QAAQ;oBACR,MAAM;oBACN,QAAQ;oBACR,O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P;wBACE,QAAQ,EAAE,WAAW;wBACrB,MAAM,EAAE,EAAE;wBACV,MAAM,EAAE;4BACN,KAAK,EAAE,SAAS;4BAChB,KAAK,EAAE,KAAK;yBACb;qBACF;iBACF;gBACD,kDAAkD,EAAE,CAAC,OAAO,EAAE,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC;gBAC7F,mCAAmC,EAAE,OAAO;gBAC5C,gDAAgD,EAAE,OAAO;gBACzD,yCAAyC,EAAE;oBACzC,OAAO;oBACP,EAAE,oBAAoB,EAAE,IAAI,EAAE,2BAA2B,EAAE,IAAI,EAAE;iBAClE;aACF;SACF;KACF;CACF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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":"
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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,
|
|
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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AAG,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"}
|
|
@@ -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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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":";
|
|
1
|
+
{"version":3,"file":"no-self-import.js","sourceRoot":"","sources":["../../src/rules/no-self-import.ts"],"names":[],"mappings":";AACA,kCAAyF;AACzF,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,SAAS,IAAI,CAAC,IAAqE;YACjF,MAAM,MAAM,GAAG,IAAA,sBAAe,EAAC,IAAI,CAAC,CAAC;YACrC,IAAI,CAAC,MAAM,EAAE;gBACX,OAAO;aACR;YAED,IAAI,MAAM,CAAC,KAAK,KAAK,WAAW,IAAI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,GAAG,GAAG,CAAC,EAAE;gBAC9E,OAAO,CAAC,MAAM,CAAC;oBACb,SAAS,EAAE,mBAAmB;oBAC9B,IAAI;iBACL,CAAC,CAAC;aACJ;iBAAM,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,+BAA+B,CAAC,EAAE;gBAC9D,OAAO,CAAC,MAAM,CAAC;oBACb,SAAS,EAAE,uBAAuB;oBAClC,IAAI;iBACL,CAAC,CAAC;aACJ;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"}
|
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,IAAI,EAAE,EAAE,CACP,oGAAoG,IAAI,KAAK,CAChH,CAAC;AAEF,SAAgB,iCAAiC,CAAC,IAAY;;IAC5D,IAAI,CAA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BAAmB,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
package/src/configs/all.ts
CHANGED
|
@@ -174,6 +174,10 @@ export const all: Linter.BaseConfig = {
|
|
|
174
174
|
"@typescript-eslint/explicit-member-accessibility": ["error", { accessibility: "no-public" }],
|
|
175
175
|
"@typescript-eslint/no-misused-new": "error",
|
|
176
176
|
"@typescript-eslint/consistent-type-definitions": "error",
|
|
177
|
+
"@typescript-eslint/no-invalid-void-type": [
|
|
178
|
+
"error",
|
|
179
|
+
{ allowAsThisParameter: true, allowInGenericTypeArguments: true },
|
|
180
|
+
],
|
|
177
181
|
},
|
|
178
182
|
},
|
|
179
183
|
],
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
import { ESLint } from "eslint";
|
|
1
2
|
import { all } from "./configs/all";
|
|
2
|
-
|
|
3
|
+
import { rules } from "./rules/index";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
if (
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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 {
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
✖
|
|
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
|
-
✖
|
|
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.
|