eslint-plugin-laygrd-plugin 0.0.6 → 0.0.8

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/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  some usefull fsd violation checkers
4
4
 
5
+ **Git**: https://github.com/Laygrd/eslint-plugin-laygrd-plugin
6
+
7
+ **NPM**: https://www.npmjs.com/package/eslint-plugin-laygrd-plugin
8
+
9
+
5
10
  ## Installation
6
11
 
7
12
  You'll first need to install [ESLint](https://eslint.org/):
@@ -34,14 +39,23 @@ Then configure the rules you want to use under the rules section.
34
39
  ```json
35
40
  {
36
41
  "rules": {
37
- "laygrd-plugin/fsd-relative-path": ['error, { alias: '@' }],
38
- "laygrd-plugin/public-api-imports": ['error, { alias: '@' }]
42
+ "laygrd-plugin/fsd-relative-path": ['error,
43
+ {
44
+ alias: '@',
45
+ }
46
+ ],
47
+ "laygrd-plugin/public-api-imports": ['error,
48
+ {
49
+ alias: '@',
50
+ testFilesPatterns: ['**/\*.test.*', '**/\*.stories.*', '**/StoreDecorator.tsx'],
51
+ }
52
+ ],
53
+ "laygrd-plugin/layer-imports": ['error,
54
+ {
55
+ alias: '@',
56
+ ignoreImportPatterns: ['**/StoreProvider'],
57
+ }
58
+ ]
39
59
  }
40
60
  }
41
61
  ```
42
-
43
- ## Supported Rules
44
-
45
- * Fill in provided rules here
46
-
47
-
@@ -0,0 +1,35 @@
1
+ # checks import from layer to layer according to fsd (you can`t import from higher layer to lower in fsd) (`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.
@@ -2,6 +2,9 @@ const isPathRelative = (p) => {
2
2
  return p === '.' || p.startsWith('./') || p.startsWith('../');
3
3
  };
4
4
 
5
+ const normalizePathSeparators = (filename) => filename.replace(/\\/g, '/');
6
+
5
7
  module.exports = {
6
8
  isPathRelative,
9
+ normalizePathSeparators,
7
10
  };
@@ -1,92 +1,91 @@
1
- /**
2
- * @fileoverview check relative paths inside module
3
- * @author laygrd
4
- */
5
- "use strict";
6
-
7
- const path = require('path');
8
- const { isPathRelative } = require('../helpers');
9
-
10
- //------------------------------------------------------------------------------
11
- // Rule Definition
12
- //------------------------------------------------------------------------------
13
-
14
- /**
15
- * @type {import('eslint').Rule.RuleModule}
16
- */
17
- module.exports = {
18
- meta: {
19
- // eslint-disable-next-line eslint-plugin/require-meta-type
20
- type: null,
21
- docs: {
22
- description: "check relative paths inside module ",
23
- category: "fsd",
24
- recommended: false,
25
- url: null,
26
- },
27
- fixable: null,
28
- schema: [
29
- {
30
- type: 'object',
31
- properties: {
32
- alias: {
33
- type: 'string'
34
- }
35
- }
36
- }
37
- ],
38
- },
39
-
40
- create(context) {
41
- const alias = context.options[0]?.alias || '';
42
-
43
- return {
44
- ImportDeclaration(node) {
45
- const value = node.source.value;
46
-
47
- // import from 'shared/Button/Button' <--- this path
48
- const importSrc = alias ? value.replace(`${alias}/`, '') : value;
49
-
50
- // location of file where current import statement is
51
- const currentFileName = context.getFilename();
52
-
53
- if (shouldPathBeRelative(currentFileName, importSrc)) {
54
- context.report({node: node, message: 'Imports within the same module must be relative, according to FSD. '});
55
- }
56
- }
57
- };
58
- },
59
- };
60
-
61
- const layers = {
62
- 'pages':'pages',
63
- 'widgets':'widgets',
64
- 'features':'features',
65
- 'entities':'entities',
66
- 'shared':'shared',
67
- };
68
-
69
- const shouldPathBeRelative = (curFile, impSrc) => {
70
- if (isPathRelative(impSrc)) {
71
- return false;
72
- }
73
-
74
- const inpSrcArray = impSrc.split('/'); // entities/Profile/ui/ProfileCard -> [entities, Profile, ui, ProfileCard]
75
- const inpSrcLayer = inpSrcArray[0]; // entities
76
- const inpSrcSlice = inpSrcArray[1]; // Profile
77
-
78
- if ( !inpSrcLayer || !inpSrcSlice || !layers[inpSrcLayer] ) {
79
- return false;
80
- }
81
-
82
- const normalizedPath = curFile.split('src')[1]; // 'C:\Users\rosti\Desktop\projects\blog-app\src\entities\Article\ui\ArticleList' -> \entities\Article\ui\ArticleList
83
- const projectFileArray = normalizedPath.split(path.sep); // \entities\Article\ui\ArticleList -> [ '', 'entities', 'Article', 'ui', 'ArticleList' ]
84
- const curFileLayer = projectFileArray[1]; // entities
85
- const curFileSlice = projectFileArray[2]; // Article
86
-
87
- if ( !curFileLayer || !curFileSlice || !layers[curFileLayer] ) {
88
- return false;
89
- }
90
-
91
- return inpSrcLayer === curFileLayer && inpSrcSlice === curFileSlice;
92
- };
1
+ /**
2
+ * @fileoverview check relative paths inside module
3
+ * @author laygrd
4
+ */
5
+ "use strict";
6
+
7
+ const { isPathRelative, normalizePathSeparators } = require('../helpers');
8
+
9
+ //------------------------------------------------------------------------------
10
+ // Rule Definition
11
+ //------------------------------------------------------------------------------
12
+
13
+ /**
14
+ * @type {import('eslint').Rule.RuleModule}
15
+ */
16
+ module.exports = {
17
+ meta: {
18
+ // eslint-disable-next-line eslint-plugin/require-meta-type
19
+ type: null,
20
+ docs: {
21
+ description: "check relative paths inside module ",
22
+ category: "fsd",
23
+ recommended: false,
24
+ url: null,
25
+ },
26
+ fixable: null,
27
+ schema: [
28
+ {
29
+ type: 'object',
30
+ properties: {
31
+ alias: {
32
+ type: 'string'
33
+ }
34
+ }
35
+ }
36
+ ],
37
+ },
38
+
39
+ create(context) {
40
+ const alias = context.options[0]?.alias || '';
41
+
42
+ return {
43
+ ImportDeclaration(node) {
44
+ const value = node.source.value;
45
+
46
+ // import from 'shared/Button/Button' <--- this path
47
+ const importSrc = alias ? value.replace(`${alias}/`, '') : value;
48
+
49
+ // location of file where current import statement is
50
+ const currentFileName = context.getFilename();
51
+
52
+ if (shouldPathBeRelative(currentFileName, importSrc)) {
53
+ context.report({node: node, message: 'Imports within the same module must be relative, according to FSD. '});
54
+ }
55
+ }
56
+ };
57
+ },
58
+ };
59
+
60
+ const layers = {
61
+ 'pages':'pages',
62
+ 'widgets':'widgets',
63
+ 'features':'features',
64
+ 'entities':'entities',
65
+ 'shared':'shared',
66
+ };
67
+
68
+ const shouldPathBeRelative = (curFile, impSrc) => {
69
+ if (isPathRelative(impSrc)) {
70
+ return false;
71
+ }
72
+
73
+ const inpSrcArray = impSrc.split('/'); // entities/Profile/ui/ProfileCard -> [entities, Profile, ui, ProfileCard]
74
+ const inpSrcLayer = inpSrcArray[0]; // entities
75
+ const inpSrcSlice = inpSrcArray[1]; // Profile
76
+
77
+ if ( !inpSrcLayer || !inpSrcSlice || !layers[inpSrcLayer] ) {
78
+ return false;
79
+ }
80
+
81
+ const normalizedPath = curFile.split('src')[1]; // 'C:\Users\rosti\Desktop\projects\blog-app\src\entities\Article\ui\ArticleList' -> \entities\Article\ui\ArticleList
82
+ const projectFileArray = normalizePathSeparators(normalizedPath).split('/'); // \entities\Article\ui\ArticleList -> [ '', 'entities', 'Article', 'ui', 'ArticleList' ]
83
+ const curFileLayer = projectFileArray[1]; // entities
84
+ const curFileSlice = projectFileArray[2]; // Article
85
+
86
+ if ( !curFileLayer || !curFileSlice || !layers[curFileLayer] ) {
87
+ return false;
88
+ }
89
+
90
+ return inpSrcLayer === curFileLayer && inpSrcSlice === curFileSlice;
91
+ };
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @fileoverview checks imports from layer to layer according to fsd rules (you cant't import into lower layer from higher)
3
+ * @author laygrd
4
+ */
5
+ "use strict";
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Rule Definition
9
+ //------------------------------------------------------------------------------
10
+
11
+ const micromatch = require('micromatch');
12
+ const { isPathRelative, normalizePathSeparators } = require('../helpers');
13
+
14
+ /** @type {import('eslint').Rule.RuleModule} */
15
+ module.exports = {
16
+ meta: {
17
+ // eslint-disable-next-line eslint-plugin/require-meta-type
18
+ type: null, // `problem`, `suggestion`, or `layout`
19
+ docs: {
20
+ description: "checks imports from layer to layer according to fsd rules (you cant't import into lower layer from higher)",
21
+ recommended: false,
22
+ url: null,
23
+ },
24
+ fixable: null, // Or `code` or `whitespace`
25
+ schema: [
26
+ {
27
+ type: 'object',
28
+ properties: {
29
+ alias: {
30
+ type: 'string'
31
+ },
32
+ ignoreImportPatterns: {
33
+ type: 'array'
34
+ }
35
+ }
36
+ }
37
+ ],
38
+ messages: {},
39
+ },
40
+
41
+ create(context) {
42
+ const layers = {
43
+ 'app': ['shared', 'entities', 'features', 'widgets', 'pages'],
44
+ 'pages': ['shared', 'entities', 'features', 'widgets'],
45
+ 'widgets': ['shared', 'entities', 'features'],
46
+ 'features': ['shared', 'entities'],
47
+ 'entities': ['shared', 'entities'],
48
+ 'shared': ['shared']
49
+ }
50
+
51
+ const availableLayers = {
52
+ 'app': 'app',
53
+ 'pages': 'pages',
54
+ 'widgets': 'widgets',
55
+ 'features': 'features',
56
+ 'entities': 'entities',
57
+ 'shared': 'shared'
58
+ }
59
+
60
+ const { alias = '', ignoreImportPatterns = [] } = context.options[0] || {};
61
+
62
+ const getCurrentFileLayer = () => {
63
+ const currentFilePath = context.getFilename();
64
+
65
+ const normalizedPath = normalizePathSeparators(currentFilePath);
66
+ const projectPath = normalizedPath?.split('src')[1];
67
+ const segments = projectPath.split('/');
68
+
69
+ return segments[1];
70
+ }
71
+
72
+ const getImportLayer = (value) => {
73
+ const importPath = alias ? value.replace(`${alias}/`, '') : value;
74
+
75
+ const segments = importPath?.split('/');
76
+
77
+ return segments?.[0];
78
+ }
79
+
80
+
81
+ return {
82
+ ImportDeclaration(node) {
83
+ const importPath = node.source.value;
84
+
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: node, message: 'Importing from higher-level layers into lower-level layers is prohibited according to the FSD.'});
106
+ }
107
+
108
+ }
109
+ };
110
+ },
111
+ };
@@ -1,78 +1,97 @@
1
- /**
2
- * @fileoverview absolute imports allowed only from public api file (index.ts)
3
- * @author laygrd
4
- */
5
- "use strict";
6
- const { isPathRelative } = require('../helpers');
7
-
8
-
9
- //------------------------------------------------------------------------------
10
- // Rule Definition
11
- //------------------------------------------------------------------------------
12
-
13
- /** @type {import('eslint').Rule.RuleModule} */
14
- module.exports = {
15
- meta: {
16
- // eslint-disable-next-line eslint-plugin/require-meta-type
17
- type: null, // `problem`, `suggestion`, or `layout`
18
- docs: {
19
- category: "fsd",
20
- description: "absolute imports allowed only from public api file (index.ts)",
21
- recommended: false,
22
- url: null, // URL to the documentation page for this rule
23
- },
24
- fixable: null, // Or `code` or `whitespace`
25
- schema: [
26
- {
27
- type: 'object',
28
- properties: {
29
- alias: {
30
- type: 'string'
31
- }
32
- }
33
- }
34
- ], // Add a schema if the rule has options
35
- messages: {}, // Add messageId and message
36
- },
37
-
38
- create(context) {
39
- const alias = context.options[0]?.alias || '';
40
-
41
- return {
42
- ImportDeclaration(node) {
43
- const value = node.source.value;
44
-
45
- // import from '@/features/Button/Button' --> import from 'features/Button/Button'
46
- const importSrc = alias ? value.replace(`${alias}/`, '') : value;
47
-
48
- // skipping relative paths like '../ui/Button/Button'
49
- if (isPathRelative(importSrc)) {
50
- return;
51
- }
52
-
53
- const segments = importSrc.split('/');
54
-
55
- // valid: "import {...} from 'entities/article'" -> ['entities', 'article']
56
- // invalid: "import {...} from 'entities/article/ui/articleCard/articleCard'" -> ['entities', 'article', 'ui', 'articleCard', 'articleCard']
57
- const isImportNotFromPublicApi = segments.length > 2;
58
-
59
- // check only declared layers from project root
60
- const layer = segments[0];
61
- if (!layersToCheck[layer]) {
62
- return;
63
- }
64
-
65
- if (isImportNotFromPublicApi) {
66
- context.report({node: node, message: 'Absolute imports should be only from module`s Public API (index.ts). '});
67
- }
68
- }
69
- };
70
- },
71
- };
72
-
73
- const layersToCheck = {
74
- 'pages':'pages',
75
- 'widgets':'widgets',
76
- 'features':'features',
77
- 'entities':'entities',
1
+ /**
2
+ * @fileoverview absolute imports allowed only from public api file (index.ts)
3
+ * @author laygrd
4
+ */
5
+ "use strict";
6
+ const { isPathRelative, normalizePathSeparators } = require('../helpers');
7
+ const micromatch = require('micromatch');
8
+
9
+ //------------------------------------------------------------------------------
10
+ // Rule Definition
11
+ //------------------------------------------------------------------------------
12
+
13
+ /** @type {import('eslint').Rule.RuleModule} */
14
+ module.exports = {
15
+ meta: {
16
+ // eslint-disable-next-line eslint-plugin/require-meta-type
17
+ type: null, // `problem`, `suggestion`, or `layout`
18
+ docs: {
19
+ category: "fsd",
20
+ description: "absolute imports allowed only from public api file (index.ts)",
21
+ recommended: false,
22
+ url: null, // URL to the documentation page for this rule
23
+ },
24
+ fixable: null, // Or `code` or `whitespace`
25
+ schema: [
26
+ {
27
+ type: 'object',
28
+ properties: {
29
+ alias: {
30
+ type: 'string'
31
+ },
32
+ testFilesPatterns: {
33
+ type: 'array'
34
+ }
35
+ }
36
+ }
37
+ ], // Add a schema if the rule has options
38
+ messages: {}, // Add messageId and message
39
+ },
40
+
41
+ create(context) {
42
+ const { alias = '', testFilesPatterns = [] } = context.options[0] || {};
43
+
44
+ return {
45
+ ImportDeclaration(node) {
46
+ const value = node.source.value;
47
+
48
+ // import from '@/features/Button/Button' --> import from 'features/Button/Button'
49
+ const importSrc = alias ? value.replace(`${alias}/`, '') : value;
50
+
51
+ // skipping relative paths like '../ui/Button/Button'
52
+ if (isPathRelative(importSrc)) {
53
+ return;
54
+ }
55
+
56
+ const segments = importSrc.split('/');
57
+
58
+ // "import {...} from 'entities/article'" -> ['entities', 'article'] -> true
59
+ // "import {...} from 'entities/article/ui/articleCard/articleCard'" -> ['entities', 'article', 'ui', 'articleCard', 'articleCard'] -> false
60
+ const isImportNotFromPublicApi = segments.length > 2;
61
+
62
+ // "import {...} from 'entities/article/testing'" -> ['entities', 'article', 'testing'] -> true
63
+ // "import {...} from 'entities/article/lib/mockData'" -> ['entities', 'article', 'lib', 'mockData'] -> fasle
64
+ const isImportFromTestingPublicApi = segments[2] === 'testing' && segments.length < 4;
65
+
66
+ // check only declared layers from project root
67
+ const layer = segments[0];
68
+ if (!layersToCheck[layer]) {
69
+ return;
70
+ }
71
+
72
+ if (isImportNotFromPublicApi && !isImportFromTestingPublicApi) {
73
+ context.report({node: node, message: 'Absolute imports should be only from module`s Public API (index.ts, index.js). '});
74
+ }
75
+
76
+ if (isImportFromTestingPublicApi) {
77
+ const currentFilePath = normalizePathSeparators(context.getFilename());
78
+
79
+ const isCurrentFileTesting = testFilesPatterns.some(
80
+ pattern => micromatch.isMatch( currentFilePath, pattern )
81
+ )
82
+
83
+ if (!isCurrentFileTesting) {
84
+ context.report({node: node, message: 'Test data can only be imported into test files via the testing public API (testing.ts, testing.js). '})
85
+ }
86
+ }
87
+ }
88
+ };
89
+ },
90
+ };
91
+
92
+ const layersToCheck = {
93
+ 'pages':'pages',
94
+ 'widgets':'widgets',
95
+ 'features':'features',
96
+ 'entities':'entities',
78
97
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-laygrd-plugin",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "some usefull fsd rule-checkers",
5
5
  "keywords": [
6
6
  "eslint",
@@ -14,6 +14,7 @@
14
14
  "test": "mocha tests --recursive"
15
15
  },
16
16
  "dependencies": {
17
+ "micromatch": "^4.0.8",
17
18
  "requireindex": "^1.2.0"
18
19
  },
19
20
  "devDependencies": {
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @fileoverview checks imports from layer to layer according to fsd rules (you cant&#39;t import into lower layer from higher)
3
+ * @author laygrd
4
+ */
5
+ "use strict";
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ const rule = require("../../../lib/rules/layer-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("layer-imports", rule, {
23
+ valid: [
24
+ {
25
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Rating.tsx',
26
+ code: "import { Button } from 'shared/ui/Button/Button.tsx'",
27
+ errors: [],
28
+ },
29
+ {
30
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\features\\rateArticle\\ui\\ArticleRating.tsx',
31
+ code: "import { Article } from 'entities/Article'",
32
+ errors: [],
33
+ },
34
+ {
35
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Profile\\ui\\ProfileCard.tsx',
36
+ code: "import { Popup } from '@/shared/ui/Popup'",
37
+ options: [{ alias: '@' }],
38
+ errors: []
39
+ },
40
+ {
41
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Article\\ui\\Article.tsx',
42
+ code: "import { StoreProvider } from 'app/providers/StoreProvider'",
43
+ options: [{ ignoreImportPatterns: ['**/StoreProvider'] }],
44
+ errors: []
45
+ },
46
+ {
47
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\shared\\ui\\Textarea\\Textarea.tsx',
48
+ code: "import { useRef } from 'react'",
49
+ errors: []
50
+ },
51
+ ],
52
+
53
+ invalid: [
54
+ {
55
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Rating.tsx',
56
+ code: "import { RatingCard } from 'features/rateArticle'",
57
+ errors: ['Importing from higher-level layers into lower-level layers is prohibited according to the FSD.'],
58
+ },
59
+ {
60
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\features\\rateArticle\\ui\\ArticleRating.tsx',
61
+ code: "import { ErrorBoundaryProvider } from 'app/providers/ErrorBoundary'",
62
+ errors: ['Importing from higher-level layers into lower-level layers is prohibited according to the FSD.'],
63
+ },
64
+ {
65
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\shared\\ui\\Popup.tsx',
66
+ code: "import { UserCard } from '@/entities/User'",
67
+ options: [{ alias: '@' }],
68
+ errors: ['Importing from higher-level layers into lower-level layers is prohibited according to the FSD.']
69
+ },
70
+ {
71
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Article\\ui\\Article.tsx',
72
+ code: "import { SomeProvider } from 'app/providers/SomeProvider'",
73
+ options: [{ ignoreImportPatterns: ['**/StoreProvider'] }],
74
+ errors: ['Importing from higher-level layers into lower-level layers is prohibited according to the FSD.']
75
+ },
76
+ ],
77
+ });
@@ -21,39 +21,89 @@ const ruleTester = new RuleTester({
21
21
  });
22
22
  ruleTester.run("public-api-exports", rule, {
23
23
  valid: [
24
+ // index.ts
24
25
  {
25
- filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Rating\\ui\\RatingCard\\RatingCard',
26
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Rating\\ui\\RatingCard\\RatingCard.tsx',
26
27
  code: "import { Avatar } from '@/widgets/Avatar'",
27
28
  errors: [],
28
29
  options: [{ alias: '@' }]
29
30
  },
30
31
  {
31
- filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\widgets\\ThemeSwitcher\\ui\\ThemeSwitcher\\ThemeSwitcher',
32
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\widgets\\ThemeSwitcher\\ui\\ThemeSwitcher\\ThemeSwitcher.tsx',
32
33
  code: "import { Button } from '@/shared/Button/ui/Button'",
33
34
  errors: [],
34
35
  options: [{ alias: '@' }]
35
36
  },
36
37
  {
37
- filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\widgets\\ThemeSwitcher\\ui\\ThemeSwitcher\\ThemeSwitcher',
38
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\widgets\\ThemeSwitcher\\ui\\ThemeSwitcher\\ThemeSwitcher.tsx',
38
39
  code: "import { useCallback } from 'react'",
39
40
  errors: [],
40
41
  options: [{ alias: '@' }]
41
42
  },
42
-
43
+
44
+ // testing.ts
45
+ {
46
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\article\\services\\getArticle.test.ts',
47
+ code: "import { mockData } from '@/entities/Article/testing'",
48
+ errors: [],
49
+ options: [{
50
+ alias: '@',
51
+ testFilesPatterns: ['**/*.test.*', '**/*.story.*', '**/StoreDecorator.tsx']
52
+ }]
53
+ },
54
+ {
55
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\shared\\lib\\decorators\\StoreDecorator.tsx',
56
+ code: "import { userReducer } from '@/entities/User/testing'",
57
+ errors: [],
58
+ options: [{
59
+ alias: '@',
60
+ testFilesPatterns: ['**/*.test.*', '**/*.story.*', '**/StoreDecorator.tsx']
61
+ }]
62
+ },
43
63
  ],
44
64
 
45
65
  invalid: [
66
+ // index.ts
46
67
  {
47
- filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Rating\\ui\\RatingCard\\RatingCard',
68
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Rating\\ui\\RatingCard\\RatingCard.tsx',
48
69
  code: "import { Avatar } from 'widgets/Avatar/ui/Avatar/Avatar'",
49
- errors: [{ message: 'Absolute imports should be only from module`s Public API (index.ts). '}],
70
+ errors: [{ message: 'Absolute imports should be only from module`s Public API (index.ts, index.js). '}],
50
71
  options: [{ alias: '@' }]
51
72
  },
52
73
  {
53
- filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\widgets\\ThemeSwitcher\\ui\\ThemeSwitcher\\ThemeSwitcher',
74
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\widgets\\ThemeSwitcher\\ui\\ThemeSwitcher\\ThemeSwitcher.tsx',
54
75
  code: "import { Theme } from '@/entities/Theme/lib/themes'",
55
- errors: [{ message: 'Absolute imports should be only from module`s Public API (index.ts). '}],
76
+ errors: [{ message: 'Absolute imports should be only from module`s Public API (index.ts, index.js). '}],
56
77
  options: [{ alias: '@' }]
57
78
  },
79
+
80
+ // testing.ts
81
+ {
82
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Article\\ui\\ArticleCard\\ArticleCard.tsx',
83
+ code: "import { mockData } from '@/entities/Article/testing'",
84
+ errors: [{ message: 'Test data can only be imported into test files via the testing public API (testing.ts, testing.js). '}],
85
+ options: [{
86
+ alias: '@',
87
+ testFilesPatterns: ['**/*.test.*', '**/*.story.*', '**/StoreDecorator.tsx']
88
+ }]
89
+ },
90
+ {
91
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Article\\services\\getArticle.test.ts',
92
+ code: "import { mockData } from '@/entities/Article/lib/consts'",
93
+ errors: [{ message: 'Absolute imports should be only from module`s Public API (index.ts, index.js). '}],
94
+ options: [{
95
+ alias: '@',
96
+ testFilesPatterns: ['**/*.test.*', '**/*.story.*', '**/StoreDecorator.tsx']
97
+ }]
98
+ },
99
+ {
100
+ filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\shared\\lib\\decorators\\StoreDecorator.tsx',
101
+ code: "import { userReducer } from '@/entities/User/testing/reducer.ts'",
102
+ errors: [{ message: 'Absolute imports should be only from module`s Public API (index.ts, index.js). '}],
103
+ options: [{
104
+ alias: '@',
105
+ testFilesPatterns: ['**/*.test.*', '**/*.story.*', '**/StoreDecorator.tsx']
106
+ }]
107
+ },
58
108
  ],
59
109
  });