eslint-plugin-gapone-plugin 0.0.8 → 0.0.10

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,4 +1,5 @@
1
1
  const { isPathRelative } = require('../helpers');
2
+ const micromatch = require('micromatch');
2
3
 
3
4
  /** @type {import('eslint').Rule.RuleModule} */
4
5
  module.exports = {
@@ -17,17 +18,22 @@ module.exports = {
17
18
  alias: {
18
19
  type: 'string',
19
20
  },
21
+ testFilesPatterns: {
22
+ type: 'array',
23
+ },
20
24
  },
21
25
  },
22
26
  ], // Add a schema if the rule has options
23
27
  messages: {
24
28
  noPublicApiImports:
25
29
  'Абсолютный импорт разрешен только из Public Api (index.ts)',
30
+ noTestingPublicApiImports:
31
+ 'Тестовые данные необходимо импортировать из Public Api (testing.ts)',
26
32
  }, // Add messageId and message
27
33
  },
28
34
 
29
35
  create(context) {
30
- const alias = context.options[0]?.alias || '';
36
+ const { alias = '', testFilesPatterns = [] } = context.options[0] ?? {};
31
37
 
32
38
  const checkingLayers = {
33
39
  entities: 'entities',
@@ -45,6 +51,7 @@ module.exports = {
45
51
  return;
46
52
  }
47
53
 
54
+ // [entities, article, model, types]
48
55
  const segments = importTo.split('/');
49
56
 
50
57
  const layer = segments[0];
@@ -55,12 +62,32 @@ module.exports = {
55
62
 
56
63
  const isImportNotFromPublickApi = segments.length > 2;
57
64
 
58
- if (isImportNotFromPublickApi) {
65
+ // [entities, article, testing]
66
+ const isTestingPublickApi =
67
+ segments[2] === 'testing' && segments.length < 4;
68
+
69
+ if (isImportNotFromPublickApi && !isTestingPublickApi) {
59
70
  context.report({
60
71
  node,
61
72
  messageId: 'noPublicApiImports',
62
73
  });
63
74
  }
75
+
76
+ if (isTestingPublickApi) {
77
+ const currentFilePath = context.getFilename();
78
+
79
+ const isCurrentFileTesting = testFilesPatterns.some(
80
+ (pattern) =>
81
+ micromatch.isMatch(currentFilePath, pattern)
82
+ );
83
+
84
+ if (!isCurrentFileTesting) {
85
+ context.report({
86
+ node,
87
+ messageId: 'noTestingPublicApiImports',
88
+ });
89
+ }
90
+ }
64
91
  },
65
92
  };
66
93
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-gapone-plugin",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "plugin for production project",
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": "^6.0.0",
31
32
  "eslint-plugin-n": "^17.0.0",