eslint-plugin-big-react-app-plugin 0.2.5 → 0.2.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.
- package/lib/rules/path-checker.js +18 -4
- package/package.json +1 -1
|
@@ -37,7 +37,17 @@ module.exports = {
|
|
|
37
37
|
// example C:\Users\tim\Desktop\javascript\production_project\src\entities\Article
|
|
38
38
|
const fromFilename = context.getFilename();
|
|
39
39
|
if(shouldBeRelative(fromFilename, importTo)) {
|
|
40
|
-
context.report({node:
|
|
40
|
+
context.report({node:
|
|
41
|
+
node,
|
|
42
|
+
message: 'В рамках одного слайса все пути должны быть относительными'});
|
|
43
|
+
fix:(fixer)=>{
|
|
44
|
+
const normalizedPath = getNormalizedFilePath(fromFilename).split('/').slice(0, -1).join('/')//enteties/Article/Artcile.tsx файл в который делаем импорт и также убираем концовку
|
|
45
|
+
let relativePath = path.relative(normalizedPath, `/${importTo}`).split('\\').join('/')
|
|
46
|
+
if(!relativePath.startsWith('.')){
|
|
47
|
+
relativePath = './' + relativePath
|
|
48
|
+
}
|
|
49
|
+
return fixer.replaceText(node.source, `'${relativePath}'`)
|
|
50
|
+
}
|
|
41
51
|
}
|
|
42
52
|
}
|
|
43
53
|
};
|
|
@@ -51,7 +61,12 @@ const layers = {
|
|
|
51
61
|
"shared":"shared",
|
|
52
62
|
"widgets":"widgets",
|
|
53
63
|
}
|
|
54
|
-
|
|
64
|
+
function getNormalizedFilePath (){
|
|
65
|
+
const normalizationPath = path.toNamespacedPath(from);
|
|
66
|
+
const projFrom = normalizationPath.split('src')[1]
|
|
67
|
+
return projFrom.split('\\').join('/')
|
|
68
|
+
}
|
|
69
|
+
function shouldBeRelative (from, to){
|
|
55
70
|
if(isPathRelative(to)){
|
|
56
71
|
return false
|
|
57
72
|
}
|
|
@@ -64,8 +79,7 @@ const shouldBeRelative = (from, to)=>{
|
|
|
64
79
|
return false
|
|
65
80
|
}
|
|
66
81
|
//нормализуем путь
|
|
67
|
-
const
|
|
68
|
-
const projFrom = normalizationPath.split('src')[1]
|
|
82
|
+
const projFrom = getNormalizedFilePath(from)
|
|
69
83
|
const fromArray = projFrom.split('\\')
|
|
70
84
|
|
|
71
85
|
const fromLayer = fromArray[1];
|