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.0 to 0.1.0-rc.1

49

lib/rules/no-relative-imports.js

@@ -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>",

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