eslint-plugin-path
Advanced tools
Comparing version 0.1.0-rc.2 to 0.1.0-rc.3
"use strict"; | ||
const { getImport, getBaseDirs, isRelativeToParent } = require("../utils"); | ||
const { | ||
getImport, | ||
getBaseDirs, | ||
isRelativeToParent, | ||
isExternalPath, | ||
} = require("../utils"); | ||
const { relative } = require("path"); | ||
function findAbsolutePath(path, baseDirs = []) { | ||
if (!path || !baseDirs) { | ||
function findAbsolutePath(target, baseDirs = []) { | ||
if (!target || !baseDirs) { | ||
return null; | ||
@@ -12,3 +17,3 @@ } | ||
return baseDirs | ||
.map((dir) => relative(dir, path)) | ||
.map(({ path, alias }) => `${alias || ""}${relative(path, target)}`) | ||
.find((path) => !isRelativeToParent(path)); | ||
@@ -35,3 +40,8 @@ } | ||
function isWrongRelativeImport(current, expected, settings) { | ||
if (!current || !expected || !isRelativeToParent(current)) { | ||
if ( | ||
!current || | ||
!expected || | ||
!isRelativeToParent(current) || | ||
isExternalPath(expected) | ||
) { | ||
return false; | ||
@@ -38,0 +48,0 @@ } |
"use strict"; | ||
const { dirname, join, normalize, resolve } = require("path"); | ||
const { dirname, join, normalize, resolve, relative } = require("path"); | ||
const { existsSync, readFileSync } = require("fs"); | ||
@@ -22,3 +22,3 @@ | ||
function getRootDirectory() { | ||
function getContextPackagePath() { | ||
let dir = resolve(FILES.package); | ||
@@ -49,4 +49,23 @@ | ||
function getBaseDirs() { | ||
const rootDir = getRootDirectory(); | ||
function isExternalPath(path) { | ||
if (!path) { | ||
return false; | ||
} | ||
const packagePath = getContextPackagePath(); | ||
if (relative(packagePath, path).startsWith("..")) { | ||
return true; | ||
} | ||
const folders = ["node_modules"]; | ||
return folders.some((folder) => { | ||
const folderPath = resolve(packagePath, folder); | ||
const relativePath = relative(folderPath, path); | ||
return !relativePath.startsWith(".."); | ||
}); | ||
} | ||
function getTSconfigDirs() { | ||
const rootDir = getContextPackagePath(); | ||
const urls = []; | ||
@@ -57,18 +76,29 @@ | ||
if (hasKey(config, "include")) { | ||
config.include.forEach((item) => urls.push(item)); | ||
} | ||
if (hasKey(config, "compilerOptions.paths")) { | ||
Object.values(config.compilerOptions.paths).forEach((items) => | ||
items.forEach((item) => urls.push(item.replace("/*", ""))) | ||
Object.entries(config.compilerOptions.paths).forEach(([key, items]) => | ||
items.forEach((item) => | ||
urls.push({ | ||
path: item.replace("*", ""), | ||
alias: key.replace("*", ""), | ||
}) | ||
) | ||
); | ||
} | ||
if (hasKey(config, "include")) { | ||
config.include.forEach((item) => urls.push({ path: item, alias: null })); | ||
} | ||
if (hasKey(config, "compilerOptions.baseUrl")) { | ||
urls.push(config.compilerOptions.baseUrl); | ||
urls.push({ | ||
path: config.compilerOptions.baseUrl, | ||
alias: null, | ||
}); | ||
} | ||
} | ||
return urls.map((item) => join(rootDir, item)); | ||
return urls.map((item) => ({ | ||
...item, | ||
path: join(rootDir, item.path), | ||
})); | ||
} | ||
@@ -105,5 +135,6 @@ | ||
module.exports = { | ||
getBaseDirs, | ||
getBaseDirs: getTSconfigDirs, | ||
getImport, | ||
isRelativeToParent, | ||
isExternalPath, | ||
}; |
{ | ||
"name": "eslint-plugin-path", | ||
"version": "0.1.0-rc.2", | ||
"version": "0.1.0-rc.3", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "author": "qDanik <qdanik@yandex.ru>", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10102
235
0