eslint-plugin-path
Advanced tools
Comparing version 0.1.0-rc.0 to 0.1.0-rc.1
@@ -6,16 +6,26 @@ "use strict"; | ||
function findAbsolutePath(path, baseDirs) { | ||
const expectedPath = baseDirs | ||
.map((item) => relative(item, path)) | ||
.find((item) => !item.startsWith("../")); | ||
function isRelativePath(path) { | ||
return path && path.startsWith("../"); | ||
} | ||
return expectedPath; | ||
function findAbsolutePath(path, baseDirs = []) { | ||
if (!path || !baseDirs) { | ||
return null; | ||
} | ||
return baseDirs | ||
.map((dir) => relative(dir, path)) | ||
.find((path) => !isRelativePath(path)); | ||
} | ||
function getSegmentCount(path) { | ||
return path.split("/").length - 1; | ||
if (!path) { | ||
return 0; | ||
} | ||
return (path.split("/").length || 1) - 1; | ||
} | ||
function isWrongRelativeImport(current, expected) { | ||
if (!current || !expected) { | ||
if (!current || !expected || !isRelativePath(current)) { | ||
return false; | ||
@@ -49,24 +59,23 @@ } | ||
return getImport(filename, ({ node, start, end, path }) => { | ||
const current = node.source.value; | ||
return getImport(filename, ({ node, start, value: current, end, path }) => { | ||
const expected = findAbsolutePath(path, baseDirs); | ||
if (isWrongRelativeImport(current, expected)) { | ||
const data = { | ||
current, | ||
expected, | ||
}; | ||
const fix = (fixer) => | ||
fixer.replaceTextRange([start + 1, end - 1], expected); | ||
context.report({ | ||
node, | ||
messageId: "noRelativeImports", | ||
data: { | ||
current, | ||
expected, | ||
}, | ||
fix: (fixer) => fixer.replaceTextRange([start + 1, end - 1], expected), | ||
data: data, | ||
fix, | ||
suggest: [ | ||
{ | ||
messageId: "replaceRelativeImport", | ||
data: { | ||
current, | ||
expected, | ||
}, | ||
fix: (fixer) => | ||
fixer.replaceTextRange([start + 1, end - 1], expected), | ||
data: data, | ||
fix, | ||
}, | ||
@@ -73,0 +82,0 @@ ], |
{ | ||
"name": "eslint-plugin-path", | ||
"version": "0.1.0-rc.0", | ||
"version": "0.1.0-rc.1", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "author": "qDanik <qdanik@yandex.ru>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8328
165