eslint-plugin-forum-react
Advanced tools
Comparing version
@@ -40,3 +40,20 @@ "use strict"; | ||
if(shouldBeRelative(fromFilename, importTo)) { | ||
context.report(node, 'В рамках одного слайса все пути должны быть относительными'); | ||
context.report({ | ||
node, | ||
message: 'В рамках одного слайса все пути должны быть относительными', | ||
fix: (fixer) => { | ||
const normalizedPath = getNormalizedCurrentFilePath(fromFilename) | ||
.split('/') | ||
.slice(0, -1) | ||
.join('/'); | ||
let relativePath = path.relative(normalizedPath, `/${importTo}`) | ||
.split('\\') | ||
.join('/'); | ||
if(!relativePath.startsWith('.')) { | ||
relativePath = './' + relativePath; | ||
} | ||
return fixer.replaceText(node.source, `'${relativePath}'`) | ||
} | ||
}); | ||
} | ||
@@ -56,2 +73,8 @@ } | ||
function getNormalizedCurrentFilePath(currenFilePath) { | ||
const normalizedPath = path.toNamespacedPath(currenFilePath); | ||
const projectFrom = normalizedPath.split('src')[1]; | ||
return projectFrom.split('\\').join('/') | ||
} | ||
function shouldBeRelative(from, to) { | ||
@@ -71,4 +94,3 @@ if(isPathRelative(to)) { | ||
const normalizedPath = path.toNamespacedPath(from); | ||
const projectFrom = normalizedPath.split('src')[1]; | ||
const projectFrom = getNormalizedCurrentFilePath(from); | ||
const fromArray = projectFrom.split('\\') | ||
@@ -75,0 +97,0 @@ |
{ | ||
"name": "eslint-plugin-forum-react", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "plugin for forum-react-project", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
22771
3.49%500
4.17%