Skip to content

Feature Request: Add a FormatterStep to Expand Star Imports #2594

@HamedTaghani

Description

@HamedTaghani

Hello Spotless maintainers,
I'm a new potential contributor and I've been exploring the features of Spotless and comparing them to other code quality tools like checkstyle. I'm very impressed with the focus on automated formatting and I would like to propose a new FormatterStep for Java.

The proposed feature would automatically expand star imports (e.g., import java.util.*) into explicit, individual class imports (e.g., import java.util.List;). This aligns well with the Spotless philosophy of automatically fixing common style violations.

Motivation:
Many style guides and tools (like Checkstyle's AvoidStarImport check) recommend against star imports for reasons of clarity and avoiding potential naming conflicts.

Implementing this as a FormatterStep would give users a seamless way to enforce this style rule, turning a linter check into an automated fix.

Example of the proposed change:
Before:

import java.util.*;

public class MyClass {
    List<String> list = new ArrayList<>();
    Map<String, String> map = new HashMap<>();
}

After:

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MyClass {
    List<String> list = new ArrayList<>();
    Map<String, String> map = new HashMap<>();
}

I believe this feature would be a valuable addition to Spotless. I am interested in implementing this and submitting a pull request if team thinks it's a worthwhile feature.

Please let me know if this is a feature you would be open to.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions