eslint-plugin-import-path-correct 0.0.2 → 0.0.4

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,7 @@
1
+ function isPathRelative(path) {
2
+ return path === "." || path.startsWith("./") || path.startsWith("../");
3
+ }
4
+
5
+ module.exports = {
6
+ isPathRelative,
7
+ };
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  const path = require("path");
4
+ const { isPathRelative } = require("../helpers");
4
5
 
5
6
  /** @type {import('eslint').Rule.RuleModule} */
6
7
  module.exports = {
7
8
  meta: {
8
- type: null, // `problem`, `suggestion`, or `layout`
9
+ type: "problem", // `problem`, `suggestion`, or `layout`
9
10
  docs: {
10
11
  description: "feature sliced relative path",
11
12
  recommended: false,
@@ -57,17 +58,13 @@ module.exports = {
57
58
  };
58
59
 
59
60
  const layers = {
60
- entities: "entities",
61
+ entites: "entites",
61
62
  features: "features",
62
63
  shared: "shared",
63
64
  pages: "pages",
64
65
  widgets: "widgets",
65
66
  };
66
67
 
67
- function isPathRelative(path) {
68
- return path === "." || path.startsWith("./") || path.startsWith("../");
69
- }
70
-
71
68
  function shouldBeRelative(from, to) {
72
69
  if (isPathRelative(to)) {
73
70
  return false;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ const { isPathRelative } = require("../helpers");
4
+ const micromatch = require("micromatch");
5
+
6
+ /** @type {import('eslint').Rule.RuleModule} */
7
+ module.exports = {
8
+ meta: {
9
+ type: "problem", // `problem`, `suggestion`, or `layout`
10
+ docs: {
11
+ description: "description",
12
+ recommended: false,
13
+ url: null, // URL to the documentation page for this rule
14
+ },
15
+ fixable: null, // Or `code` or `whitespace`
16
+ schema: [
17
+ {
18
+ type: "object",
19
+ properties: {
20
+ alias: { type: "string", description: "some" },
21
+ testFilesPatterns: {
22
+ type: "array",
23
+ description: "description",
24
+ },
25
+ },
26
+ additionalProperties: false,
27
+ },
28
+ ], // Add a schema if the rule has options
29
+ defaultOptions: [
30
+ {
31
+ // Add this property
32
+ alias: "", // Default value for alias
33
+ testFilesPatterns: [""],
34
+ },
35
+ ],
36
+ messages: {
37
+ publicApiRequired:
38
+ "Абсолютный импорт разрешен только из Publick API(index.ts)",
39
+ testingPublicApi:
40
+ "Тестовые данных необходимо импортировать из publicApi/testing.ts",
41
+ },
42
+ },
43
+
44
+ create(context) {
45
+ // const options = context.options[0] || {};
46
+ const { alias = "", testFilesPatterns = [] } = context.options[0] ?? {};
47
+
48
+ const checkingLayers = {
49
+ entites: "entites",
50
+ features: "features",
51
+ pages: "pages",
52
+ widgets: "widgets",
53
+ };
54
+
55
+ return {
56
+ ImportDeclaration(node) {
57
+ const value = node.source.value;
58
+ const importTo = alias ? value.replace(`${alias}/`, "") : value;
59
+
60
+ if (isPathRelative(importTo)) {
61
+ return;
62
+ }
63
+
64
+ const segments = importTo.split("/");
65
+
66
+ const layer = segments[0];
67
+ if (!checkingLayers[layer]) {
68
+ return;
69
+ }
70
+
71
+ const isImportNotFromPublicApi = segments.length > 2;
72
+ const isTestingPublicApi =
73
+ segments[2] === "testing" && segments.length < 4;
74
+
75
+ if (isImportNotFromPublicApi && !isTestingPublicApi) {
76
+ context.report({
77
+ node,
78
+ messageId: "publicApiRequired",
79
+ });
80
+ }
81
+
82
+ if (isTestingPublicApi) {
83
+ const currentFilePath = context.filename;
84
+ const isCurrentFileTesting = testFilesPatterns.some((pattern) =>
85
+ micromatch.isMatch(currentFilePath, pattern),
86
+ );
87
+
88
+ if (!isCurrentFileTesting) {
89
+ context.report({
90
+ node,
91
+ messageId: "testingPublicApi",
92
+ });
93
+ }
94
+ }
95
+ },
96
+ };
97
+ },
98
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-import-path-correct",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "plugin for paths",
5
5
  "keywords": [
6
6
  "eslint",
@@ -21,11 +21,12 @@
21
21
  "update:eslint-docs": "eslint-doc-generator"
22
22
  },
23
23
  "dependencies": {
24
+ "micromatch": "^4.0.8",
24
25
  "requireindex": "^1.2.0"
25
26
  },
26
27
  "devDependencies": {
27
- "eslint": "^9.0.0",
28
28
  "@eslint/js": "^9.0.0",
29
+ "eslint": "^9.0.0",
29
30
  "eslint-doc-generator": "^2.0.0",
30
31
  "eslint-plugin-eslint-plugin": "^7.3.2",
31
32
  "eslint-plugin-n": "^17.0.0",