eslint-plugin-big-react-app-plugin 0.1.8 → 0.2.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.
Files changed (38) hide show
  1. package/.history/lib/rules/layer-imports_20251101143845.js +44 -0
  2. package/.history/lib/rules/layer-imports_20251101144032.js +106 -0
  3. package/.history/lib/rules/layer-imports_20251101144044.js +106 -0
  4. package/.history/lib/rules/layer-imports_20251101144137.js +106 -0
  5. package/.history/lib/rules/layer-imports_20251101144214.js +110 -0
  6. package/.history/lib/rules/public-api-imports_20251030072017.js +77 -0
  7. package/.history/lib/rules/public-api-imports_20251030072333.js +76 -0
  8. package/.history/lib/rules/public-api-imports_20251030072413.js +76 -0
  9. package/.history/lib/rules/public-api-imports_20251030072442.js +76 -0
  10. package/.history/lib/rules/public-api-imports_20251030072512.js +76 -0
  11. package/.history/lib/rules/public-api-imports_20251030073010.js +77 -0
  12. package/.history/lib/rules/public-api-imports_20251030073013.js +77 -0
  13. package/.history/lib/rules/public-api-imports_20251030073246.js +77 -0
  14. package/.history/package_20251030073306.json +33 -0
  15. package/.history/package_20251102101931.json +33 -0
  16. package/.history/package_20251102101944.json +33 -0
  17. package/.history/tests/lib/rules/layer-imports_20251101143845.js +31 -0
  18. package/.history/tests/lib/rules/layer-imports_20251101144101.js +77 -0
  19. package/.history/tests/lib/rules/layer-imports_20251101144110.js +81 -0
  20. package/.history/tests/lib/rules/layer-imports_20251101144121.js +83 -0
  21. package/.history/tests/lib/rules/layer-imports_20251101144130.js +97 -0
  22. package/.history/tests/lib/rules/path-checker_20251101143521.js +34 -0
  23. package/.history/tests/lib/rules/public-api-imports_20251030071316.js +96 -0
  24. package/.history/tests/lib/rules/public-api-imports_20251030071331.js +96 -0
  25. package/.history/tests/lib/rules/public-api-imports_20251030073042.js +96 -0
  26. package/.history/tests/lib/rules/public-api-imports_20251030073103.js +96 -0
  27. package/.history/tests/lib/rules/public-api-imports_20251030073107.js +96 -0
  28. package/.history/tests/lib/rules/public-api-imports_20251030073112.js +96 -0
  29. package/.history/tests/lib/rules/public-api-imports_20251101143401.js +95 -0
  30. package/.history/tests/lib/rules/public-api-imports_20251101143431.js +95 -0
  31. package/.history/tests/lib/rules/public-api-imports_20251101143526.js +87 -0
  32. package/docs/rules/layer-imports.md +35 -0
  33. package/lib/rules/layer-imports.js +110 -0
  34. package/lib/rules/public-api-imports.js +2 -1
  35. package/package.json +1 -1
  36. package/tests/lib/rules/layer-imports.js +97 -0
  37. package/tests/lib/rules/path-checker.js +1 -11
  38. package/tests/lib/rules/public-api-imports.js +1 -10
@@ -0,0 +1,96 @@
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
+
29
+ ruleTester.run("public-api-imports", rule, {
30
+ valid: [
31
+ {
32
+ code: "import { addCommentFormActions, addCommentFormReducer } from '../../model/slices/addCommentFormSlice'",
33
+ errors: [],
34
+ },
35
+ {
36
+ filename: 'C:\Users\ADMIN\Documents\GitHub\ulbi\big-react-app\src\shared\config\storybook\StoreDecorator\StoreDecorator.tsx',
37
+ code: "import { loginReducer } from '@/features/AuthByUsername/testing'",
38
+ errors: [],
39
+ options: [{
40
+ alias: '@',
41
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
42
+ }],
43
+ },
44
+ {
45
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article'",
46
+ errors: [],
47
+ options: aliasOptions,
48
+ },
49
+ {
50
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\file.test.ts',
51
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
52
+ errors: [],
53
+ options: [{
54
+ alias: '@',
55
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
56
+ }],
57
+ },
58
+ {
59
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
60
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
61
+ errors: [],
62
+ options: [{
63
+ alias: '@',
64
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
65
+ }],
66
+ }
67
+ ],
68
+
69
+ invalid: [
70
+ {
71
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/model/file.ts'",
72
+ errors: [{ message: "Абсолютный импорт разрешен только из Public API (index.ts)"}],
73
+ options: aliasOptions,
74
+ },
75
+ {
76
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
77
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing/file.tsx'",
78
+ errors: [{message: 'Абсолютный импорт разрешен только из Public API (index.ts)'}],
79
+ options: [{
80
+ alias: '@',
81
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
82
+ }],
83
+ },
84
+ {
85
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\forbidden.ts',
86
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
87
+ errors: [{message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'}],
88
+ options: [{
89
+ alias: '@',
90
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
91
+ }],
92
+ }
93
+
94
+ ],
95
+ });
96
+
@@ -0,0 +1,96 @@
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
+
29
+ ruleTester.run("public-api-imports", rule, {
30
+ valid: [
31
+ {
32
+ code: "import { addCommentFormActions, addCommentFormReducer } from '../../model/slices/addCommentFormSlice'",
33
+ errors: [],
34
+ },
35
+ {
36
+ filename: 'D:\\KonovalovVasiliy\\GitHub\\ulbi\\big-react-app\\src\\shared\\config\\storybook\\StoreDecorator\\StoreDecorator.tsx',
37
+ code: "import { loginReducer } from '@/features/AuthByUsername/testing'",
38
+ errors: [],
39
+ options: [{
40
+ alias: '@',
41
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
42
+ }],
43
+ },
44
+ {
45
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article'",
46
+ errors: [],
47
+ options: aliasOptions,
48
+ },
49
+ {
50
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\file.test.ts',
51
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
52
+ errors: [],
53
+ options: [{
54
+ alias: '@',
55
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
56
+ }],
57
+ },
58
+ {
59
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
60
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
61
+ errors: [],
62
+ options: [{
63
+ alias: '@',
64
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
65
+ }],
66
+ }
67
+ ],
68
+
69
+ invalid: [
70
+ {
71
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/model/file.ts'",
72
+ errors: [{ message: "Абсолютный импорт разрешен только из Public API (index.ts)"}],
73
+ options: aliasOptions,
74
+ },
75
+ {
76
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
77
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing/file.tsx'",
78
+ errors: [{message: 'Абсолютный импорт разрешен только из Public API (index.ts)'}],
79
+ options: [{
80
+ alias: '@',
81
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
82
+ }],
83
+ },
84
+ {
85
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\forbidden.ts',
86
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
87
+ errors: [{message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'}],
88
+ options: [{
89
+ alias: '@',
90
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
91
+ }],
92
+ }
93
+
94
+ ],
95
+ });
96
+
@@ -0,0 +1,95 @@
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
+
29
+ ruleTester.run("public-api-imports", rule, {
30
+ valid: [
31
+ {
32
+ code: "import { addCommentFormActions, addCommentFormReducer } from '../../model/slices/addCommentFormSlice'",
33
+ errors: [],
34
+ },
35
+ {
36
+ filename: 'D:\\KonovalovVasiliy\\GitHub\\ulbi\\big-react-app\\src\\shared\\config\\storybook\\StoreDecorator\\StoreDecorator.tsx',
37
+ code: "import { loginReducer } from '@/features/AuthByUsername/testing'",
38
+ errors: [],
39
+ options: [{
40
+ alias: '@',
41
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
42
+ }],
43
+ },
44
+ {
45
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article'",
46
+ errors: [],
47
+ options: aliasOptions,
48
+ },
49
+ {
50
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\file.test.ts',
51
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
52
+ errors: [],
53
+ options: [{
54
+ alias: '@',
55
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
56
+ }],
57
+ },
58
+ {
59
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
60
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
61
+ errors: [],
62
+ options: [{
63
+ alias: '@',
64
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
65
+ }],
66
+ }
67
+ ],
68
+
69
+ invalid: [
70
+ {
71
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/model/file.ts'",
72
+ errors: [{ message: "Абсолютный импорт разрешен только из Public API (index.ts)"}],
73
+ options: aliasOptions,
74
+ },
75
+ {
76
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
77
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing/file.tsx'",
78
+ errors: [{message: 'Абсолютный импорт разрешен только из Public API (index.ts)'}],
79
+ options: [{
80
+ alias: '@',
81
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
82
+ }],
83
+ },
84
+ {
85
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\forbidden.ts',
86
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
87
+ errors: [{message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'}],
88
+ options: [{
89
+ alias: '@',
90
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
91
+ }],
92
+ }
93
+ ],
94
+ });
95
+
@@ -0,0 +1,95 @@
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
+
29
+ ruleTester.run("public-api-imports", rule, {
30
+ valid: [
31
+ {
32
+ code: "import { addCommentFormActions, addCommentFormReducer } from '../../model/slices/addCommentFormSlice'",
33
+ errors: [],
34
+ },
35
+ {
36
+ filename: 'D:\\KonovalovVasiliy\\GitHub\\ulbi\\big-react-app\\src\\shared\\config\\storybook\\StoreDecorator\\StoreDecorator.tsx',
37
+ code: "import { loginReducer } from '@/features/AuthByUsername/testing'",
38
+ errors: [],
39
+ options: [{
40
+ alias: '@',
41
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
42
+ }],
43
+ },
44
+ {
45
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article'",
46
+ errors: [],
47
+ options: aliasOptions,
48
+ },
49
+ {
50
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\file.test.ts',
51
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
52
+ errors: [],
53
+ options: [{
54
+ alias: '@',
55
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
56
+ }],
57
+ },
58
+ {
59
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
60
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
61
+ errors: [],
62
+ options: [{
63
+ alias: '@',
64
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
65
+ }],
66
+ }
67
+ ],
68
+
69
+ invalid: [
70
+ {
71
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/model/file.ts'",
72
+ errors: [{ message: "Абсолютный импорт разрешен только из Public API (index.ts)"}],
73
+ options: aliasOptions,
74
+ },
75
+ {
76
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
77
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing/file.tsx'",
78
+ errors: [{message: 'Абсолютный импорт разрешен только из Public API (index.ts)'}],
79
+ options: [{
80
+ alias: '@',
81
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
82
+ }],
83
+ },
84
+ {
85
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\forbidden.ts',
86
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
87
+ errors: [{message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'}],
88
+ options: [{
89
+ alias: '@',
90
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
91
+ }],
92
+ }
93
+ ],
94
+ });
95
+
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @fileoverview public API path checker
3
+ * @author vasilii
4
+ */
5
+ "use strict";
6
+
7
+ const rule = require("../../../lib/rules/public-api-imports"),
8
+ RuleTester = require("eslint").RuleTester;
9
+
10
+
11
+ const ruleTester = new RuleTester({
12
+ parserOptions: {ecmaVersion: 6, sourceType: 'module'}
13
+ });
14
+
15
+ const aliasOptions = [
16
+ {
17
+ alias: '@'
18
+ }
19
+ ]
20
+
21
+ ruleTester.run("public-api-imports", rule, {
22
+ valid: [
23
+ {
24
+ code: "import { addCommentFormActions, addCommentFormReducer } from '../../model/slices/addCommentFormSlice'",
25
+ errors: [],
26
+ },
27
+ {
28
+ filename: 'D:\\KonovalovVasiliy\\GitHub\\ulbi\\big-react-app\\src\\shared\\config\\storybook\\StoreDecorator\\StoreDecorator.tsx',
29
+ code: "import { loginReducer } from '@/features/AuthByUsername/testing'",
30
+ errors: [],
31
+ options: [{
32
+ alias: '@',
33
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
34
+ }],
35
+ },
36
+ {
37
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article'",
38
+ errors: [],
39
+ options: aliasOptions,
40
+ },
41
+ {
42
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\file.test.ts',
43
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
44
+ errors: [],
45
+ options: [{
46
+ alias: '@',
47
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
48
+ }],
49
+ },
50
+ {
51
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
52
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
53
+ errors: [],
54
+ options: [{
55
+ alias: '@',
56
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
57
+ }],
58
+ }
59
+ ],
60
+
61
+ invalid: [
62
+ {
63
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/model/file.ts'",
64
+ errors: [{ message: "Абсолютный импорт разрешен только из Public API (index.ts)"}],
65
+ options: aliasOptions,
66
+ },
67
+ {
68
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
69
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing/file.tsx'",
70
+ errors: [{message: 'Абсолютный импорт разрешен только из Public API (index.ts)'}],
71
+ options: [{
72
+ alias: '@',
73
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
74
+ }],
75
+ },
76
+ {
77
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\forbidden.ts',
78
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
79
+ errors: [{message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'}],
80
+ options: [{
81
+ alias: '@',
82
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
83
+ }],
84
+ }
85
+ ],
86
+ });
87
+
@@ -0,0 +1,35 @@
1
+ # The rule ensures that the layers above are not used in the layers below. (layer-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.
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @fileoverview The rule ensures that the layers above are not used in the layers below.
3
+ * @author vasilii
4
+ */
5
+ "use strict";
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Rule Definition
9
+ //------------------------------------------------------------------------------
10
+
11
+ /**
12
+ * @type {import('eslint').Rule.RuleModule}
13
+ */
14
+
15
+ const path = require('path');
16
+ const {isPathRelative} = require('../helpers');
17
+ const micromatch = require('micromatch');
18
+ module.exports = {
19
+ meta: {
20
+ type: null, // `problem`, `suggestion`, or `layout`
21
+ docs: {
22
+ description: "saf",
23
+ category: "Fill me in",
24
+ recommended: false,
25
+ url: null, // URL to the documentation page for this rule
26
+ },
27
+ fixable: null, // Or `code` or `whitespace`
28
+ schema: [
29
+ {
30
+ type: 'object',
31
+ properties: {
32
+ alias: {
33
+ type: 'string',
34
+ },
35
+ ignoreImportPatterns: {
36
+ type: 'array',
37
+ }
38
+ },
39
+ }
40
+ ],
41
+ },
42
+
43
+ create(context) {
44
+ const layers = {
45
+ 'app': ['pages', 'widgets', 'features', 'shared', 'entities'],
46
+ 'pages': ['widgets', 'features', 'shared', 'entities'],
47
+ 'widgets': ['features', 'shared', 'entities'],
48
+ 'features': ['shared', 'entities'],
49
+ 'entities': ['shared', 'entities'],
50
+ 'shared': ['shared'],
51
+ }
52
+
53
+ const availableLayers = {
54
+ 'app': 'app',
55
+ 'entities': 'entities',
56
+ 'features': 'features',
57
+ 'shared': 'shared',
58
+ 'pages': 'pages',
59
+ 'widgets': 'widgets',
60
+ }
61
+
62
+
63
+ const {alias = '', ignoreImportPatterns = []} = context.options[0] ?? {};
64
+
65
+ const getCurrentFileLayer = () => {
66
+ const currentFilePath = context.getFilename();
67
+
68
+ const normalizedPath = path.toNamespacedPath(currentFilePath);
69
+ const projectPath = normalizedPath?.split('src')[1];
70
+ const segments = projectPath?.split('\\')
71
+
72
+ return segments?.[1];
73
+ }
74
+
75
+ const getImportLayer = (value) => {
76
+ const importPath = alias ? value.replace(`${alias}/`, '') : value;
77
+ const segments = importPath?.split('/')
78
+
79
+ return segments?.[0]
80
+ }
81
+
82
+ return {
83
+ ImportDeclaration(node) {
84
+ const importPath = node.source.value
85
+ const currentFileLayer = getCurrentFileLayer()
86
+ const importLayer = getImportLayer(importPath)
87
+
88
+ if(isPathRelative(importPath)) {
89
+ return;
90
+ }
91
+
92
+ if(!availableLayers[importLayer] || !availableLayers[currentFileLayer]) {
93
+ return;
94
+ }
95
+
96
+ const isIgnored = ignoreImportPatterns.some(pattern => {
97
+ return micromatch.isMatch(importPath, pattern)
98
+ });
99
+
100
+ if(isIgnored) {
101
+ return;
102
+ }
103
+
104
+ if(!layers[currentFileLayer]?.includes(importLayer)) {
105
+ context.report(node, 'Слой может импортировать в себя только нижележащие слои (shared, entities, features, widgets, pages, app)');
106
+ }
107
+ }
108
+ };
109
+ },
110
+ };
@@ -41,6 +41,7 @@ module.exports = {
41
41
  // example app/entities/Article
42
42
  const value = node.source.value;
43
43
  const importTo = alias ? value.replace(`${alias}/`, "") : value;
44
+
44
45
  //если путь относительный то выходим
45
46
  if(isPathRelative(importTo)){
46
47
  return;
@@ -64,7 +65,7 @@ module.exports = {
64
65
 
65
66
  if(isTestingPublicApi){
66
67
  const currentFilePath = context.getFilename();
67
- const normalizedPath = path.normalize(currentFilePath).replace(/\\/g, '/')
68
+ const normalizedPath = currentFilePath.split(path.sep).join('/');
68
69
  const isCurrentFileTesting = testFilesPatterns.some(pattern=>micromatch.isMatch(normalizedPath, pattern))
69
70
  if(!isCurrentFileTesting){
70
71
  context.report({node: node, message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-big-react-app-plugin",
3
- "version": "0.1.8",
3
+ "version": "0.2.0",
4
4
  "description": "plugin for prod proj",
5
5
  "keywords": [
6
6
  "eslint",