eslint-plugin-big-react-app-plugin 0.0.8 → 0.1.1
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/.history/.gitignore_20251018083109 +0 -0
- package/.history/.gitignore_20251018083124 +1 -0
- package/.history/lib/helpers/index_20251018083334.js +0 -0
- package/.history/lib/helpers/index_20251018083357.js +6 -0
- package/.history/lib/helpers/index_20251018083414.js +6 -0
- package/.history/lib/helpers/index_20251018083417.js +6 -0
- package/.history/lib/helpers/index_20251018083618.js +6 -0
- package/.history/lib/rules/path-checker_20251018083151.js +89 -0
- package/.history/lib/rules/path-checker_20251018083710.js +87 -0
- package/.history/lib/rules/public-api-imports_20251018083042.js +44 -0
- package/.history/lib/rules/public-api-imports_20251018083211.js +50 -0
- package/.history/lib/rules/public-api-imports_20251018083235.js +43 -0
- package/.history/lib/rules/public-api-imports_20251018083244.js +51 -0
- package/.history/lib/rules/public-api-imports_20251018083454.js +51 -0
- package/.history/lib/rules/public-api-imports_20251018083640.js +40 -0
- package/.history/lib/rules/public-api-imports_20251018083748.js +42 -0
- package/.history/lib/rules/public-api-imports_20251018083818.js +42 -0
- package/.history/lib/rules/public-api-imports_20251018084540.js +41 -0
- package/.history/lib/rules/public-api-imports_20251018084843.js +44 -0
- package/.history/lib/rules/public-api-imports_20251018084847.js +44 -0
- package/.history/lib/rules/public-api-imports_20251018084906.js +44 -0
- package/.history/lib/rules/public-api-imports_20251018084913.js +43 -0
- package/.history/lib/rules/public-api-imports_20251018085014.js +48 -0
- package/.history/lib/rules/public-api-imports_20251018085807.js +48 -0
- package/.history/lib/rules/public-api-imports_20251018090400.js +58 -0
- package/.history/package_20251018085916.json +32 -0
- package/.history/package_20251018090415.json +32 -0
- package/.history/tests/lib/rules/public-api-imports_20251018083042.js +31 -0
- package/.history/tests/lib/rules/public-api-imports_20251018085128.js +34 -0
- package/.history/tests/lib/rules/public-api-imports_20251018085249.js +34 -0
- package/.history/tests/lib/rules/public-api-imports_20251018085350.js +40 -0
- package/.history/tests/lib/rules/public-api-imports_20251018085726.js +36 -0
- package/docs/rules/public-api-imports.md +35 -0
- package/lib/helpers/index.js +6 -0
- package/lib/rules/path-checker.js +3 -5
- package/lib/rules/public-api-imports.js +58 -0
- package/package.json +1 -1
- package/tests/lib/rules/public-api-imports.js +36 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const {isPathRelative} = require("../helpers")
|
|
3
|
+
module.exports = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: null,
|
|
6
|
+
docs: {
|
|
7
|
+
description: "description",
|
|
8
|
+
category: "Fill me in",
|
|
9
|
+
recommended: false,
|
|
10
|
+
url: null,
|
|
11
|
+
},
|
|
12
|
+
fixable: null,
|
|
13
|
+
schema: [],
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
create(context) {
|
|
18
|
+
const layers = {
|
|
19
|
+
"entities":"entities",
|
|
20
|
+
"features":"features",
|
|
21
|
+
"pages":"pages",
|
|
22
|
+
"shared":"shared",
|
|
23
|
+
"widgets":"widgets",
|
|
24
|
+
}
|
|
25
|
+
const alias = context.options[0]?.alias ?? "";
|
|
26
|
+
return {
|
|
27
|
+
ImportDeclaration(node) {
|
|
28
|
+
// example app/entities/Article
|
|
29
|
+
const value = node.source.value;
|
|
30
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
31
|
+
if(isPathRelative(importTo)){
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const segments = importTo.split('/')
|
|
35
|
+
//[enteties, article, ... далее еще что-то может быть]
|
|
36
|
+
const isImportNotFromPublicApi = segments.lenght > 2;
|
|
37
|
+
|
|
38
|
+
if(isImportNotFromPublicApi) {
|
|
39
|
+
context.report({node: node, message: 'Абсолютный импорт разрешен только из Public Api(index.ts)'});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const {isPathRelative} = require("../helpers")
|
|
3
|
+
module.exports = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: null,
|
|
6
|
+
docs: {
|
|
7
|
+
description: "description",
|
|
8
|
+
category: "Fill me in",
|
|
9
|
+
recommended: false,
|
|
10
|
+
url: null,
|
|
11
|
+
},
|
|
12
|
+
fixable: null,
|
|
13
|
+
schema: [],
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
create(context) {
|
|
18
|
+
const checkingLayers = {
|
|
19
|
+
"entities":"entities",
|
|
20
|
+
"features":"features",
|
|
21
|
+
"pages":"pages",
|
|
22
|
+
"shared":"shared",
|
|
23
|
+
"widgets":"widgets",
|
|
24
|
+
}
|
|
25
|
+
const alias = context.options[0]?.alias ?? "";
|
|
26
|
+
return {
|
|
27
|
+
ImportDeclaration(node) {
|
|
28
|
+
// example app/entities/Article
|
|
29
|
+
const value = node.source.value;
|
|
30
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
31
|
+
if(isPathRelative(importTo)){
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const segments = importTo.split('/')
|
|
35
|
+
//[enteties, article, ... далее еще что-то может быть]
|
|
36
|
+
const isImportNotFromPublicApi = segments.lenght > 2;
|
|
37
|
+
|
|
38
|
+
if(isImportNotFromPublicApi) {
|
|
39
|
+
context.report({node: node, message: 'Абсолютный импорт разрешен только из Public Api(index.ts)'});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const {isPathRelative} = require("../helpers")
|
|
3
|
+
module.exports = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: null,
|
|
6
|
+
docs: {
|
|
7
|
+
description: "description",
|
|
8
|
+
category: "Fill me in",
|
|
9
|
+
recommended: false,
|
|
10
|
+
url: null,
|
|
11
|
+
},
|
|
12
|
+
fixable: null,
|
|
13
|
+
schema: [],
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
create(context) {
|
|
18
|
+
const checkingLayers = {
|
|
19
|
+
"entities":"entities",
|
|
20
|
+
"features":"features",
|
|
21
|
+
"pages":"pages",
|
|
22
|
+
"widgets":"widgets",
|
|
23
|
+
}
|
|
24
|
+
const alias = context.options[0]?.alias ?? "";
|
|
25
|
+
return {
|
|
26
|
+
ImportDeclaration(node) {
|
|
27
|
+
// example app/entities/Article
|
|
28
|
+
const value = node.source.value;
|
|
29
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
30
|
+
if(isPathRelative(importTo)){
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const segments = importTo.split('/')
|
|
34
|
+
//[enteties, article, ... далее еще что-то может быть]
|
|
35
|
+
const isImportNotFromPublicApi = segments.lenght > 2;
|
|
36
|
+
|
|
37
|
+
if(isImportNotFromPublicApi) {
|
|
38
|
+
context.report({node: node, message: 'Абсолютный импорт разрешен только из Public Api(index.ts)'});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const {isPathRelative} = require("../helpers")
|
|
3
|
+
module.exports = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: null,
|
|
6
|
+
docs: {
|
|
7
|
+
description: "description",
|
|
8
|
+
category: "Fill me in",
|
|
9
|
+
recommended: false,
|
|
10
|
+
url: null,
|
|
11
|
+
},
|
|
12
|
+
fixable: null,
|
|
13
|
+
schema: [],
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
create(context) {
|
|
18
|
+
const checkingLayers = {
|
|
19
|
+
"entities":"entities",
|
|
20
|
+
"features":"features",
|
|
21
|
+
"pages":"pages",
|
|
22
|
+
"widgets":"widgets",
|
|
23
|
+
}
|
|
24
|
+
const alias = context.options[0]?.alias ?? "";
|
|
25
|
+
return {
|
|
26
|
+
ImportDeclaration(node) {
|
|
27
|
+
// example app/entities/Article
|
|
28
|
+
const value = node.source.value;
|
|
29
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
30
|
+
if(isPathRelative(importTo)){
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
//[enteties, article, ... далее еще что-то может быть]
|
|
34
|
+
const segments = importTo.split('/')
|
|
35
|
+
const layer = segments[0]//получаем слой
|
|
36
|
+
if(!checkingLayers[layer]){
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const isImportNotFromPublicApi = segments.lenght > 2;
|
|
41
|
+
|
|
42
|
+
if(isImportNotFromPublicApi) {
|
|
43
|
+
context.report({node: node, message: 'Абсолютный импорт разрешен только из Public Api(index.ts)'});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const {isPathRelative} = require("../helpers")
|
|
3
|
+
module.exports = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: null,
|
|
6
|
+
docs: {
|
|
7
|
+
description: "description",
|
|
8
|
+
category: "Fill me in",
|
|
9
|
+
recommended: false,
|
|
10
|
+
url: null,
|
|
11
|
+
},
|
|
12
|
+
fixable: null,
|
|
13
|
+
schema: [],
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
create(context) {
|
|
18
|
+
const checkingLayers = {
|
|
19
|
+
"entities":"entities",
|
|
20
|
+
"features":"features",
|
|
21
|
+
"pages":"pages",
|
|
22
|
+
"widgets":"widgets",
|
|
23
|
+
}
|
|
24
|
+
const alias = context.options[0]?.alias ?? "";
|
|
25
|
+
return {
|
|
26
|
+
ImportDeclaration(node) {
|
|
27
|
+
// example app/entities/Article
|
|
28
|
+
const value = node.source.value;
|
|
29
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
30
|
+
if(isPathRelative(importTo)){
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
//[enteties, article, ... далее еще что-то может быть]
|
|
34
|
+
const segments = importTo.split('/')
|
|
35
|
+
const layer = segments[0]//получаем слой
|
|
36
|
+
if(!checkingLayers[layer]){
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const isImportNotFromPublicApi = segments.lenght > 2;
|
|
41
|
+
|
|
42
|
+
if(isImportNotFromPublicApi) {
|
|
43
|
+
context.report({node: node, message: 'Абсолютный импорт разрешен только из Public Api(index.ts)'});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const {isPathRelative} = require("../helpers")
|
|
3
|
+
module.exports = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: null,
|
|
6
|
+
docs: {
|
|
7
|
+
description: "description",
|
|
8
|
+
category: "Fill me in",
|
|
9
|
+
recommended: false,
|
|
10
|
+
url: null,
|
|
11
|
+
},
|
|
12
|
+
fixable: null,
|
|
13
|
+
schema: [
|
|
14
|
+
{
|
|
15
|
+
type:"object",
|
|
16
|
+
properties:
|
|
17
|
+
{
|
|
18
|
+
alias:{
|
|
19
|
+
type: 'string'
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
create(context) {
|
|
28
|
+
const checkingLayers = {
|
|
29
|
+
"entities":"entities",
|
|
30
|
+
"features":"features",
|
|
31
|
+
"pages":"pages",
|
|
32
|
+
"widgets":"widgets",
|
|
33
|
+
}
|
|
34
|
+
const alias = context.options[0]?.alias ?? "";
|
|
35
|
+
return {
|
|
36
|
+
ImportDeclaration(node) {
|
|
37
|
+
// example app/entities/Article
|
|
38
|
+
const value = node.source.value;
|
|
39
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
40
|
+
if(isPathRelative(importTo)){
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
//[enteties, article, ... далее еще что-то может быть]
|
|
44
|
+
const segments = importTo.split('/')
|
|
45
|
+
const layer = segments[0]//получаем слой
|
|
46
|
+
if(!checkingLayers[layer]){
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const isImportNotFromPublicApi = segments.lenght > 2;
|
|
51
|
+
|
|
52
|
+
if(isImportNotFromPublicApi) {
|
|
53
|
+
context.report({node: node, message: 'Абсолютный импорт разрешен только из Public Api(index.ts)'});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-plugin-big-react-app-plugin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "plugin for prod proj",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"eslint",
|
|
7
|
+
"eslintplugin",
|
|
8
|
+
"eslint-plugin"
|
|
9
|
+
],
|
|
10
|
+
"author": "Vasilii",
|
|
11
|
+
"main": "lib/index.js",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"lint": "eslint .",
|
|
14
|
+
"test": "mocha tests --recursive"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"requireindex": "^1.2.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"eslint": "^8.0.1",
|
|
21
|
+
"eslint-plugin-eslint-plugin": "^4.0.1",
|
|
22
|
+
"eslint-plugin-node": "^11.1.0",
|
|
23
|
+
"mocha": "^9.1.3"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": "12.x || 14.x || >= 16"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"eslint": ">=6"
|
|
30
|
+
},
|
|
31
|
+
"license": "ISC"
|
|
32
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-plugin-big-react-app-plugin",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "plugin for prod proj",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"eslint",
|
|
7
|
+
"eslintplugin",
|
|
8
|
+
"eslint-plugin"
|
|
9
|
+
],
|
|
10
|
+
"author": "Vasilii",
|
|
11
|
+
"main": "lib/index.js",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"lint": "eslint .",
|
|
14
|
+
"test": "mocha tests --recursive"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"requireindex": "^1.2.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"eslint": "^8.0.1",
|
|
21
|
+
"eslint-plugin-eslint-plugin": "^4.0.1",
|
|
22
|
+
"eslint-plugin-node": "^11.1.0",
|
|
23
|
+
"mocha": "^9.1.3"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": "12.x || 14.x || >= 16"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"eslint": ">=6"
|
|
30
|
+
},
|
|
31
|
+
"license": "ISC"
|
|
32
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview description
|
|
3
|
+
* @author vasilii
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Requirements
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const rule = require("../../../lib/rules/public-api-imports"),
|
|
12
|
+
RuleTester = require("eslint").RuleTester;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
//------------------------------------------------------------------------------
|
|
16
|
+
// Tests
|
|
17
|
+
//------------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
const ruleTester = new RuleTester();
|
|
20
|
+
ruleTester.run("public-api-imports", rule, {
|
|
21
|
+
valid: [
|
|
22
|
+
// give me some code that won't trigger a warning
|
|
23
|
+
],
|
|
24
|
+
|
|
25
|
+
invalid: [
|
|
26
|
+
{
|
|
27
|
+
code: "",
|
|
28
|
+
errors: [{ message: "Fill me in.", type: "Me too" }],
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview description
|
|
3
|
+
* @author vasilii
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Requirements
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const rule = require("../../../lib/rules/public-api-imports"),
|
|
12
|
+
RuleTester = require("eslint").RuleTester;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
//------------------------------------------------------------------------------
|
|
16
|
+
// Tests
|
|
17
|
+
//------------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
const ruleTester = new RuleTester({
|
|
20
|
+
parserOptions:{ecmaVersion:6, sourceType:'module'}
|
|
21
|
+
});
|
|
22
|
+
ruleTester.run("public-api-imports", rule, {
|
|
23
|
+
|
|
24
|
+
valid: [
|
|
25
|
+
// give me some code that won't trigger a warning
|
|
26
|
+
],
|
|
27
|
+
|
|
28
|
+
invalid: [
|
|
29
|
+
{
|
|
30
|
+
code: "",
|
|
31
|
+
errors: [{ message: "Fill me in.", type: "Me too" }],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview public API path checker
|
|
3
|
+
* @author vasilii
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Requirements
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const rule = require("../../../lib/rules/public-api-imports"),
|
|
12
|
+
RuleTester = require("eslint").RuleTester;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
//------------------------------------------------------------------------------
|
|
16
|
+
// Tests
|
|
17
|
+
//------------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
const ruleTester = new RuleTester({
|
|
20
|
+
parserOptions:{ecmaVersion:6, sourceType:'module'}
|
|
21
|
+
});
|
|
22
|
+
ruleTester.run("public-api-imports", rule, {
|
|
23
|
+
|
|
24
|
+
valid: [
|
|
25
|
+
|
|
26
|
+
],
|
|
27
|
+
|
|
28
|
+
invalid: [
|
|
29
|
+
{
|
|
30
|
+
code: "",
|
|
31
|
+
errors: [{ message: "Fill me in.", type: "Me too" }],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview public API path checker
|
|
3
|
+
* @author vasilii
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Requirements
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const rule = require("../../../lib/rules/public-api-imports"),
|
|
12
|
+
RuleTester = require("eslint").RuleTester;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
//------------------------------------------------------------------------------
|
|
16
|
+
// Tests
|
|
17
|
+
//------------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
const ruleTester = new RuleTester({
|
|
20
|
+
parserOptions:{ecmaVersion:6, sourceType:'module'}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const aliasOptions = [
|
|
24
|
+
{
|
|
25
|
+
alias:'@'
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
ruleTester.run("public-api-imports", rule, {
|
|
29
|
+
|
|
30
|
+
valid: [
|
|
31
|
+
|
|
32
|
+
],
|
|
33
|
+
|
|
34
|
+
invalid: [
|
|
35
|
+
{
|
|
36
|
+
code: "",
|
|
37
|
+
errors: [{ message: "Fill me in.", type: "Me too" }],
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview public API path checker
|
|
3
|
+
* @author vasilii
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Requirements
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const rule = require("../../../lib/rules/public-api-imports"),
|
|
12
|
+
RuleTester = require("eslint").RuleTester;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
//------------------------------------------------------------------------------
|
|
16
|
+
// Tests
|
|
17
|
+
//------------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
const ruleTester = new RuleTester({
|
|
20
|
+
parserOptions:{ecmaVersion:6, sourceType:'module'}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
ruleTester.run("public-api-imports", rule, {
|
|
25
|
+
|
|
26
|
+
valid: [
|
|
27
|
+
|
|
28
|
+
],
|
|
29
|
+
|
|
30
|
+
invalid: [
|
|
31
|
+
{
|
|
32
|
+
code: "",
|
|
33
|
+
errors: [{ message: "Fill me in.", type: "Me too" }],
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# description (public-api-imports)
|
|
2
|
+
|
|
3
|
+
Please describe the origin of the rule here.
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
This rule aims to...
|
|
8
|
+
|
|
9
|
+
Examples of **incorrect** code for this rule:
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
|
|
13
|
+
// fill me in
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Examples of **correct** code for this rule:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
|
|
21
|
+
// fill me in
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Options
|
|
26
|
+
|
|
27
|
+
If there are any options, describe them here. Otherwise, delete this section.
|
|
28
|
+
|
|
29
|
+
## When Not To Use It
|
|
30
|
+
|
|
31
|
+
Give a short description of when it would be appropriate to turn off this rule.
|
|
32
|
+
|
|
33
|
+
## Further Reading
|
|
34
|
+
|
|
35
|
+
If there are other links that describe the issue this rule addresses, please include them here in a bulleted list.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { type } = require('os');
|
|
4
4
|
const path = require('path');
|
|
5
|
-
|
|
5
|
+
const {isPathRelative} = require("../helpers")
|
|
6
6
|
module.exports = {
|
|
7
7
|
meta: {
|
|
8
8
|
type: null,
|
|
@@ -52,7 +52,7 @@ const layers = {
|
|
|
52
52
|
"widgets":"widgets",
|
|
53
53
|
}
|
|
54
54
|
const shouldBeRelative = (from, to)=>{
|
|
55
|
-
if(
|
|
55
|
+
if(isPathRelative(to)){
|
|
56
56
|
return false
|
|
57
57
|
}
|
|
58
58
|
const toArray = to.split('/')
|
|
@@ -76,9 +76,7 @@ const shouldBeRelative = (from, to)=>{
|
|
|
76
76
|
|
|
77
77
|
return toSlice === fromSlice && toLayer === fromLayer
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
return path = path.startsWith('.' || './' || './/')
|
|
81
|
-
}
|
|
79
|
+
|
|
82
80
|
|
|
83
81
|
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/Article/fasfasfas'))
|
|
84
82
|
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/ASdasd/fasfasfas'))
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const {isPathRelative} = require("../helpers")
|
|
3
|
+
module.exports = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: null,
|
|
6
|
+
docs: {
|
|
7
|
+
description: "description",
|
|
8
|
+
category: "Fill me in",
|
|
9
|
+
recommended: false,
|
|
10
|
+
url: null,
|
|
11
|
+
},
|
|
12
|
+
fixable: null,
|
|
13
|
+
schema: [
|
|
14
|
+
{
|
|
15
|
+
type:"object",
|
|
16
|
+
properties:
|
|
17
|
+
{
|
|
18
|
+
alias:{
|
|
19
|
+
type: 'string'
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
create(context) {
|
|
28
|
+
const checkingLayers = {
|
|
29
|
+
"entities":"entities",
|
|
30
|
+
"features":"features",
|
|
31
|
+
"pages":"pages",
|
|
32
|
+
"widgets":"widgets",
|
|
33
|
+
}
|
|
34
|
+
const alias = context.options[0]?.alias ?? "";
|
|
35
|
+
return {
|
|
36
|
+
ImportDeclaration(node) {
|
|
37
|
+
// example app/entities/Article
|
|
38
|
+
const value = node.source.value;
|
|
39
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
40
|
+
if(isPathRelative(importTo)){
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
//[enteties, article, ... далее еще что-то может быть]
|
|
44
|
+
const segments = importTo.split('/')
|
|
45
|
+
const layer = segments[0]//получаем слой
|
|
46
|
+
if(!checkingLayers[layer]){
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const isImportNotFromPublicApi = segments.lenght > 2;
|
|
51
|
+
|
|
52
|
+
if(isImportNotFromPublicApi) {
|
|
53
|
+
context.report({node: node, message: 'Абсолютный импорт разрешен только из Public Api(index.ts)'});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
};
|