eslint-plugin-unimport

raw JSON →
1.0.0 verified Sat Apr 25 auth: no javascript

ESLint plugin (v1.0.0, latest) that automatically inserts imports from Unimport into ESLint fixes. Integrates with unplugin-auto-import and Nuxt to auto-fix missing imports in codebases using auto-import features. ESM-only since v1.0.0, requires ESLint ^9.0.0 || ^8.45.0. Differentiator: bridges Unimport's auto-import with ESLint's autofix, making auto-imported symbols explicit in source files.

error Cannot find module 'eslint-plugin-unimport'
cause Package not installed or ESM-only require() call.
fix
Install the package: npm install eslint-plugin-unimport. If using require(), switch to import.
error Error: .unimport-items.json not found
cause unplugin-auto-import not configured to dump items or file not generated.
fix
Add dumpUnimportItems: true to AutoImport config and run build/dev to generate the file.
error ESLint couldn't find the plugin 'unimport'
cause Plugin not properly registered in flat config.
fix
Add plugin object: plugins: { unimport: (await import('eslint-plugin-unimport')).default }.
breaking v1.0.0 switched to ESM-only; projects using CommonJS require() will break.
fix Migrate to ESM or use dynamic import().
gotcha The plugin requires a pre-generated .unimport-items.json from unplugin-auto-import with dumpUnimportItems: true.
fix Ensure unplugin-auto-import config includes dumpUnimportItems: true and the file exists before running ESLint.
gotcha Flat config only; the plugin does not support legacy eslintrc format.
fix Use eslint.config.js/.mjs file with flat config.
deprecated v0.x used a different plugin format; v0.0.2 had a breaking change in plugin format.
fix Upgrade to v1.0.0 and follow new configuration pattern.
npm install eslint-plugin-unimport
yarn add eslint-plugin-unimport
pnpm add eslint-plugin-unimport

Sets up eslint-plugin-unimport with a flat config, reading auto-import items from a JSON file.

import fs from 'node:fs';
import { createAutoInsert } from 'eslint-plugin-unimport';

export default [
  {
    plugins: {
      unimport: (await import('eslint-plugin-unimport')).default,
    },
  },
  {
    rules: {
      'unimport/auto-insert': 'error',
    },
  },
  ...createAutoInsert({
    imports: JSON.parse(fs.readFileSync('.unimport-items.json', 'utf-8')),
  }),
];