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