Skip to main content
interlace
Plugin: import-nextRules

no-unassigned-import

Prevents unassigned imports

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

Rule Details

An import that binds nothing is loaded only for its side effects, which a reader cannot see. Reported: import 'm', import {} from 'm', and a require('m') whose result is discarded (an expression statement, or a non-final item of a sequence).

Not reported: any form that binds or re-exports a name (default, namespace, named, type-only, export … from, a require whose result is used, import x = require()), and specifiers listed in allowModules (exact match).

❌ Incorrect

import './polyfill';
import {} from './setup';
require('./register');

✅ Correct

import { install } from './polyfill';
const register = require('./register');
// with { allowModules: ['./polyfill'] }
import './polyfill';

Options

[
  {
    "type": "object",
    "properties": {
      "allowModules": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "description": "Allow specific modules to be imported without assignment."
      }
    },
    "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-unassigned-import": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-import-next'],    rules: {      'import-next/no-unassigned-import': '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.