eslint-plugin-big-react-app-plugin 0.2.9 → 0.2.11

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,8 +1,8 @@
1
1
  "use strict";
2
2
 
3
- const { type } = require('os');
4
- const path = require('path');
5
- const {isPathRelative} = require("../helpers")
3
+ const { type } = require("os");
4
+ const path = require("path");
5
+ const { isPathRelative } = require("../helpers");
6
6
  module.exports = {
7
7
  meta: {
8
8
  type: null,
@@ -10,88 +10,97 @@ module.exports = {
10
10
  description: "feature sliced relative path checker",
11
11
  category: "Fill me in",
12
12
  recommended: false,
13
- url: null,
13
+ url: null,
14
14
  },
15
- fixable: 'code',
15
+ fixable: "code",
16
16
  schema: [
17
- {
18
- type:"object",
19
- properties:
20
- {
21
- alias:{
22
- type: 'string'
23
- }
24
- }
25
- }
26
- ],
17
+ {
18
+ type: "object",
19
+ properties: {
20
+ alias: {
21
+ type: "string",
22
+ },
23
+ },
24
+ },
25
+ ],
27
26
  },
28
27
 
29
28
  create(context) {
30
29
  const alias = context.options[0]?.alias ?? "";
31
30
  return {
32
31
  ImportDeclaration(node) {
33
- // example app/entities/Article
34
- const value = node.source.value;
35
- const importTo = alias ? value.replace(`${alias}/`, "") : value;
32
+ try {
33
+ // example app/entities/Article
34
+ const value = node.source.value;
35
+ const importTo = alias ? value.replace(`${alias}/`, "") : value;
36
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:
41
- node,
42
- message: 'В рамках одного слайса все пути должны быть относительными',
43
- fix:(fixer)=>{
44
- const normalizedPath = getNormalizedFilePath(fromFilename).split('/').slice(0, -1).join('/')//enteties/Article/Artcile.tsx файл в который делаем импорт и также убираем концовку
45
- let relativePath = path.relative(normalizedPath, `/${importTo}`).split('\\').join('/')
46
- if(!relativePath.startsWith('.')){
47
- relativePath = './' + relativePath
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({
41
+ node: node,
42
+ message:
43
+ "В рамках одного слайса все пути должны быть относительными",
44
+ fix: (fixer) => {
45
+ const normalizedPath = getNormalizedFilePath(fromFilename)
46
+ .split("/")
47
+ .slice(0, -1)
48
+ .join("/"); //enteties/Article/Artcile.tsx файл в который делаем импорт и также убираем концовку
49
+ let relativePath = path
50
+ .relative(normalizedPath, `/${importTo}`)
51
+ .split("\\")
52
+ .join("/");
53
+ if (!relativePath.startsWith(".")) {
54
+ relativePath = "./" + relativePath;
48
55
  }
49
- return fixer.replaceText(node.source, `'${relativePath}'`)
50
- }
51
- })
56
+ return fixer.replaceText(node.source, `'${relativePath}'`);
57
+ },
58
+ });
59
+ }
60
+ } catch (error) {
61
+ console.log(error);
52
62
  }
53
- }
63
+ },
54
64
  };
55
65
  },
56
66
  };
57
67
 
58
68
  const layers = {
59
- "entities":"entities",
60
- "features":"features",
61
- "pages":"pages",
62
- "shared":"shared",
63
- "widgets":"widgets",
64
- }
65
- function getNormalizedFilePath (from){
66
- const normalizationPath = path.toNamespacedPath(from);
67
- const projFrom = normalizationPath.split('src')[1]
68
- return projFrom.split('\\').join('/')
69
+ entities: "entities",
70
+ features: "features",
71
+ pages: "pages",
72
+ shared: "shared",
73
+ widgets: "widgets",
74
+ };
75
+ function getNormalizedFilePath(from) {
76
+ const normalizationPath = path.toNamespacedPath(from);
77
+ const projFrom = normalizationPath.split("src")[1];
78
+ return projFrom?.split("\\").join("/");
69
79
  }
70
- function shouldBeRelative (from, to){
71
- if(isPathRelative(to)){
72
- return false
80
+ function shouldBeRelative(from, to) {
81
+ if (isPathRelative(to)) {
82
+ return false;
73
83
  }
74
- const toArray = to.split('/')
84
+ const toArray = to.split("/");
75
85
  //app/entities/Article
76
86
  const toLayer = toArray[0];
77
87
  //"C:\Users\ADMIN\Documents\GitHub\ulbi\big-app-react\src\entities\Article\model\types\artcile.ts"
78
88
  const toSlice = toArray[1];
79
- if(!toLayer || !toSlice || !layers[toLayer]){
80
- return false
89
+ if (!toLayer || !toSlice || !layers[toLayer]) {
90
+ return false;
81
91
  }
82
- //нормализуем путь
83
- const projFrom = getNormalizedFilePath(from)
84
- const fromArray = projFrom.split('/')
85
-
92
+ //нормализуем путь
93
+ const projFrom = getNormalizedFilePath(from);
94
+ const fromArray = projFrom.split("/");
95
+
86
96
  const fromLayer = fromArray[1];
87
97
  const fromSlice = fromArray[2];
88
- if(!fromLayer || !fromSlice || !layers[fromLayer]){
89
- return false
98
+ if (!fromLayer || !fromSlice || !layers[fromLayer]) {
99
+ return false;
90
100
  }
91
-
92
- return toSlice === fromSlice && toLayer === fromLayer
93
- }
94
101
 
102
+ return toSlice === fromSlice && toLayer === fromLayer;
103
+ }
95
104
 
96
105
  // console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/Article/fasfasfas'))
97
106
  // console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/ASdasd/fasfasfas'))
@@ -99,4 +108,4 @@ function shouldBeRelative (from, to){
99
108
  // console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\features\\Article', 'features/Article/fasfasfas'))
100
109
  // console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'app/index.tsx'))
101
110
  // console.log(shouldBeRelative('C:/Users/tim/Desktop/javascript/GOOD_COURSE_test/src/entities/Article', 'entities/Article/asfasf/asfasf'))
102
- // console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', '../../model/selectors/getSidebarItems'))
111
+ // 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-big-react-app-plugin",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "description": "plugin for prod proj",
5
5
  "keywords": [
6
6
  "eslint",