Skip to content

unused-import

Reports an import whose name the file does not use. Imports with * are not checked, and a name in a doc comment counts as a use where the language has doc comments. No fix: removing an import can change which declaration a name means.

An import that nothing uses is dead code. It misleads the reader about what the file depends on, and where an import runs the module, as in Python, it still costs the time to load it and fails where the module is not installed.

To fix, remove the import.

Reported
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.io.*;
import static java.lang.Math.max;
import static java.lang.Math.min;
/** Uses {@link Set}. */
class A {
...
java:
lint:
rules:
unused-import: warn # off (default), warn, error
kotlin:
lint:
rules:
unused-import: warn # off (default), warn, error
python:
lint:
rules:
unused-import: warn # off (default), warn, error

Enabled by the presets: kotlin/ktlint, python/ruff.

Suppress one line with sudsy-disable-next-line unused-import in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
checkstyle UnusedImports partial Names in Javadoc count as used; no option to turn that off.
ktlint no-unused-imports full
ruff F401 full