eslint-plugin-big-react-app-plugin 0.1.5 → 0.1.6

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,76 @@
1
+ "use strict";
2
+ const micromatch = require("micromatch");
3
+ const {isPathRelative} = require("../helpers")
4
+ const path = require("path");
5
+ module.exports = {
6
+ meta: {
7
+ type: null,
8
+ docs: {
9
+ description: "description",
10
+ category: "Fill me in",
11
+ recommended: false,
12
+ url: null,
13
+ },
14
+ fixable: null,
15
+ schema: [
16
+ {
17
+ type: 'object',
18
+ properties: {
19
+ alias: {
20
+ type: 'string'
21
+ },
22
+ testFilesPatterns: {
23
+ type: 'array'
24
+ }
25
+ }
26
+ }
27
+ ],
28
+ },
29
+
30
+
31
+ create(context) {
32
+ const checkingLayers = {
33
+ "entities":"entities",
34
+ "features":"features",
35
+ "pages":"pages",
36
+ "widgets":"widgets",
37
+ }
38
+ const {alias='', testFilesPatterns=[]} = context.options[0] ?? {};
39
+ return {
40
+ ImportDeclaration(node) {
41
+ // example app/entities/Article
42
+ const value = node.source.value;
43
+ const importTo = alias ? value.replace(`${alias}/`, "") : value;
44
+ //если путь относительный то выходим
45
+ if(isPathRelative(importTo)){
46
+ return;
47
+ }
48
+ //[enteties, article, ... далее еще что-то может быть]
49
+ const segments = importTo.split('/')
50
+ const layer = segments[0]//получаем слой
51
+ // проверяем что есть слой из массива
52
+
53
+ //[enteties, article, testing]
54
+ const isTestingPublicApi = segments[2] === 'testing' && segments.length < 4;
55
+
56
+ if(!checkingLayers[layer]){
57
+ return;
58
+ }
59
+ const isImportNotFromPublicApi = segments.length > 2;
60
+
61
+ if(isImportNotFromPublicApi && !isTestingPublicApi ) {
62
+ context.report({node: node, message: 'Абсолютный импорт разрешен только из Public API (index.ts)'});
63
+ }
64
+
65
+ if(isTestingPublicApi){
66
+ const currentFilePath = context.getFilename();
67
+ const normalizedPath = path.toNamespacedPath(currentFilePath);
68
+ const isCurrentFileTesting = testFilesPatterns.some(pattern=>micromatch.isMatch(normalizedPath, pattern))
69
+ if(!isCurrentFileTesting){
70
+ context.report({node: node, message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'});
71
+ }
72
+ }
73
+ }
74
+ };
75
+ },
76
+ };
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ const micromatch = require("micromatch");
3
+ const {isPathRelative} = require("../helpers")
4
+ const path = require("path");
5
+ module.exports = {
6
+ meta: {
7
+ type: null,
8
+ docs: {
9
+ description: "description",
10
+ category: "Fill me in",
11
+ recommended: false,
12
+ url: null,
13
+ },
14
+ fixable: null,
15
+ schema: [
16
+ {
17
+ type: 'object',
18
+ properties: {
19
+ alias: {
20
+ type: 'string'
21
+ },
22
+ testFilesPatterns: {
23
+ type: 'array'
24
+ }
25
+ }
26
+ }
27
+ ],
28
+ },
29
+
30
+
31
+ create(context) {
32
+ const checkingLayers = {
33
+ "entities":"entities",
34
+ "features":"features",
35
+ "pages":"pages",
36
+ "widgets":"widgets",
37
+ }
38
+ const {alias='', testFilesPatterns=[]} = context.options[0] ?? {};
39
+ return {
40
+ ImportDeclaration(node) {
41
+ // example app/entities/Article
42
+ const value = node.source.value;
43
+ const importTo = alias ? value.replace(`${alias}/`, "") : value;
44
+ //если путь относительный то выходим
45
+ if(isPathRelative(importTo)){
46
+ return;
47
+ }
48
+ //[enteties, article, ... далее еще что-то может быть]
49
+ const segments = importTo.split('/')
50
+ const layer = segments[0]//получаем слой
51
+ // проверяем что есть слой из массива
52
+
53
+ //[enteties, article, testing]
54
+ const isTestingPublicApi = segments[2] === 'testing' && segments.length < 4;
55
+
56
+ if(!checkingLayers[layer]){
57
+ return;
58
+ }
59
+ const isImportNotFromPublicApi = segments.length > 2;
60
+
61
+ if(isImportNotFromPublicApi && !isTestingPublicApi ) {
62
+ context.report({node: node, message: 'Абсолютный импорт разрешен только из Public API (index.ts)'});
63
+ }
64
+
65
+ if(isTestingPublicApi){
66
+ const currentFilePath = context.getFilename();
67
+ const isCurrentFileTesting = testFilesPatterns.some(pattern=>micromatch.isMatch(normalizedPath, pattern))
68
+ if(!isCurrentFileTesting){
69
+ context.report({node: node, message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'});
70
+ }
71
+ }
72
+ }
73
+ };
74
+ },
75
+ };
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ const micromatch = require("micromatch");
3
+ const {isPathRelative} = require("../helpers")
4
+ const path = require("path");
5
+ module.exports = {
6
+ meta: {
7
+ type: null,
8
+ docs: {
9
+ description: "description",
10
+ category: "Fill me in",
11
+ recommended: false,
12
+ url: null,
13
+ },
14
+ fixable: null,
15
+ schema: [
16
+ {
17
+ type: 'object',
18
+ properties: {
19
+ alias: {
20
+ type: 'string'
21
+ },
22
+ testFilesPatterns: {
23
+ type: 'array'
24
+ }
25
+ }
26
+ }
27
+ ],
28
+ },
29
+
30
+
31
+ create(context) {
32
+ const checkingLayers = {
33
+ "entities":"entities",
34
+ "features":"features",
35
+ "pages":"pages",
36
+ "widgets":"widgets",
37
+ }
38
+ const {alias='', testFilesPatterns=[]} = context.options[0] ?? {};
39
+ return {
40
+ ImportDeclaration(node) {
41
+ // example app/entities/Article
42
+ const value = node.source.value;
43
+ const importTo = alias ? value.replace(`${alias}/`, "") : value;
44
+ //если путь относительный то выходим
45
+ if(isPathRelative(importTo)){
46
+ return;
47
+ }
48
+ //[enteties, article, ... далее еще что-то может быть]
49
+ const segments = importTo.split('/')
50
+ const layer = segments[0]//получаем слой
51
+ // проверяем что есть слой из массива
52
+
53
+ //[enteties, article, testing]
54
+ const isTestingPublicApi = segments[2] === 'testing' && segments.length < 4;
55
+
56
+ if(!checkingLayers[layer]){
57
+ return;
58
+ }
59
+ const isImportNotFromPublicApi = segments.length > 2;
60
+
61
+ if(isImportNotFromPublicApi && !isTestingPublicApi ) {
62
+ context.report({node: node, message: 'Абсолютный импорт разрешен только из Public API (index.ts)'});
63
+ }
64
+
65
+ if(isTestingPublicApi){
66
+ const currentFilePath = context.getFilename();
67
+ const isCurrentFileTesting = testFilesPatterns.some(pattern=>micromatch.isMatch(currentFilePath, pattern))
68
+ if(!isCurrentFileTesting){
69
+ context.report({node: node, message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'});
70
+ }
71
+ }
72
+ }
73
+ };
74
+ },
75
+ };
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "eslint-plugin-big-react-app-plugin",
3
+ "version": "0.1.5",
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
+ "micromatch": "^4.0.5",
18
+ "requireindex": "^1.2.0"
19
+ },
20
+ "devDependencies": {
21
+ "eslint": "^8.0.1",
22
+ "eslint-plugin-eslint-plugin": "^4.0.1",
23
+ "eslint-plugin-node": "^11.1.0",
24
+ "mocha": "^9.1.3"
25
+ },
26
+ "engines": {
27
+ "node": "12.x || 14.x || >= 16"
28
+ },
29
+ "peerDependencies": {
30
+ "eslint": ">=6"
31
+ },
32
+ "license": "ISC"
33
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "eslint-plugin-big-react-app-plugin",
3
+ "version": "0.1.6",
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
+ "micromatch": "^4.0.5",
18
+ "requireindex": "^1.2.0"
19
+ },
20
+ "devDependencies": {
21
+ "eslint": "^8.0.1",
22
+ "eslint-plugin-eslint-plugin": "^4.0.1",
23
+ "eslint-plugin-node": "^11.1.0",
24
+ "mocha": "^9.1.3"
25
+ },
26
+ "engines": {
27
+ "node": "12.x || 14.x || >= 16"
28
+ },
29
+ "peerDependencies": {
30
+ "eslint": ">=6"
31
+ },
32
+ "license": "ISC"
33
+ }
@@ -64,8 +64,7 @@ module.exports = {
64
64
 
65
65
  if(isTestingPublicApi){
66
66
  const currentFilePath = context.getFilename();
67
- const normalizedPath = path.toNamespacedPath(currentFilePath);
68
- const isCurrentFileTesting = testFilesPatterns.some(pattern=>micromatch.isMatch(normalizedPath, pattern))
67
+ const isCurrentFileTesting = testFilesPatterns.some(pattern=>micromatch.isMatch(currentFilePath, pattern))
69
68
  if(!isCurrentFileTesting){
70
69
  context.report({node: node, message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'});
71
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-big-react-app-plugin",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "plugin for prod proj",
5
5
  "keywords": [
6
6
  "eslint",