eslint-plugin-big-react-app-plugin 0.0.8 → 0.1.0
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/package_20251018085916.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 +48 -0
- package/package.json +1 -1
- package/tests/lib/rules/public-api-imports.js +36 -0
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.history
|
|
File without changes
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { type } = require('os');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
meta: {
|
|
8
|
+
type: null,
|
|
9
|
+
docs: {
|
|
10
|
+
description: "feature sliced relative path checker",
|
|
11
|
+
category: "Fill me in",
|
|
12
|
+
recommended: false,
|
|
13
|
+
url: null,
|
|
14
|
+
},
|
|
15
|
+
fixable: null,
|
|
16
|
+
schema: [
|
|
17
|
+
{
|
|
18
|
+
type:"object",
|
|
19
|
+
properties:
|
|
20
|
+
{
|
|
21
|
+
alias:{
|
|
22
|
+
type: 'string'
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
create(context) {
|
|
30
|
+
const alias = context.options[0]?.alias ?? "";
|
|
31
|
+
return {
|
|
32
|
+
ImportDeclaration(node) {
|
|
33
|
+
// example app/entities/Article
|
|
34
|
+
const value = node.source.value;
|
|
35
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
36
|
+
|
|
37
|
+
// example C:\Users\tim\Desktop\javascript\production_project\src\entities\Article
|
|
38
|
+
const fromFilename = context.getFilename();
|
|
39
|
+
if(shouldBeRelative(fromFilename, importTo)) {
|
|
40
|
+
context.report({node: node, message: 'В рамках одного слайса все пути должны быть относительными'});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const layers = {
|
|
48
|
+
"entities":"entities",
|
|
49
|
+
"features":"features",
|
|
50
|
+
"pages":"pages",
|
|
51
|
+
"shared":"shared",
|
|
52
|
+
"widgets":"widgets",
|
|
53
|
+
}
|
|
54
|
+
const shouldBeRelative = (from, to)=>{
|
|
55
|
+
if(pathRelative(to)){
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
const toArray = to.split('/')
|
|
59
|
+
//app/entities/Article
|
|
60
|
+
const toLayer = toArray[0];
|
|
61
|
+
//"C:\Users\ADMIN\Documents\GitHub\ulbi\big-app-react\src\entities\Article\model\types\artcile.ts"
|
|
62
|
+
const toSlice = toArray[1];
|
|
63
|
+
if(!toLayer || !toSlice || !layers[toLayer]){
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
//нормализуем путь
|
|
67
|
+
const normalizationPath = path.toNamespacedPath(from);
|
|
68
|
+
const projFrom = normalizationPath.split('src')[1]
|
|
69
|
+
const fromArray = projFrom.split('\\')
|
|
70
|
+
|
|
71
|
+
const fromLayer = fromArray[1];
|
|
72
|
+
const fromSlice = fromArray[2];
|
|
73
|
+
if(!fromLayer || !fromSlice || !layers[fromLayer]){
|
|
74
|
+
return false
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return toSlice === fromSlice && toLayer === fromLayer
|
|
78
|
+
}
|
|
79
|
+
const pathRelative = (path)=>{
|
|
80
|
+
return path = path.startsWith('.' || './' || './/')
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/Article/fasfasfas'))
|
|
84
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/ASdasd/fasfasfas'))
|
|
85
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'features/Article/fasfasfas'))
|
|
86
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\features\\Article', 'features/Article/fasfasfas'))
|
|
87
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'app/index.tsx'))
|
|
88
|
+
// console.log(shouldBeRelative('C:/Users/tim/Desktop/javascript/GOOD_COURSE_test/src/entities/Article', 'entities/Article/asfasf/asfasf'))
|
|
89
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', '../../model/selectors/getSidebarItems'))
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { type } = require('os');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const {isPathRelative} = require("../helpers")
|
|
6
|
+
module.exports = {
|
|
7
|
+
meta: {
|
|
8
|
+
type: null,
|
|
9
|
+
docs: {
|
|
10
|
+
description: "feature sliced relative path checker",
|
|
11
|
+
category: "Fill me in",
|
|
12
|
+
recommended: false,
|
|
13
|
+
url: null,
|
|
14
|
+
},
|
|
15
|
+
fixable: null,
|
|
16
|
+
schema: [
|
|
17
|
+
{
|
|
18
|
+
type:"object",
|
|
19
|
+
properties:
|
|
20
|
+
{
|
|
21
|
+
alias:{
|
|
22
|
+
type: 'string'
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
create(context) {
|
|
30
|
+
const alias = context.options[0]?.alias ?? "";
|
|
31
|
+
return {
|
|
32
|
+
ImportDeclaration(node) {
|
|
33
|
+
// example app/entities/Article
|
|
34
|
+
const value = node.source.value;
|
|
35
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
36
|
+
|
|
37
|
+
// example C:\Users\tim\Desktop\javascript\production_project\src\entities\Article
|
|
38
|
+
const fromFilename = context.getFilename();
|
|
39
|
+
if(shouldBeRelative(fromFilename, importTo)) {
|
|
40
|
+
context.report({node: node, message: 'В рамках одного слайса все пути должны быть относительными'});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const layers = {
|
|
48
|
+
"entities":"entities",
|
|
49
|
+
"features":"features",
|
|
50
|
+
"pages":"pages",
|
|
51
|
+
"shared":"shared",
|
|
52
|
+
"widgets":"widgets",
|
|
53
|
+
}
|
|
54
|
+
const shouldBeRelative = (from, to)=>{
|
|
55
|
+
if(isPathRelative(to)){
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
const toArray = to.split('/')
|
|
59
|
+
//app/entities/Article
|
|
60
|
+
const toLayer = toArray[0];
|
|
61
|
+
//"C:\Users\ADMIN\Documents\GitHub\ulbi\big-app-react\src\entities\Article\model\types\artcile.ts"
|
|
62
|
+
const toSlice = toArray[1];
|
|
63
|
+
if(!toLayer || !toSlice || !layers[toLayer]){
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
//нормализуем путь
|
|
67
|
+
const normalizationPath = path.toNamespacedPath(from);
|
|
68
|
+
const projFrom = normalizationPath.split('src')[1]
|
|
69
|
+
const fromArray = projFrom.split('\\')
|
|
70
|
+
|
|
71
|
+
const fromLayer = fromArray[1];
|
|
72
|
+
const fromSlice = fromArray[2];
|
|
73
|
+
if(!fromLayer || !fromSlice || !layers[fromLayer]){
|
|
74
|
+
return false
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return toSlice === fromSlice && toLayer === fromLayer
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/Article/fasfasfas'))
|
|
82
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/ASdasd/fasfasfas'))
|
|
83
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'features/Article/fasfasfas'))
|
|
84
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\features\\Article', 'features/Article/fasfasfas'))
|
|
85
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'app/index.tsx'))
|
|
86
|
+
// console.log(shouldBeRelative('C:/Users/tim/Desktop/javascript/GOOD_COURSE_test/src/entities/Article', 'entities/Article/asfasf/asfasf'))
|
|
87
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', '../../model/selectors/getSidebarItems'))
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview description
|
|
3
|
+
* @author vasilii
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Rule Definition
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @type {import('eslint').Rule.RuleModule}
|
|
13
|
+
*/
|
|
14
|
+
module.exports = {
|
|
15
|
+
meta: {
|
|
16
|
+
type: null, // `problem`, `suggestion`, or `layout`
|
|
17
|
+
docs: {
|
|
18
|
+
description: "description",
|
|
19
|
+
category: "Fill me in",
|
|
20
|
+
recommended: false,
|
|
21
|
+
url: null, // URL to the documentation page for this rule
|
|
22
|
+
},
|
|
23
|
+
fixable: null, // Or `code` or `whitespace`
|
|
24
|
+
schema: [], // Add a schema if the rule has options
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
create(context) {
|
|
28
|
+
// variables should be defined here
|
|
29
|
+
|
|
30
|
+
//----------------------------------------------------------------------
|
|
31
|
+
// Helpers
|
|
32
|
+
//----------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
// any helper functions should go here or else delete this section
|
|
35
|
+
|
|
36
|
+
//----------------------------------------------------------------------
|
|
37
|
+
// Public
|
|
38
|
+
//----------------------------------------------------------------------
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
// visitor functions for different types of nodes
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview description
|
|
3
|
+
* @author vasilii
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Rule Definition
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @type {import('eslint').Rule.RuleModule}
|
|
13
|
+
*/
|
|
14
|
+
module.exports = {
|
|
15
|
+
meta: {
|
|
16
|
+
type: null, // `problem`, `suggestion`, or `layout`
|
|
17
|
+
docs: {
|
|
18
|
+
description: "description",
|
|
19
|
+
category: "Fill me in",
|
|
20
|
+
recommended: false,
|
|
21
|
+
url: null, // URL to the documentation page for this rule
|
|
22
|
+
},
|
|
23
|
+
fixable: null, // Or `code` or `whitespace`
|
|
24
|
+
schema: [], // Add a schema if the rule has options
|
|
25
|
+
},
|
|
26
|
+
const layers = {
|
|
27
|
+
"entities":"entities",
|
|
28
|
+
"features":"features",
|
|
29
|
+
"pages":"pages",
|
|
30
|
+
"shared":"shared",
|
|
31
|
+
"widgets":"widgets",
|
|
32
|
+
}
|
|
33
|
+
create(context) {
|
|
34
|
+
// variables should be defined here
|
|
35
|
+
|
|
36
|
+
//----------------------------------------------------------------------
|
|
37
|
+
// Helpers
|
|
38
|
+
//----------------------------------------------------------------------
|
|
39
|
+
|
|
40
|
+
// any helper functions should go here or else delete this section
|
|
41
|
+
|
|
42
|
+
//----------------------------------------------------------------------
|
|
43
|
+
// Public
|
|
44
|
+
//----------------------------------------------------------------------
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
// visitor functions for different types of nodes
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview description
|
|
3
|
+
* @author vasilii
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Rule Definition
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @type {import('eslint').Rule.RuleModule}
|
|
13
|
+
*/
|
|
14
|
+
module.exports = {
|
|
15
|
+
meta: {
|
|
16
|
+
type: null, // `problem`, `suggestion`, or `layout`
|
|
17
|
+
docs: {
|
|
18
|
+
description: "description",
|
|
19
|
+
category: "Fill me in",
|
|
20
|
+
recommended: false,
|
|
21
|
+
url: null, // URL to the documentation page for this rule
|
|
22
|
+
},
|
|
23
|
+
fixable: null, // Or `code` or `whitespace`
|
|
24
|
+
schema: [], // Add a schema if the rule has options
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
create(context) {
|
|
28
|
+
const alias = context.options[0]?.alias ?? "";
|
|
29
|
+
return {
|
|
30
|
+
ImportDeclaration(node) {
|
|
31
|
+
// example app/entities/Article
|
|
32
|
+
const value = node.source.value;
|
|
33
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
34
|
+
|
|
35
|
+
// example C:\Users\tim\Desktop\javascript\production_project\src\entities\Article
|
|
36
|
+
const fromFilename = context.getFilename();
|
|
37
|
+
if(shouldBeRelative(fromFilename, importTo)) {
|
|
38
|
+
context.report({node: node, message: 'В рамках одного слайса все пути должны быть относительными'});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview description
|
|
3
|
+
* @author vasilii
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Rule Definition
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @type {import('eslint').Rule.RuleModule}
|
|
13
|
+
*/
|
|
14
|
+
module.exports = {
|
|
15
|
+
meta: {
|
|
16
|
+
type: null, // `problem`, `suggestion`, or `layout`
|
|
17
|
+
docs: {
|
|
18
|
+
description: "description",
|
|
19
|
+
category: "Fill me in",
|
|
20
|
+
recommended: false,
|
|
21
|
+
url: null, // URL to the documentation page for this rule
|
|
22
|
+
},
|
|
23
|
+
fixable: null, // Or `code` or `whitespace`
|
|
24
|
+
schema: [], // Add a schema if the rule has options
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
create(context) {
|
|
29
|
+
const layers = {
|
|
30
|
+
"entities":"entities",
|
|
31
|
+
"features":"features",
|
|
32
|
+
"pages":"pages",
|
|
33
|
+
"shared":"shared",
|
|
34
|
+
"widgets":"widgets",
|
|
35
|
+
}
|
|
36
|
+
const alias = context.options[0]?.alias ?? "";
|
|
37
|
+
return {
|
|
38
|
+
ImportDeclaration(node) {
|
|
39
|
+
// example app/entities/Article
|
|
40
|
+
const value = node.source.value;
|
|
41
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
42
|
+
|
|
43
|
+
// example C:\Users\tim\Desktop\javascript\production_project\src\entities\Article
|
|
44
|
+
const fromFilename = context.getFilename();
|
|
45
|
+
if(shouldBeRelative(fromFilename, importTo)) {
|
|
46
|
+
context.report({node: node, message: 'В рамках одного слайса все пути должны быть относительными'});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview description
|
|
3
|
+
* @author vasilii
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Rule Definition
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @type {import('eslint').Rule.RuleModule}
|
|
13
|
+
*/
|
|
14
|
+
module.exports = {
|
|
15
|
+
meta: {
|
|
16
|
+
type: null,
|
|
17
|
+
docs: {
|
|
18
|
+
description: "description",
|
|
19
|
+
category: "Fill me in",
|
|
20
|
+
recommended: false,
|
|
21
|
+
url: null,
|
|
22
|
+
},
|
|
23
|
+
fixable: null,
|
|
24
|
+
schema: [],
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
create(context) {
|
|
29
|
+
const layers = {
|
|
30
|
+
"entities":"entities",
|
|
31
|
+
"features":"features",
|
|
32
|
+
"pages":"pages",
|
|
33
|
+
"shared":"shared",
|
|
34
|
+
"widgets":"widgets",
|
|
35
|
+
}
|
|
36
|
+
const alias = context.options[0]?.alias ?? "";
|
|
37
|
+
return {
|
|
38
|
+
ImportDeclaration(node) {
|
|
39
|
+
// example app/entities/Article
|
|
40
|
+
const value = node.source.value;
|
|
41
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
42
|
+
|
|
43
|
+
// example C:\Users\tim\Desktop\javascript\production_project\src\entities\Article
|
|
44
|
+
const fromFilename = context.getFilename();
|
|
45
|
+
if(shouldBeRelative(fromFilename, importTo)) {
|
|
46
|
+
context.report({node: node, message: 'В рамках одного слайса все пути должны быть относительными'});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
|
|
32
|
+
// example C:\Users\tim\Desktop\javascript\production_project\src\entities\Article
|
|
33
|
+
const fromFilename = context.getFilename();
|
|
34
|
+
if(shouldBeRelative(fromFilename, importTo)) {
|
|
35
|
+
context.report({node: node, message: 'В рамках одного слайса все пути должны быть относительными'});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
// example C:\Users\tim\Desktop\javascript\production_project\src\entities\Article
|
|
35
|
+
const fromFilename = context.getFilename();
|
|
36
|
+
if(shouldBeRelative(fromFilename, importTo)) {
|
|
37
|
+
context.report({node: node, message: 'В рамках одного слайса все пути должны быть относительными'});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
// example C:\Users\tim\Desktop\javascript\production_project\src\entities\Article
|
|
35
|
+
const fromFilename = context.getFilename();
|
|
36
|
+
if(shouldBeRelative(fromFilename, importTo)) {
|
|
37
|
+
context.report({node: node, message: 'В рамках одного слайса все пути должны быть относительными'});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
if() {
|
|
36
|
+
context.report({node: node, message: 'Абсолютный импорт разрешен только из Public Api(index.ts)'});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
};
|
|
@@ -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() {
|
|
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 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,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,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,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
|
+
};
|
package/package.json
CHANGED
|
@@ -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
|
+
});
|