eslint-plugin-zozu-plugin 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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const path = require('path');
|
|
4
|
+
const {isPathRelative} = require('../helpers');
|
|
4
5
|
module.exports = {
|
|
5
6
|
meta: {
|
|
6
7
|
type: null,
|
|
@@ -42,10 +43,6 @@ module.exports = {
|
|
|
42
43
|
},
|
|
43
44
|
};
|
|
44
45
|
|
|
45
|
-
function isPathRelative(path) {
|
|
46
|
-
return path === '.' || path.startsWith('./') || path.startsWith('../')
|
|
47
|
-
}
|
|
48
|
-
|
|
49
46
|
const layers = {
|
|
50
47
|
'entities': 'entities',
|
|
51
48
|
'features': 'features',
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {isPathRelative} = require('../helpers');
|
|
4
|
+
const micromatch = require("micromatch");
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
meta: {
|
|
8
|
+
type: null, // `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: {
|
|
19
|
+
alias: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
},
|
|
22
|
+
testFilesPatterns: {
|
|
23
|
+
type: 'array',
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
messages: {}, // Add messageId and message
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
create(context) {
|
|
32
|
+
const {alias = '', testFilesPatterns = []} = context.options[0] ?? {};
|
|
33
|
+
|
|
34
|
+
const checkingLayers = {
|
|
35
|
+
'entities': 'entities',
|
|
36
|
+
'features': 'features',
|
|
37
|
+
'pages': 'pages',
|
|
38
|
+
'widgets': 'widgets',
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
ImportDeclaration(node) {
|
|
43
|
+
// example app/entities/Article
|
|
44
|
+
const value = node.source.value;
|
|
45
|
+
const importTo = alias ? value.replace(`${alias}/`, '') : value;
|
|
46
|
+
|
|
47
|
+
if (isPathRelative(importTo)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// [entities, article, model, types]
|
|
52
|
+
const segments = importTo.split('/');
|
|
53
|
+
|
|
54
|
+
const layer = segments[0];
|
|
55
|
+
|
|
56
|
+
if(!checkingLayers[layer]) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const isImportNotFromPublicApi = segments.length > 2;
|
|
60
|
+
|
|
61
|
+
const isTestingPublicApi = segments[2] === 'testing' && segments.length < 4;
|
|
62
|
+
|
|
63
|
+
if (isImportNotFromPublicApi && !isTestingPublicApi) {
|
|
64
|
+
context.report({node: node, message: 'Абсолютный импорт разрешен только из Public API (index.ts)'});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (isTestingPublicApi) {
|
|
68
|
+
const currentFilePath = context.getFilename();
|
|
69
|
+
const isCurrentFileTesting = testFilesPatterns.some(
|
|
70
|
+
pattern => micromatch.isMatch(currentFilePath, pattern)
|
|
71
|
+
)
|
|
72
|
+
if (!isCurrentFileTesting) {
|
|
73
|
+
context.report({node: node, message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-zozu-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "plugin for my pet project",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -21,11 +21,12 @@
|
|
|
21
21
|
"update:eslint-docs": "eslint-doc-generator"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"micromatch": "^4.0.8",
|
|
24
25
|
"requireindex": "^1.2.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"eslint": "^9.0.0",
|
|
28
28
|
"@eslint/js": "^9.0.0",
|
|
29
|
+
"eslint": "^9.0.0",
|
|
29
30
|
"eslint-doc-generator": "^2.0.0",
|
|
30
31
|
"eslint-plugin-eslint-plugin": "^6.0.0",
|
|
31
32
|
"eslint-plugin-n": "^17.0.0",
|