eslint-plugin-alexandr-plugin 0.0.3 → 0.0.4
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
|
|
|
5
6
|
module.exports = {
|
|
6
7
|
meta: {
|
|
@@ -52,10 +53,6 @@ const layers = {
|
|
|
52
53
|
'widgets': 'widgets',
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
function isPathRelative(path) {
|
|
56
|
-
return path === '.' || path.startsWith('./') || path.startsWith('../')
|
|
57
|
-
}
|
|
58
|
-
|
|
59
56
|
function shouldBeRelative(from, to) {
|
|
60
57
|
if (isPathRelative(to)) {
|
|
61
58
|
return false;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const {isPathRelative} = require('../helpers');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: null, // `problem`, `suggestion`, or `layout`
|
|
6
|
+
docs: {
|
|
7
|
+
description: "description",
|
|
8
|
+
recommended: false,
|
|
9
|
+
url: null, // URL to the documentation page for this rule
|
|
10
|
+
},
|
|
11
|
+
fixable: null, // Or `code` or `whitespace`
|
|
12
|
+
schema: [
|
|
13
|
+
{
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
alias: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
], // Add a schema if the rule has options
|
|
22
|
+
messages: {}, // Add messageId and message
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
create(context) {
|
|
26
|
+
const { alias = '', testFilesPatterns = [] } = context.options[0] ?? {};
|
|
27
|
+
|
|
28
|
+
const checkingLayers = {
|
|
29
|
+
'entities': 'entities',
|
|
30
|
+
'features': 'features',
|
|
31
|
+
'pages': 'pages',
|
|
32
|
+
'widgets': 'widgets',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
ImportDeclaration(node) {
|
|
37
|
+
const value = node.source.value
|
|
38
|
+
const importTo = alias ? value.replace(`${alias}/`, '') : value;
|
|
39
|
+
|
|
40
|
+
if(isPathRelative(importTo)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// [entities, article, model, types]
|
|
45
|
+
const segments = importTo.split('/')
|
|
46
|
+
const layer = segments[0];
|
|
47
|
+
|
|
48
|
+
if(!checkingLayers[layer]) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const isImportNotFromPublicApi = segments.length > 2;
|
|
53
|
+
|
|
54
|
+
if(isImportNotFromPublicApi) {
|
|
55
|
+
context.report(node, 'Абсолютный импорт разрешен только из Public API (index.ts)');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-alexandr-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "plugin for production 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",
|