eslint-plugin-laygrd-plugin 0.0.8 → 0.0.9
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.
package/lib/helpers/index.js
CHANGED
|
@@ -4,7 +4,16 @@ const isPathRelative = (p) => {
|
|
|
4
4
|
|
|
5
5
|
const normalizePathSeparators = (filename) => filename.replace(/\\/g, '/');
|
|
6
6
|
|
|
7
|
+
const getCurrentFileSegments = (filePath) => {
|
|
8
|
+
const normalizedPath = filePath.replace(/[\\]+/g, "/")
|
|
9
|
+
const projectPath = normalizedPath?.split('src')[1]
|
|
10
|
+
const segments = projectPath?.split('/')
|
|
11
|
+
|
|
12
|
+
return segments;
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
module.exports = {
|
|
8
16
|
isPathRelative,
|
|
9
17
|
normalizePathSeparators,
|
|
18
|
+
getCurrentFileSegments,
|
|
10
19
|
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
"use strict";
|
|
6
6
|
|
|
7
|
-
const { isPathRelative,
|
|
7
|
+
const { isPathRelative, getCurrentFileSegments } = require('../helpers');
|
|
8
8
|
|
|
9
9
|
//------------------------------------------------------------------------------
|
|
10
10
|
// Rule Definition
|
|
@@ -78,10 +78,10 @@ const shouldPathBeRelative = (curFile, impSrc) => {
|
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
const curFileLayer =
|
|
84
|
-
const curFileSlice =
|
|
81
|
+
const segments = getCurrentFileSegments(curFile) // 'C:\Users\rosti\Desktop\projects\blog-app\src\entities\Article\ui\ArticleList' -> \entities\Article\ui\ArticleList
|
|
82
|
+
// \entities\Article\ui\ArticleList -> [ '', 'entities', 'Article', 'ui', 'ArticleList' ]
|
|
83
|
+
const curFileLayer = segments[1]; // entities
|
|
84
|
+
const curFileSlice = segments[2]; // Article
|
|
85
85
|
|
|
86
86
|
if ( !curFileLayer || !curFileSlice || !layers[curFileLayer] ) {
|
|
87
87
|
return false;
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
//------------------------------------------------------------------------------
|
|
10
10
|
|
|
11
11
|
const micromatch = require('micromatch');
|
|
12
|
-
const { isPathRelative,
|
|
12
|
+
const { isPathRelative, getCurrentFileSegments } = require('../helpers');
|
|
13
13
|
|
|
14
14
|
/** @type {import('eslint').Rule.RuleModule} */
|
|
15
15
|
module.exports = {
|
|
@@ -61,10 +61,7 @@ module.exports = {
|
|
|
61
61
|
|
|
62
62
|
const getCurrentFileLayer = () => {
|
|
63
63
|
const currentFilePath = context.getFilename();
|
|
64
|
-
|
|
65
|
-
const normalizedPath = normalizePathSeparators(currentFilePath);
|
|
66
|
-
const projectPath = normalizedPath?.split('src')[1];
|
|
67
|
-
const segments = projectPath.split('/');
|
|
64
|
+
const segments = getCurrentFileSegments(currentFilePath)
|
|
68
65
|
|
|
69
66
|
return segments[1];
|
|
70
67
|
}
|