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

eslint-plugin-no-relative-import-paths

Package Overview
Dependencies
Maintainers
0
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-no-relative-import-paths - npm Package Compare versions

Comparing version 1.5.4 to 1.5.5

35

index.js

@@ -18,2 +18,11 @@ const path = require("path");

function getRelativePathDepth(path) {
let depth = 0;
while (path.startsWith('../')) {
depth += 1;
path = path.substring(3)
}
return depth;
}
function getAbsolutePath(relativePath, context, rootDir, prefix) {

@@ -50,2 +59,3 @@ return [

prefix: { type: "string" },
allowedDepth: { type: "number" },
},

@@ -58,3 +68,4 @@ additionalProperties: false,

create: function (context) {
const { allowSameFolder, rootDir, prefix } = {
const { allowedDepth, allowSameFolder, rootDir, prefix } = {
allowedDepth: context.options[0]?.allowedDepth,
allowSameFolder: context.options[0]?.allowSameFolder || false,

@@ -69,12 +80,14 @@ rootDir: context.options[0]?.rootDir || '',

if (isParentFolder(path, context, rootDir)) {
context.report({
node,
message: message,
fix: function (fixer) {
return fixer.replaceTextRange(
[node.source.range[0] + 1, node.source.range[1] - 1],
getAbsolutePath(path, context, rootDir, prefix)
);
},
});
if (typeof allowedDepth === 'undefined' || getRelativePathDepth(path) > allowedDepth) {
context.report({
node,
message: message,
fix: function (fixer) {
return fixer.replaceTextRange(
[node.source.range[0] + 1, node.source.range[1] - 1],
getAbsolutePath(path, context, rootDir, prefix)
);
},
});
}
}

@@ -81,0 +94,0 @@

{
"name": "eslint-plugin-no-relative-import-paths",
"version": "v1.5.4",
"version": "v1.5.5",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -108,2 +108,29 @@ # eslint-plugin-no-relative-import-paths

import Something from "@/components/something";
```
```
### `allowedDepth`
Used to allow some relative imports of certain depths.
Examples of code for this rule:
```js
// when configured as { "allowedDepth": 1 }
// will NOT generate a warning
import Something from "../components/something";
// will generate a warning
import Something from "../../components/something";
```
```js
// when configured as { "allowedDepth": 2 }
// will NOT generate a warning
import Something from "../../components/something";
// will generate a warning
import Something from "../../../components/something";
```
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