eslint-plugin-path-checker-relative 0.0.4 → 0.0.6

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,3 @@
1
+ module.exports = function isPathRelative(path) {
2
+ return path === '.' || path.startsWith('./') || path.startsWith('../');
3
+ }
@@ -4,6 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
  const path = require("path");
7
+ const isPathRelative = require('../helpers')
7
8
  //------------------------------------------------------------------------------
8
9
  // Rule Definition
9
10
  //------------------------------------------------------------------------------
@@ -49,11 +50,6 @@ module.exports = {
49
50
  },
50
51
  };
51
52
 
52
-
53
- function isPathRelative(path) {
54
- return path === '.' || path.startsWith('./') || path.startsWith('../');
55
- }
56
-
57
53
  const layers = {
58
54
  'entities': 'entities',
59
55
  'feature': 'feature',
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @fileoverview description
3
+ * @author evgeniy
4
+ */
5
+ "use strict";
6
+
7
+ const path = require("path");
8
+
9
+ const isPathRelative = require("../helpers");
10
+
11
+ /** @type {import('eslint').Rule.RuleModule} */
12
+ module.exports = {
13
+ meta: {
14
+ type: null, // `problem`, `suggestion`, or `layout`
15
+ docs: {
16
+ description: "description",
17
+ recommended: false,
18
+ url: null, // URL to the documentation page for this rule
19
+ },
20
+ fixable: null, // Or `code` or `whitespace`
21
+ schema: [
22
+ {
23
+ type: "object",
24
+ properties: {
25
+ alias: {
26
+ type: "string",
27
+ },
28
+ },
29
+ },
30
+ ],
31
+ messages: {
32
+ "Абсолютный импорт разрешен только из Public API (index.ts)":
33
+ "Абсолютный импорт разрешен только из Public API (index.ts)",
34
+ },
35
+ },
36
+
37
+ create(context) {
38
+ const alias = context.options[0]?.alias || "";
39
+
40
+ const checkingLayers = {
41
+ entities: "entities",
42
+ feature: "feature",
43
+ pages: "pages",
44
+ widgets: "widgets",
45
+ };
46
+
47
+ return {
48
+ ImportDeclaration(node) {
49
+ const value = node.source.value;
50
+ const importTo = alias ? value.replace(`${alias}/`, "") : value;
51
+
52
+ if (isPathRelative(importTo)) {
53
+ return;
54
+ }
55
+
56
+ const segment = importTo.split("/");
57
+
58
+ const layer = segment[0];
59
+
60
+ if (!checkingLayers[layer]) {
61
+ return;
62
+ }
63
+
64
+ const isImportNotFromPublicApi = segment.length > 2;
65
+
66
+ if (isImportNotFromPublicApi) {
67
+ context.report({
68
+ node,
69
+ messageId:
70
+ "Абсолютный импорт разрешен только из Public API (index.ts)",
71
+ });
72
+ }
73
+ },
74
+ };
75
+ },
76
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-path-checker-relative",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "plugin for production project",
5
5
  "keywords": [
6
6
  "eslint",