Skip to content

Control static import placement #306

Closed

Description

@mkordas

Is there a way to configure Spotless so that static imports in Java/Groovy are put below normal imports? That's IntelliJ default...
I cannot find anything about it in docs, but I think the behavior should be documented and configurable.

Activity

  1. nedtwigg commented on Oct 5, 2018

    @nedtwigg
    Member

    There is not, but that would be a great feature to have! Our import sorter has a few hairy bits.

    #167 (minor bug that explains the background of import sorter, and how to do what you want to do)
    #174 (really minor bug)

    Possibly related, #232 is about incorporating the eclipse #include sorter for C/C++. Dunno if there's a common infrastructure, but if anyone wants to contribute a fix, I would start there.

  2. nedtwigg commented on Oct 5, 2018

    @nedtwigg
    Member

    Also looks like #305 can get lumped in to the ImportSorter mess :)

  3. fvgh commented on Oct 5, 2018

    @fvgh
    Member

    @nedtwigg I don't think that the import sorter is really suitable for C++. CDT provide a nice article about their rules. Gives a good reasoning why the topic in C++ is complex. As stated in #232, my aim is to get the CDT implementation in and provide it as an optional step.

  4. teur commented on Mar 10, 2019

    @teur

    There are examples of configuration static imports in ImportOrderStepTest by using \#.
    For example a configuration importOrder 'java', '\\#java', 'javax', '\\#javax', '', '\\#' may be used to put static imports below.

  5. fvgh commented on Mar 30, 2019

    @fvgh
    Member

    @nedtwigg I had another go on the IncludeOrganizer as it is provided by CDT. Unfortunately it is not an option as I described in my comment for #232. So maybe there can be a common code base for the Java/C++ import/include order.

  6. azizbekian commented on Jan 15, 2020

    @azizbekian

    This issue is still valid and needs to be resolved, because formatting file in IDE differs from spotless config.

  7. nedtwigg commented on Jan 15, 2020

    @nedtwigg
    Member

    Thanks for verifying. PR’s welcome!

  8. aljoscha commented on Dec 16, 2020

    @aljoscha

    @azizbekian Did you see @teur's comment? I have this config in a project and it puts static imports at the bottom:

    <order>org.apache.flink,org.apache.flink.shaded,javax,java,scala,\#</order>
    
  9. matshou commented on Feb 4, 2021

    @matshou

    Like @teur mentioned, adding '\\#' to the end of importOrder arranges static imports to be placed last.

  10. nedtwigg commented on Feb 4, 2021

    @nedtwigg
    Member

    Looks like this issue is solved. Thanks all!

  11. NathanQingyangXu commented on Nov 6, 2024

    @NathanQingyangXu

    I tried many times, but seems the issue is still there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions