eslint-plugin-big-react-app-plugin 0.0.0 → 0.0.2

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,24 +1,57 @@
1
+ const path = require('path');
1
2
  "use strict";
2
- module.exports = {
3
- meta: {
4
- type: null, // `problem`, `suggestion`, or `layout`
5
- docs: {
6
- description: "feature sliced relative path checker",
7
- category: "Fill me in",
8
- recommended: false,
9
- url: null, // URL to the documentation page for this rule
10
- },
11
- fixable: null, // Or `code` or `whitespace`
12
- schema: [], // Add a schema if the rule has options
13
- },
14
-
15
- create(context) {
16
- return {
17
- ImportDeclaration(node){
18
- const importTo = node.source.value
19
- const importFrom = context.getFilename()
20
- context.report(node, "Линтер работает и ругается")
21
- }
22
- };
3
+ export const meta = {
4
+ type: null, // `problem`, `suggestion`, or `layout`
5
+ docs: {
6
+ description: "feature sliced relative path checker",
7
+ category: "Fill me in",
8
+ recommended: false,
9
+ url: null, // URL to the documentation page for this rule
23
10
  },
11
+ fixable: null, // Or `code` or `whitespace`
12
+ schema: [], // Add a schema if the rule has options
24
13
  };
14
+ export function create(context) {
15
+ return {
16
+ ImportDeclaration(node) {
17
+ const importTo = node.source.value;
18
+ const importFrom = context.getFilename();
19
+ if(shouldBeRelative(importFrom, importTo)){
20
+ context.report(node, "В рамках одного модуля должны использоваться относительные импорты");
21
+ }
22
+ }
23
+ };
24
+ }
25
+ const layers = {
26
+ "entities":"entities",
27
+ "features":"features",
28
+ "pages":"pages",
29
+ "shared":"shared",
30
+ "widgets":"widgets",
31
+ }
32
+ const shouldBeRelative = (from, to)=>{
33
+ if(pathRelative(to)){
34
+ return false
35
+ }
36
+ const toArray = to.split('/')
37
+ //app/entities/Article
38
+ const toLayer = toArray[0];
39
+ //"C:\Users\ADMIN\Documents\GitHub\ulbi\big-app-react\src\entities\Article\model\types\artcile.ts"
40
+ const toSlice = toArray[1];
41
+ if(!toLayer || !toSlice || layers[toArray]){
42
+ return false
43
+ }
44
+ //нормализуем путь
45
+ const normalizationPath = path.toNamespacedPath(from);
46
+ const fromArray = normalizationPath.split('\\')[1]
47
+
48
+ const fromLayer = fromArray[1];
49
+ const fromSlice = fromArray[2];
50
+ if(!fromLayer || !fromSlice || layers[fromArray]){
51
+ return false
52
+ }
53
+ return toSlice === fromSlice && toLayer === fromLayer
54
+ }
55
+ const pathRelative = (path)=>{
56
+ return path = path.startWith('.' || './' || './/')
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-big-react-app-plugin",
3
- "version": "0.0.0",
3
+ "version": "0.0.2",
4
4
  "description": "plugin for prod proj",
5
5
  "keywords": [
6
6
  "eslint",