Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-path

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-path - npm Package Compare versions

Comparing version 0.1.0-rc.2 to 0.1.0-rc.3

20

lib/rules/no-relative-imports.js
"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>",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc