Skip to main content
interlace
Plugin: import-nextRules

no-relative-parent-imports

A module may only depend on files at or below its own directory. A relative specifier that, once normalised, climbs out of the importing file's directory is rep

💼 This rule is enabled in the following configs: recommended, typescript.

Prevents ../ imports

Rule Details

A module may only depend on files at or below its own directory. A relative specifier that, once normalised, climbs out of the importing file's directory is reported: .., ../x, ./../x, ./a/../../x. Every way a module is loaded or re-exported is checked: import, side-effect import, export … from, export * from, require(), import() and TypeScript's import x = require().

Options: commonjs (default true) checks require(); amd (default false) checks the dependency arrays of define([...]) and require([...]). import x = require() is TypeScript's ES-import form and is always checked.

Not reported: a path that stays inside (./x, ./a/../b), and packages.

❌ Incorrect

import config from '../config';
export * from '..';
const util = require('./a/../../util');

✅ Correct

import helper from './helper';
import nested from './a/../b';
import lodash from 'lodash';

Options

[
  {
    "type": "object",
    "properties": {
      "commonjs": {
        "type": "boolean",
        "default": true,
        "description": "Check CommonJS require() calls."
      },
      "amd": {
        "type": "boolean",
        "default": false,
        "description": "Check AMD define/require calls."
      }
    },
    "additionalProperties": false
  }
]

Implementation

OWASP Foundation

  • Category: A00:2021 - General Security

Use this rule

npm install -D oxlint-plugin-import-next
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-import-next"],  "rules": {    "import-next/no-relative-parent-imports": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-import-next'],    rules: {      'import-next/no-relative-parent-imports': 'error',    },  },});

oxlint-plugin-import-next re-exports eslint-plugin-import-next/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.

Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.