Unused Imports
Remove every unused import in every language and file type, including imported symbols, modules, stylesheets, assets, includes, requires, and equivalent dependency declarations. An import is unused when neither its exported values nor its loading side effects are required by the file.
Correct
import { readFile } from 'fs'
const content = readFile(path)
import './registration.js'
@import './colors.css';
.card { color: var(--primaryColor); }
from pathlib import Path
path = Path('content')
Incorrect
import { readFile, writeFile } from 'fs'
const content = readFile(path)
import Button from './Button.jsx'
export default <Content />
@import './unused.css';
from pathlib import Path, PurePath
path = Path('content')
Exceptions
- Keep an import when loading the module is itself required for registration, initialization, polyfills, styles, or another intentional side effect.
Fix
Remove the unused import or imported member. If loading the dependency has a required side effect, use the language’s explicit side-effect import form where available.