eslint-plugin-big-react-app-plugin 0.2.10 → 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,92 +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
- try {
32
+ try {
34
33
  // example app/entities/Article
35
- const value = node.source.value;
36
- const importTo = alias ? value.replace(`${alias}/`, "") : value;
34
+ const value = node.source.value;
35
+ const importTo = alias ? value.replace(`${alias}/`, "") : value;
37
36
 
38
- // example C:\Users\tim\Desktop\javascript\production_project\src\entities\Article
39
- const fromFilename = context.getFilename();
40
- if(shouldBeRelative(fromFilename, importTo)) {
41
- context.report({node:
42
- node,
43
- message: 'В рамках одного слайса все пути должны быть относительными',
44
- fix:(fixer)=>{
45
- const normalizedPath = getNormalizedFilePath(fromFilename).split('/').slice(0, -1).join('/')//enteties/Article/Artcile.tsx файл в который делаем импорт и также убираем концовку
46
- let relativePath = path.relative(normalizedPath, `/${importTo}`).split('\\').join('/')
47
- if(!relativePath.startsWith('.')){
48
- 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;
49
55
  }
50
- return fixer.replaceText(node.source, `'${relativePath}'`)
51
- }
52
- })
56
+ return fixer.replaceText(node.source, `'${relativePath}'`);
57
+ },
58
+ });
59
+ }
60
+ } catch (error) {
61
+ console.log(error);
53
62
  }
54
- } catch (error) {
55
- console.log(error)
56
- }
57
- }
63
+ },
58
64
  };
59
65
  },
60
66
  };
61
67
 
62
68
  const layers = {
63
- "entities":"entities",
64
- "features":"features",
65
- "pages":"pages",
66
- "shared":"shared",
67
- "widgets":"widgets",
68
- }
69
- function getNormalizedFilePath (from){
70
- const normalizationPath = path.toNamespacedPath(from);
71
- const projFrom = normalizationPath.split('src')[1]
72
- 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("/");
73
79
  }
74
- function shouldBeRelative (from, to){
75
- if(isPathRelative(to)){
76
- return false
80
+ function shouldBeRelative(from, to) {
81
+ if (isPathRelative(to)) {
82
+ return false;
77
83
  }
78
- const toArray = to.split('/')
84
+ const toArray = to.split("/");
79
85
  //app/entities/Article
80
86
  const toLayer = toArray[0];
81
87
  //"C:\Users\ADMIN\Documents\GitHub\ulbi\big-app-react\src\entities\Article\model\types\artcile.ts"
82
88
  const toSlice = toArray[1];
83
- if(!toLayer || !toSlice || !layers[toLayer]){
84
- return false
89
+ if (!toLayer || !toSlice || !layers[toLayer]) {
90
+ return false;
85
91
  }
86
- //нормализуем путь
87
- const projFrom = getNormalizedFilePath(from)
88
- const fromArray = projFrom.split('/')
89
-
92
+ //нормализуем путь
93
+ const projFrom = getNormalizedFilePath(from);
94
+ const fromArray = projFrom.split("/");
95
+
90
96
  const fromLayer = fromArray[1];
91
97
  const fromSlice = fromArray[2];
92
- if(!fromLayer || !fromSlice || !layers[fromLayer]){
93
- return false
98
+ if (!fromLayer || !fromSlice || !layers[fromLayer]) {
99
+ return false;
94
100
  }
95
-
96
- return toSlice === fromSlice && toLayer === fromLayer
97
- }
98
101
 
102
+ return toSlice === fromSlice && toLayer === fromLayer;
103
+ }
99
104
 
100
105
  // console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/Article/fasfasfas'))
101
106
  // console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/ASdasd/fasfasfas'))
@@ -103,4 +108,4 @@ function shouldBeRelative (from, to){
103
108
  // console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\features\\Article', 'features/Article/fasfasfas'))
104
109
  // console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'app/index.tsx'))
105
110
  // console.log(shouldBeRelative('C:/Users/tim/Desktop/javascript/GOOD_COURSE_test/src/entities/Article', 'entities/Article/asfasf/asfasf'))
106
- // 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.10",
3
+ "version": "0.2.11",
4
4
  "description": "plugin for prod proj",
5
5
  "keywords": [
6
6
  "eslint",