eslint-plugin-import-path-correct 0.0.3 → 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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  const { isPathRelative } = require("../helpers");
4
+ const micromatch = require("micromatch");
4
5
 
5
6
  /** @type {import('eslint').Rule.RuleModule} */
6
7
  module.exports = {
@@ -15,7 +16,13 @@ module.exports = {
15
16
  schema: [
16
17
  {
17
18
  type: "object",
18
- properties: { alias: { type: "string", description: "some" } },
19
+ properties: {
20
+ alias: { type: "string", description: "some" },
21
+ testFilesPatterns: {
22
+ type: "array",
23
+ description: "description",
24
+ },
25
+ },
19
26
  additionalProperties: false,
20
27
  },
21
28
  ], // Add a schema if the rule has options
@@ -23,17 +30,20 @@ module.exports = {
23
30
  {
24
31
  // Add this property
25
32
  alias: "", // Default value for alias
33
+ testFilesPatterns: [""],
26
34
  },
27
35
  ],
28
36
  messages: {
29
37
  publicApiRequired:
30
38
  "Абсолютный импорт разрешен только из Publick API(index.ts)",
39
+ testingPublicApi:
40
+ "Тестовые данных необходимо импортировать из publicApi/testing.ts",
31
41
  },
32
42
  },
33
43
 
34
44
  create(context) {
35
- const options = context.options[0] || {};
36
- const alias = options.alias || "";
45
+ // const options = context.options[0] || {};
46
+ const { alias = "", testFilesPatterns = [] } = context.options[0] ?? {};
37
47
 
38
48
  const checkingLayers = {
39
49
  entites: "entites",
@@ -59,13 +69,29 @@ module.exports = {
59
69
  }
60
70
 
61
71
  const isImportNotFromPublicApi = segments.length > 2;
72
+ const isTestingPublicApi =
73
+ segments[2] === "testing" && segments.length < 4;
62
74
 
63
- if (isImportNotFromPublicApi) {
75
+ if (isImportNotFromPublicApi && !isTestingPublicApi) {
64
76
  context.report({
65
77
  node,
66
78
  messageId: "publicApiRequired",
67
79
  });
68
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
+ }
69
95
  },
70
96
  };
71
97
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-import-path-correct",
3
- "version": "0.0.3",
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",