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