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