idea-gradle-dependencies-formatter icon indicating copy to clipboard operation
idea-gradle-dependencies-formatter copied to clipboard

Format dependencies in order to have consitent look and feel

Open ghilainm opened this issue 6 years ago • 6 comments

The plugin should in addition of reordering dependencies also format them in order to have consistent look and feel.

Example:

    implementation 'org.apache.commons:commons-lang3:3.7'
    implementation "org.springframework.hateoas:spring-hateoas"
    annotationProcessor("org.projectlombok:lombok:1.18.2")

->

    implementation("org.apache.commons:commons-lang3:3.7")
    implementation("org.springframework.hateoas:spring-hateoas")
    annotationProcessor("org.projectlombok:lombok:1.18.2")

ghilainm avatar Oct 05 '18 09:10 ghilainm

Thanks for an idea and reporting it. I can see one important challenge here. Which format to choose? The simplest? The most common one? What if preferred format cannot be applied to all dependencies (e.g. we want to use format without brackets, but we have to because of closures). What does it mean 'the simplest format'? I prefer format without brackes and you added brackets to all dependences in your example. It wood be good to discuss these issues with examples.

platan avatar Oct 05 '18 10:10 platan

I would go for the format which can be used with closures and I would use Groovy string in order to support variable replacement.

-> implementation("org.apache.commons:commons-lang3:$commonLangVersion")

Gradle (understand Groovy) is confusing because of the numerous syntax that are available. It would be good for développeuse to have all the time the same format.

I think that this format also helps clarifying that behind it corresponds to a standard method call.

Other options if you don't like forcing people:

  • [easy to implement] Add enable/disable formatting, so that people can choose.
  • [maybe harder] Add an option to choose the preferred format in your plugin. And in case format is not syntactically valid, choose a valid one for this line.

ghilainm avatar Oct 05 '18 11:10 ghilainm

Why not making it configurable in the settings?

LSafer avatar Aug 30 '21 03:08 LSafer

Or better, why not making it project level thing? because every project might have its own better convention.

LSafer avatar Aug 30 '21 03:08 LSafer

The settings might be like this:

  • invoke methods with braces or not
  • prefer GString over string or the way around with the exception of always using GString when a variable been injected.
  • sort by scope or by name, some may prefer leaving test dependencies at the bottom and some may prefer sorting by the name.

LSafer avatar Aug 30 '21 04:08 LSafer

I generally prefer

implementation 'org.apache.commons:commons-lang3:3.7'
implementation "org.springframework.hateoas:spring-hateoas"

The parenthesis adds too much visual distraction and I would only want that distraction if the above version is not able to do it (e.g. if exclusions are needed) as it will visually indicate deviating from the defaults.

trajano avatar Jan 08 '23 19:01 trajano