eslint-plugin-laygrd-plugin 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
+ const path = require('path');
7
8
  //------------------------------------------------------------------------------
8
9
  // Rule Definition
9
10
  //------------------------------------------------------------------------------
@@ -13,10 +14,11 @@
13
14
  */
14
15
  module.exports = {
15
16
  meta: {
17
+ // eslint-disable-next-line eslint-plugin/require-meta-type
16
18
  type: null, // `problem`, `suggestion`, or `layout`
17
19
  docs: {
18
20
  description: "check relative paths inside module ",
19
- category: "Fill me in",
21
+ category: "fsd",
20
22
  recommended: false,
21
23
  url: null, // URL to the documentation page for this rule
22
24
  },
@@ -34,8 +36,47 @@ module.exports = {
34
36
  // location of file where current import statement is
35
37
  const currentFileName = context.getFilename();
36
38
 
37
- context.report(node, `Линтер ругается!! \nimportSrc: ${importSrc}\ncurrentFilename: ${currentFileName}`)
39
+ if (shouldPathBeRelative(currentFileName, importSrc)) {
40
+ context.report({node: node, message: 'Imports within the same module must be relative, according to FSD. '});
41
+ }
38
42
  }
39
43
  };
40
44
  },
41
45
  };
46
+
47
+ const layers = {
48
+ 'pages':'pages',
49
+ 'widgets':'widgets',
50
+ 'features':'features',
51
+ 'entities':'entities',
52
+ 'shared':'shared',
53
+ };
54
+
55
+ const isPathRelative = (p) => {
56
+ return p === '.' || p.startsWith('./') || p.startsWith('../');
57
+ };
58
+
59
+ const shouldPathBeRelative = (curFile, impSrc) => {
60
+ if (isPathRelative(impSrc)) {
61
+ return false;
62
+ }
63
+
64
+ const inpSrcArray = impSrc.split('/'); // entities/Profile/ui/ProfileCard -> [entities, Profile, ui, ProfileCard]
65
+ const inpSrcLayer = inpSrcArray[0]; // entities
66
+ const inpSrcSlice = inpSrcArray[1]; // Profile
67
+
68
+ if ( !inpSrcLayer || !inpSrcSlice || !layers[inpSrcLayer] ) {
69
+ return false;
70
+ }
71
+
72
+ const normalizedPath = curFile.split('src')[1]; // 'C:\Users\rosti\Desktop\projects\blog-app\src\entities\Article\ui\ArticleList' -> \entities\Article\ui\ArticleList
73
+ const projectFileArray = normalizedPath.split(path.sep); // \entities\Article\ui\ArticleList -> [ '', 'entities', 'Article', 'ui', 'ArticleList' ]
74
+ const curFileLayer = projectFileArray[1]; // entities
75
+ const curFileSlice = projectFileArray[2]; // Article
76
+
77
+ if ( !curFileLayer || !curFileSlice || !layers[curFileLayer] ) {
78
+ return false;
79
+ }
80
+
81
+ return inpSrcLayer === curFileLayer && inpSrcSlice === curFileSlice;
82
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-laygrd-plugin",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "description": "some usefull fsd violation checkers",
5
5
  "keywords": [
6
6
  "eslint",