eslint-plugin-big-react-app-plugin 0.1.0 → 0.1.2

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,58 @@
1
+ "use strict";
2
+ const {isPathRelative} = require("../helpers")
3
+ module.exports = {
4
+ meta: {
5
+ type: null,
6
+ docs: {
7
+ description: "description",
8
+ category: "Fill me in",
9
+ recommended: false,
10
+ url: null,
11
+ },
12
+ fixable: null,
13
+ schema: [
14
+ {
15
+ type:"object",
16
+ properties:
17
+ {
18
+ alias:{
19
+ type: 'string'
20
+ }
21
+ }
22
+ }
23
+ ],
24
+ },
25
+
26
+
27
+ create(context) {
28
+ const checkingLayers = {
29
+ "entities":"entities",
30
+ "features":"features",
31
+ "pages":"pages",
32
+ "widgets":"widgets",
33
+ }
34
+ const alias = context.options[0]?.alias ?? "";
35
+ return {
36
+ ImportDeclaration(node) {
37
+ // example app/entities/Article
38
+ const value = node.source.value;
39
+ const importTo = alias ? value.replace(`${alias}/`, "") : value;
40
+ if(isPathRelative(importTo)){
41
+ return;
42
+ }
43
+ //[enteties, article, ... далее еще что-то может быть]
44
+ const segments = importTo.split('/')
45
+ const layer = segments[0]//получаем слой
46
+ if(!checkingLayers[layer]){
47
+ return;
48
+ }
49
+
50
+ const isImportNotFromPublicApi = segments.lenght > 2;
51
+
52
+ if(isImportNotFromPublicApi) {
53
+ context.report({node: node, message: 'Абсолютный импорт разрешен только из Public Api(index.ts)'});
54
+ }
55
+ }
56
+ };
57
+ },
58
+ };
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ const {isPathRelative} = require("../helpers")
3
+ module.exports = {
4
+ meta: {
5
+ type: null,
6
+ docs: {
7
+ description: "description",
8
+ category: "Fill me in",
9
+ recommended: false,
10
+ url: null,
11
+ },
12
+ fixable: null,
13
+ schema: [
14
+ {
15
+ type: 'object',
16
+ properties: {
17
+ alias: {
18
+ type: 'string'
19
+ },
20
+ testFilesPatterns: {
21
+ type: 'array'
22
+ }
23
+ }
24
+ }
25
+ ],
26
+ },
27
+
28
+
29
+ create(context) {
30
+ const checkingLayers = {
31
+ "entities":"entities",
32
+ "features":"features",
33
+ "pages":"pages",
34
+ "widgets":"widgets",
35
+ }
36
+ const alias = context.options[0]?.alias ?? "";
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
+ if(isPathRelative(importTo)){
43
+ return;
44
+ }
45
+ //[enteties, article, ... далее еще что-то может быть]
46
+ const segments = importTo.split('/')
47
+ const layer = segments[0]//получаем слой
48
+ if(!checkingLayers[layer]){
49
+ return;
50
+ }
51
+
52
+ const isImportNotFromPublicApi = segments.lenght > 2;
53
+
54
+ if(isImportNotFromPublicApi) {
55
+ context.report({node: node, message: 'Абсолютный импорт разрешен только из Public Api(index.ts)'});
56
+ }
57
+ }
58
+ };
59
+ },
60
+ };
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "eslint-plugin-big-react-app-plugin",
3
+ "version": "0.1.1",
4
+ "description": "plugin for prod proj",
5
+ "keywords": [
6
+ "eslint",
7
+ "eslintplugin",
8
+ "eslint-plugin"
9
+ ],
10
+ "author": "Vasilii",
11
+ "main": "lib/index.js",
12
+ "scripts": {
13
+ "lint": "eslint .",
14
+ "test": "mocha tests --recursive"
15
+ },
16
+ "dependencies": {
17
+ "requireindex": "^1.2.0"
18
+ },
19
+ "devDependencies": {
20
+ "eslint": "^8.0.1",
21
+ "eslint-plugin-eslint-plugin": "^4.0.1",
22
+ "eslint-plugin-node": "^11.1.0",
23
+ "mocha": "^9.1.3"
24
+ },
25
+ "engines": {
26
+ "node": "12.x || 14.x || >= 16"
27
+ },
28
+ "peerDependencies": {
29
+ "eslint": ">=6"
30
+ },
31
+ "license": "ISC"
32
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "eslint-plugin-big-react-app-plugin",
3
+ "version": "0.1.2",
4
+ "description": "plugin for prod proj",
5
+ "keywords": [
6
+ "eslint",
7
+ "eslintplugin",
8
+ "eslint-plugin"
9
+ ],
10
+ "author": "Vasilii",
11
+ "main": "lib/index.js",
12
+ "scripts": {
13
+ "lint": "eslint .",
14
+ "test": "mocha tests --recursive"
15
+ },
16
+ "dependencies": {
17
+ "requireindex": "^1.2.0"
18
+ },
19
+ "devDependencies": {
20
+ "eslint": "^8.0.1",
21
+ "eslint-plugin-eslint-plugin": "^4.0.1",
22
+ "eslint-plugin-node": "^11.1.0",
23
+ "mocha": "^9.1.3"
24
+ },
25
+ "engines": {
26
+ "node": "12.x || 14.x || >= 16"
27
+ },
28
+ "peerDependencies": {
29
+ "eslint": ">=6"
30
+ },
31
+ "license": "ISC"
32
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * @fileoverview public API path checker
3
+ * @author vasilii
4
+ */
5
+ "use strict";
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ const rule = require("../../../lib/rules/public-api-imports"),
12
+ RuleTester = require("eslint").RuleTester;
13
+
14
+
15
+ //------------------------------------------------------------------------------
16
+ // Tests
17
+ //------------------------------------------------------------------------------
18
+
19
+ const ruleTester = new RuleTester({
20
+ parserOptions: {ecmaVersion: 6, sourceType: 'module'}
21
+ });
22
+
23
+ const aliasOptions = [
24
+ {
25
+ alias: '@'
26
+ }
27
+ ]
28
+
29
+ ruleTester.run("public-api-imports", rule, {
30
+ valid: [
31
+ {
32
+ code: "import { addCommentFormActions, addCommentFormReducer } from '../../model/slices/addCommentFormSlice'",
33
+ errors: [],
34
+ },
35
+ {
36
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article'",
37
+ errors: [],
38
+ options: aliasOptions,
39
+ },
40
+ {
41
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\file.test.ts',
42
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
43
+ errors: [],
44
+ options: [{
45
+ alias: '@',
46
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
47
+ }],
48
+ },
49
+ {
50
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
51
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
52
+ errors: [],
53
+ options: [{
54
+ alias: '@',
55
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
56
+ }],
57
+ }
58
+ ],
59
+
60
+ invalid: [
61
+ {
62
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/model/file.ts'",
63
+ errors: [{ message: "Абсолютный импорт разрешен только из Public API (index.ts)"}],
64
+ options: aliasOptions,
65
+ },
66
+ {
67
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
68
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing/file.tsx'",
69
+ errors: [{message: 'Абсолютный импорт разрешен только из Public API (index.ts)'}],
70
+ options: [{
71
+ alias: '@',
72
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
73
+ }],
74
+ },
75
+ {
76
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\forbidden.ts',
77
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
78
+ errors: [{message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'}],
79
+ options: [{
80
+ alias: '@',
81
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
82
+ }],
83
+ }
84
+ ],
85
+ });
86
+
@@ -10,7 +10,19 @@ module.exports = {
10
10
  url: null,
11
11
  },
12
12
  fixable: null,
13
- schema: [],
13
+ schema: [
14
+ {
15
+ type: 'object',
16
+ properties: {
17
+ alias: {
18
+ type: 'string'
19
+ },
20
+ testFilesPatterns: {
21
+ type: 'array'
22
+ }
23
+ }
24
+ }
25
+ ],
14
26
  },
15
27
 
16
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-big-react-app-plugin",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "plugin for prod proj",
5
5
  "keywords": [
6
6
  "eslint",
@@ -17,20 +17,70 @@ const rule = require("../../../lib/rules/public-api-imports"),
17
17
  //------------------------------------------------------------------------------
18
18
 
19
19
  const ruleTester = new RuleTester({
20
- parserOptions:{ecmaVersion:6, sourceType:'module'}
20
+ parserOptions: {ecmaVersion: 6, sourceType: 'module'}
21
21
  });
22
22
 
23
+ const aliasOptions = [
24
+ {
25
+ alias: '@'
26
+ }
27
+ ]
23
28
 
24
29
  ruleTester.run("public-api-imports", rule, {
25
-
26
30
  valid: [
27
-
31
+ {
32
+ code: "import { addCommentFormActions, addCommentFormReducer } from '../../model/slices/addCommentFormSlice'",
33
+ errors: [],
34
+ },
35
+ {
36
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article'",
37
+ errors: [],
38
+ options: aliasOptions,
39
+ },
40
+ {
41
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\file.test.ts',
42
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
43
+ errors: [],
44
+ options: [{
45
+ alias: '@',
46
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
47
+ }],
48
+ },
49
+ {
50
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
51
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
52
+ errors: [],
53
+ options: [{
54
+ alias: '@',
55
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
56
+ }],
57
+ }
28
58
  ],
29
59
 
30
60
  invalid: [
31
61
  {
32
- code: "",
33
- errors: [{ message: "Fill me in.", type: "Me too" }],
62
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/model/file.ts'",
63
+ errors: [{ message: "Абсолютный импорт разрешен только из Public API (index.ts)"}],
64
+ options: aliasOptions,
65
+ },
66
+ {
67
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
68
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing/file.tsx'",
69
+ errors: [{message: 'Абсолютный импорт разрешен только из Public API (index.ts)'}],
70
+ options: [{
71
+ alias: '@',
72
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
73
+ }],
34
74
  },
75
+ {
76
+ filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\forbidden.ts',
77
+ code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
78
+ errors: [{message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'}],
79
+ options: [{
80
+ alias: '@',
81
+ testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
82
+ }],
83
+ }
35
84
  ],
36
85
  });
86
+