eslint-plugin-big-react-app-plugin 0.1.1 → 0.1.3

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,6 @@
1
+ const isPathRelative = (path)=>{
2
+ return path = path.startsWith('.' || './' || '.ю//')
3
+ }
4
+ module.exports = {
5
+ isPathRelative
6
+ }
@@ -0,0 +1,6 @@
1
+ const isPathRelative = (path)=>{
2
+ return path = path.startsWith('.' || './' || '..//')
3
+ }
4
+ module.exports = {
5
+ isPathRelative
6
+ }
@@ -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,61 @@
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
+ //если путь относительный то выходим
43
+ if(isPathRelative(importTo)){
44
+ return;
45
+ }
46
+ //[enteties, article, ... далее еще что-то может быть]
47
+ const segments = importTo.split('/')
48
+ const layer = segments[0]//получаем слой
49
+ if(!checkingLayers[layer]){
50
+ return;
51
+ }
52
+
53
+ const isImportNotFromPublicApi = segments.lenght > 2;
54
+
55
+ if(isImportNotFromPublicApi) {
56
+ context.report({node: node, message: 'Абсолютный импорт разрешен только из Public Api(index.ts)'});
57
+ }
58
+ }
59
+ };
60
+ },
61
+ };
@@ -0,0 +1,62 @@
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
+ //если путь относительный то выходим
43
+ if(isPathRelative(importTo)){
44
+ return;
45
+ }
46
+ //[enteties, article, ... далее еще что-то может быть]
47
+ const segments = importTo.split('/')
48
+ const layer = segments[0]//получаем слой
49
+ // проверяем что есть слой из массива
50
+ if(!checkingLayers[layer]){
51
+ return;
52
+ }
53
+
54
+ const isImportNotFromPublicApi = segments.lenght > 2;
55
+
56
+ if(isImportNotFromPublicApi) {
57
+ context.report({node: node, message: 'Абсолютный импорт разрешен только из Public Api(index.ts)'});
58
+ }
59
+ }
60
+ };
61
+ },
62
+ };
@@ -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,32 @@
1
+ {
2
+ "name": "eslint-plugin-big-react-app-plugin",
3
+ "version": "0.1.3",
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
+
@@ -1,5 +1,5 @@
1
1
  const isPathRelative = (path)=>{
2
- return path = path.startsWith('.' || './' || './/')
2
+ return path = path.startsWith('.' || './' || '..//')
3
3
  }
4
4
  module.exports = {
5
5
  isPathRelative
@@ -11,15 +11,17 @@ module.exports = {
11
11
  },
12
12
  fixable: null,
13
13
  schema: [
14
- {
15
- type:"object",
16
- properties:
17
- {
18
- alias:{
19
- type: 'string'
14
+ {
15
+ type: 'object',
16
+ properties: {
17
+ alias: {
18
+ type: 'string'
19
+ },
20
+ testFilesPatterns: {
21
+ type: 'array'
20
22
  }
21
23
  }
22
- }
24
+ }
23
25
  ],
24
26
  },
25
27
 
@@ -37,12 +39,14 @@ module.exports = {
37
39
  // example app/entities/Article
38
40
  const value = node.source.value;
39
41
  const importTo = alias ? value.replace(`${alias}/`, "") : value;
42
+ //если путь относительный то выходим
40
43
  if(isPathRelative(importTo)){
41
44
  return;
42
45
  }
43
46
  //[enteties, article, ... далее еще что-то может быть]
44
47
  const segments = importTo.split('/')
45
48
  const layer = segments[0]//получаем слой
49
+ // проверяем что есть слой из массива
46
50
  if(!checkingLayers[layer]){
47
51
  return;
48
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-big-react-app-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
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
+