eslint-plugin-alexandr-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.
@@ -1,10 +1,7 @@
1
- /**
2
- * @fileoverview feature sliced relative path checker
3
- * @author alexandr
4
- */
5
1
  "use strict";
6
2
 
7
- /** @type {import('eslint').Rule.RuleModule} */
3
+ const path = require('path');
4
+
8
5
  module.exports = {
9
6
  meta: {
10
7
  type: null, // `problem`, `suggestion`, or `layout`
@@ -27,8 +24,58 @@ module.exports = {
27
24
  // example D:\Repository\ulbi-project\src\entities\Article
28
25
  const fromFilename = context.getFilename();
29
26
 
30
- context.report(node, 'ЛИНТЕР РУГАЕТСЯ!!!');
27
+ if (shouldBeRelative(fromFilename, importTo)) {
28
+ context.report(node, 'В рамках одного слайса все пути должны быть относительными');
29
+ }
31
30
  }
32
31
  };
33
32
  },
34
33
  };
34
+
35
+ const layers = {
36
+ 'entities': 'entities',
37
+ 'features': 'features',
38
+ 'shared': 'shared',
39
+ 'pages': 'pages',
40
+ 'widgets': 'widgets',
41
+ }
42
+
43
+ function isPathRelative(path) {
44
+ return path === '.' || path.startsWith('./') || path.startsWith('../')
45
+ }
46
+
47
+ function shouldBeRelative(from, to) {
48
+ if (isPathRelative(to)) {
49
+ return false;
50
+ }
51
+
52
+ // example app/entities/Article
53
+ const toArray = to.split('/');
54
+ const toLayer = toArray[0]; // entities
55
+ const toSlice = toArray[1]; // Article
56
+
57
+ if (!toLayer || !toSlice || !layers[toLayer]) {
58
+ return false;
59
+ }
60
+
61
+ const normalizedPath = path.toNamespacedPath(from);
62
+ const projectFrom = normalizedPath.split('src')[1];
63
+ const fromArray = projectFrom.split('\\');
64
+
65
+ const fromLayer = fromArray[1];
66
+ const fromSlice = fromArray[2];
67
+
68
+ if (!fromLayer || !fromSlice || !layers[fromLayer]) {
69
+ return false;
70
+ }
71
+
72
+ return fromSlice === toSlice && toLayer === fromLayer;
73
+ // example D:\Repository\ulbi-project\src\entities\Article
74
+ }
75
+ console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/Article/fasfasfas'))
76
+ console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/ASdasd/fasfasfas'))
77
+ console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'features/Article/fasfasfas'))
78
+ console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\features\\Article', 'features/Article/fasfasfas'))
79
+ console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'app/index.tsx'))
80
+ console.log(shouldBeRelative('C:/Users/tim/Desktop/javascript/GOOD_COURSE_test/src/entities/Article', 'entities/Article/asfasf/asfasf'))
81
+ console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', '../../model/selectors/getSidebarItems'))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-alexandr-plugin",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "description": "plugin for production project",
5
5
  "keywords": [
6
6
  "eslint",