eslint-plugin-import-path-correct 0.0.2 → 0.0.3
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.
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const path = require("path");
|
|
4
|
+
const { isPathRelative } = require("../helpers");
|
|
4
5
|
|
|
5
6
|
/** @type {import('eslint').Rule.RuleModule} */
|
|
6
7
|
module.exports = {
|
|
7
8
|
meta: {
|
|
8
|
-
type:
|
|
9
|
+
type: "problem", // `problem`, `suggestion`, or `layout`
|
|
9
10
|
docs: {
|
|
10
11
|
description: "feature sliced relative path",
|
|
11
12
|
recommended: false,
|
|
@@ -57,17 +58,13 @@ module.exports = {
|
|
|
57
58
|
};
|
|
58
59
|
|
|
59
60
|
const layers = {
|
|
60
|
-
|
|
61
|
+
entites: "entites",
|
|
61
62
|
features: "features",
|
|
62
63
|
shared: "shared",
|
|
63
64
|
pages: "pages",
|
|
64
65
|
widgets: "widgets",
|
|
65
66
|
};
|
|
66
67
|
|
|
67
|
-
function isPathRelative(path) {
|
|
68
|
-
return path === "." || path.startsWith("./") || path.startsWith("../");
|
|
69
|
-
}
|
|
70
|
-
|
|
71
68
|
function shouldBeRelative(from, to) {
|
|
72
69
|
if (isPathRelative(to)) {
|
|
73
70
|
return false;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { isPathRelative } = require("../helpers");
|
|
4
|
+
|
|
5
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
6
|
+
module.exports = {
|
|
7
|
+
meta: {
|
|
8
|
+
type: "problem", // `problem`, `suggestion`, or `layout`
|
|
9
|
+
docs: {
|
|
10
|
+
description: "description",
|
|
11
|
+
recommended: false,
|
|
12
|
+
url: null, // URL to the documentation page for this rule
|
|
13
|
+
},
|
|
14
|
+
fixable: null, // Or `code` or `whitespace`
|
|
15
|
+
schema: [
|
|
16
|
+
{
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: { alias: { type: "string", description: "some" } },
|
|
19
|
+
additionalProperties: false,
|
|
20
|
+
},
|
|
21
|
+
], // Add a schema if the rule has options
|
|
22
|
+
defaultOptions: [
|
|
23
|
+
{
|
|
24
|
+
// Add this property
|
|
25
|
+
alias: "", // Default value for alias
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
messages: {
|
|
29
|
+
publicApiRequired:
|
|
30
|
+
"Абсолютный импорт разрешен только из Publick API(index.ts)",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
create(context) {
|
|
35
|
+
const options = context.options[0] || {};
|
|
36
|
+
const alias = options.alias || "";
|
|
37
|
+
|
|
38
|
+
const checkingLayers = {
|
|
39
|
+
entites: "entites",
|
|
40
|
+
features: "features",
|
|
41
|
+
pages: "pages",
|
|
42
|
+
widgets: "widgets",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
ImportDeclaration(node) {
|
|
47
|
+
const value = node.source.value;
|
|
48
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
49
|
+
|
|
50
|
+
if (isPathRelative(importTo)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const segments = importTo.split("/");
|
|
55
|
+
|
|
56
|
+
const layer = segments[0];
|
|
57
|
+
if (!checkingLayers[layer]) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const isImportNotFromPublicApi = segments.length > 2;
|
|
62
|
+
|
|
63
|
+
if (isImportNotFromPublicApi) {
|
|
64
|
+
context.report({
|
|
65
|
+
node,
|
|
66
|
+
messageId: "publicApiRequired",
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
};
|