eslint-plugin-path-checker-relative 0.0.7 → 0.0.8

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.
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @fileoverview fix slice layer
3
+ * @author layer-imports
4
+ */
5
+ "use strict";
6
+ const path = require("path");
7
+ const isPathRelative = require("../helpers");
8
+ const micromatch = require("micromatch");
9
+ //------------------------------------------------------------------------------
10
+ // Rule Definition
11
+ //------------------------------------------------------------------------------
12
+
13
+ /** @type {import('eslint').Rule.RuleModule} */
14
+ module.exports = {
15
+ meta: {
16
+ type: null, // `problem`, `suggestion`, or `layout`
17
+ docs: {
18
+ description: "fix slice layer",
19
+ recommended: false,
20
+ url: null, // URL to the documentation page for this rule
21
+ },
22
+ fixable: null, // Or `code` or `whitespace`
23
+ schema: [
24
+ {
25
+ type: "object",
26
+ properties: {
27
+ alias: {
28
+ type: "string",
29
+ },
30
+ testFilesPattern: {
31
+ type: "array",
32
+ },
33
+ },
34
+ },
35
+ ], // Add a schema if the rule has options
36
+ messages: {
37
+ "Слой может импортировать в себя только нижележащие слои (shared, entities, features, widgets, pages, app)":
38
+ "Слой может импортировать в себя только нижележащие слои (shared, entities, features, widgets, pages, app)",
39
+ }, // Add messageId and message
40
+ },
41
+
42
+ create(context) {
43
+ const layers = {
44
+ app: ["pages", "widgets", "features", "shared", "entities"],
45
+ pages: ["widgets", "features", "shared", "entities"],
46
+ widgets: ["features", "shared", "entities"],
47
+ features: ["shared", "entities"],
48
+ entities: ["shared", "entities"],
49
+ shared: ["shared"],
50
+ };
51
+
52
+ const availableLayers = {
53
+ app: "app",
54
+ entities: "entities",
55
+ features: "features",
56
+ pages: "pages",
57
+ shared: "shared",
58
+ widgets: "widgets",
59
+ };
60
+
61
+ const { alias = "", ignoreImportPatterns = [] } = context.options[0] ?? {};
62
+
63
+ const getCurrentFileLayer = () => {
64
+ const currentFile = context.filename;
65
+
66
+ const normalizedPath = path.toNamespacedPath(currentFile);
67
+ const projectPath = normalizedPath?.split("src")[1];
68
+
69
+ const segment = projectPath?.split("/");
70
+
71
+ return segment?.[1];
72
+ };
73
+
74
+ const getImportLayer = (value) => {
75
+ const importPath = alias ? value.replace(`${alias}/`, "") : value;
76
+ const segment = importPath?.split("/");
77
+ return segment?.[0];
78
+ };
79
+
80
+ return {
81
+ ImportDeclaration(node) {
82
+ const importPath = node.source.value;
83
+ const currentFileLayer = getCurrentFileLayer();
84
+ const importLayer = getImportLayer(importPath);
85
+
86
+ if (isPathRelative(importPath)) {
87
+ return;
88
+ }
89
+
90
+ if (
91
+ !availableLayers[importLayer] ||
92
+ !availableLayers[currentFileLayer]
93
+ ) {
94
+ return;
95
+ }
96
+
97
+ const isIgnored = ignoreImportPatterns.some((pattern) =>
98
+ micromatch.isMatch(importPath, pattern)
99
+ );
100
+
101
+ if (isIgnored) {
102
+ return;
103
+ }
104
+
105
+ if (!layers[currentFileLayer]?.includes(importLayer)) {
106
+ context.report({
107
+ node: node,
108
+ messageId:
109
+ "Слой может импортировать в себя только нижележащие слои (shared, entities, features, widgets, pages, app)",
110
+ });
111
+ }
112
+ },
113
+ };
114
+ },
115
+ };
@@ -52,7 +52,7 @@ module.exports = {
52
52
 
53
53
  const layers = {
54
54
  'entities': 'entities',
55
- 'feature': 'feature',
55
+ 'features': 'features',
56
56
  'pages': 'pages',
57
57
  'shared': 'shared',
58
58
  'widgets': 'widgets',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-path-checker-relative",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "plugin for production project",
5
5
  "keywords": [
6
6
  "eslint",