gitmyhub

eslint-plugin-import

JavaScript ★ 5.9k updated 1d ago

ESLint plugin with rules that help validate proper imports.

An ESLint plugin that catches broken imports before your app runs, missing files, non-existent named exports, unlisted packages, circular dependencies, and messy import ordering.

JavaScriptTypeScriptESLintNode.jsnpmsetup: easycomplexity 2/5

eslint-plugin-import is an add-on for ESLint, a tool that checks JavaScript code for problems while you write it. This plugin focuses specifically on the import and export statements that modern JavaScript uses to share code between files. It adds a collection of rules that catch mistakes your editor would not otherwise flag, before those mistakes reach a running application.

The most practical rules handle things like typos in file paths, importing a named export that does not actually exist in the source file, and importing packages that are not listed in your project's dependencies. These are errors that tend to appear only at runtime without this kind of static analysis, and they can be confusing to trace back to the source.

A second category of rules covers code organization. The plugin can enforce a consistent order for import statements at the top of a file, require a blank line between third-party imports and your own project files, forbid duplicate imports of the same module, and prevent circular dependencies, where file A imports from file B while file B also imports from file A.

There is also a group of rules about module system consistency. Projects that are migrating from older CommonJS-style code to modern ES module syntax can use these rules to flag mixed usage, such as a file that uses both require() and import at the same time.

Installation involves adding the package from npm and referencing it in your ESLint configuration file. Most rules can be turned on or off individually, and the plugin ships with a recommended configuration that enables a sensible starting set. It works with JavaScript and TypeScript projects and includes a typescript configuration preset for TypeScript users.

Where it fits