Skip to content

Add Ktlint as code formatter#1405

Merged
aballano merged 14 commits intomasterfrom
ab/add_ktlint
Apr 15, 2019
Merged

Add Ktlint as code formatter#1405
aballano merged 14 commits intomasterfrom
ab/add_ktlint

Conversation

@aballano
Copy link
Member

@aballano aballano commented Apr 13, 2019

What's done

  • Added Ktlint as default code formatter.
  • It is already integrated with Travis (see second commit's failures)

How to use

For verification is enough by doing gradle build or more explicitly gradle ktlint.

For auto-correction: gradle ktlintformat and it will fix most issues except some that cannot be auto corrected.

What's missing

There are 2 issues that cannot be auto corrected and have to be fixed manually within this PR scope. The issues are:

Those doesn't seem to be configurable, so I'd rather prefer to hear opinions before changing them myself cc @arrow-kt/maintainers

=> The solution would be either ignore this issues file by file or fix them and prescind of wildcard imports and align file names with the class inside.

@JorgeCastilloPrz
Copy link
Member

Should we run it now for the complete project?

@aballano
Copy link
Member Author

It is run already (see second commit), but the two cases that cannot be fixed (pr desc.) have to be fixed manually.

Also, shall we get rid of detekt as well?

@JorgeCastilloPrz
Copy link
Member

JorgeCastilloPrz commented Apr 13, 2019

Ok, thought it wasn't since those seemed like too few changes for such a big project, but looks like you tweaked the linter config to match the style we already had.

Yes, I'd get rid of detekt here if it's not too much to ask. I don't think there's much value on keeping both of them.

Copy link
Member

@JorgeCastilloPrz JorgeCastilloPrz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!. There's still a couple of detekt files (yml and Gradle) on root root dir we'd need to remove.

@aballano
Copy link
Member Author

@JorgeCastilloPrz Only found detekt's config file, any pointer for the gradle one?

Copy link
Member

@JorgeCastilloPrz JorgeCastilloPrz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's not a Gradle one, thought we had some detekt related tasks somewhere but can't find it anymore

@JorgeCastilloPrz
Copy link
Member

Pls remember to fix the reported style issues for Ank

Copy link
Member

@raulraja raulraja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@aballano
Copy link
Member Author

aballano commented Apr 14, 2019

@JorgeCastilloPrz The reported files affect all entire project (see details below).

The question is ❓, do we ignore the issue file by file or fix it file by file too? I just need some hints as I'm unsure about if, for example, using wildcard imports is something you folks want to keep using or you'd be fine using qualified ones. Same question for the other issue described in the PR description.

Thoughts? cc @pakoito @raulraja @nomisRev

Details
> Task :arrow-dagger:ktlintMainSourceSetCheck
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/all.kt:1:1: class ArrowInstances should be declared in a file named ArrowInstances.kt (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/either.kt:4:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/either.kt:5:1: Wildcard import (cannot be auto-corrected)
> :arrow-dagger-effects:ktlintMainSourceSetCheck
> :arrow-core-extensions:ktlintMainSourceSetCheck


> Task :arrow-dagger-effects-rx2:ktlintMainSourceSetCheck FAILED
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger-effects-rx2/src/main/kotlin/arrow/dagger/effects/extensions/rx2/all.kt:1:1: class ArrowEffectsRx2Instances should be declared in a file named ArrowEffectsRx2Instances.kt (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger-effects-rx2/src/main/kotlin/arrow/dagger/effects/extensions/rx2/flowable.kt:1:1: class FlowableKInstances should be declared in a file named FlowableKInstances.kt (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger-effects-rx2/src/main/kotlin/arrow/dagger/effects/extensions/rx2/flowable.kt:16:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger-effects-rx2/src/main/kotlin/arrow/dagger/effects/extensions/rx2/observable.kt:1:1: class ObservableKInstances should be declared in a file named ObservableKInstances.kt (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger-effects-rx2/src/main/kotlin/arrow/dagger/effects/extensions/rx2/observable.kt:16:1: Wildcard import (cannot be auto-corrected)
"plain" report written to /Users/aballano/workspace/arrow/modules/dagger/arrow-dagger-effects-rx2/build/reports/ktlint/ktlintMainSourceSetCheck.txt

> Task :arrow-dagger-effects:ktlintMainSourceSetCheck
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger-effects/src/main/kotlin/arrow/dagger/effects/extensions/all.kt:1:1: class ArrowEffectsInstances should be declared in a file named ArrowEffectsInstances.kt (cannot be auto-corrected)



/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger-effects/src/main/kotlin/arrow/dagger/effects/extensions/io.kt:3:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger-effects/src/main/kotlin/arrow/dagger/effects/extensions/io.kt:19:1: Wildcard import (cannot be auto-corrected)
"plain" report written to /Users/aballano/workspace/arrow/modules/dagger/arrow-dagger-effects/build/reports/ktlint/ktlintMainSourceSetCheck.txt

> Task :arrow-dagger-effects:ktlintMainSourceSetCheck FAILED

> Task :arrow-dagger:ktlintMainSourceSetCheck
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/eithert.kt:4:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/eithert.kt:5:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/eval.kt:1:1: class EvalInstances should be declared in a file named EvalInstances.kt (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/eval.kt:3:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/eval.kt:9:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/function0.kt:1:1: class Function0Instances should be declared in a file named Function0Instances.kt (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/function0.kt:3:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/function0.kt:9:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/id.kt:1:1: class IdInstances should be declared in a file named IdInstances.kt (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/id.kt:3:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/id.kt:9:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/kleisli.kt:8:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/listk.kt:1:1: class ListKInstances should be declared in a file named ListKInstances.kt (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/listk.kt:3:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/listk.kt:11:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/mapk.kt:4:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/mapk.kt:5:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/nonemptylist.kt:1:1: class NonEmptyListInstances should be declared in a file named NonEmptyListInstances.kt (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/nonemptylist.kt:3:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/nonemptylist.kt:12:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/number.kt:1:1: class NumberInstances should be declared in a file named NumberInstances.kt (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/number.kt:3:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/number.kt:4:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/option.kt:1:1: class OptionInstances should be declared in a file named OptionInstances.kt (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/option.kt:3:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/option.kt:10:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/optiont.kt:4:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/optiont.kt:5:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/sequence.kt:1:1: class SequenceKInstances should be declared in a file named SequenceKInstances.kt (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/sequence.kt:3:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/sequence.kt:11:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/set.kt:3:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/sortedmap.kt:4:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/statet.kt:4:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/statet.kt:5:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/string.kt:1:1: class StringInstances should be declared in a file named StringInstances.kt (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/try.kt:1:1: class TryInstances should be declared in a file named TryInstances.kt (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/try.kt:3:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/try.kt:10:1: Wildcard import (cannot be auto-corrected)



/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/tuple.eq.kt:3:1: Wildcard import (cannot be auto-corrected)
"plain" report written to /Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/build/reports/ktlint/ktlintMainSourceSetCheck.txt
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/tuple.eq.kt:4:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/tuple.eq.kt:5:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/validated.kt:3:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/validated.kt:4:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/validated.kt:5:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/writert.kt:4:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/dagger/arrow-dagger/src/main/kotlin/arrow/dagger/extensions/writert.kt:5:1: Wildcard import (cannot be auto-corrected)

> Task :arrow-core-extensions:ktlintMainSourceSetCheck FAILED
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/const.kt:7:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/either.kt:5:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/either.kt:8:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/eval.kt:3:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/eval.kt:7:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/function0.kt:4:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/function0.kt:8:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/function1.kt:4:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/function1.kt:7:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/id.kt:6:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/id.kt:10:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/monoid.kt:1:1: interface MonoidInvariant should be declared in a file named MonoidInvariant.kt (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/monoid.kt:4:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/number.kt:3:1: Wildcard import (cannot be auto-corrected)
"plain" report written to /Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/build/reports/ktlint/ktlintMainSourceSetCheck.txt
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/option.kt:5:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/option.kt:10:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/string.kt:3:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/try.kt:6:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/try.kt:10:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/tuple.kt:6:1: Wildcard import (cannot be auto-corrected)
/Users/aballano/workspace/arrow/modules/core/arrow-core-extensions/src/main/kotlin/arrow/core/extensions/tuple.kt:10:1: Wildcard import (cannot be auto-corrected)

> Task :arrow-core-data:ktlintMainSourceSetCheck FAILED
"plain" report written to /Users/aballano/workspace/arrow/modules/core/arrow-core-data/build/reports/ktlint/ktlintMainSourceSetCheck.txt
/Users/aballano/workspace/arrow/modules/core/arrow-core-data/src/main/kotlin/arrow/core/list.kt:1:1: object ListExtensions should be declared in a file named ListExtensions.kt (cannot be auto-corrected)

@JorgeCastilloPrz
Copy link
Member

Wildcard imports are useful for importing complete namespaces so I'm fine keeping those. There's a trend on avoiding them but I don't think it would bring much value for us, since we intentionally group features per namespaces (i.e: arrow.effects) precisely to be able to use wildcard imports over those on call site files.

@raulraja
Copy link
Member

Giving 99% of user base is in IDEA and IDEA manages imports for you I'm fine removing wildcard imports. IDEA auto import clean up already does so wherever it makes sense. Unless we are taking here about a collision between IDEA and ktlint expectations I think we should follow ktlint defaults to avoid friction as much as possible.

@raulraja
Copy link
Member

As for file names that do not correspond to classes we should also follow ktlint expectations and have those files renamed as expected.

@jrgonzalezg
Copy link
Member

It seems this PR is forcing new lines at the end of file to be removed due to the ktlint config used. Is that what we want? It feels a bit odd that the last line is not completed by a newline.

@jrgonzalezg
Copy link
Member

Ensuring new line at the end of file is even a recommended rule to enable in ktlint documentation: https://github.com/pinterest/ktlint#standard-rules

@aballano
Copy link
Member Author

@raulraja 👌 on it. It seems ktlint had a fail-fast kind of mechanism, so now there come way more changes than before 😅

@aballano aballano mentioned this pull request Apr 15, 2019
@aballano aballano marked this pull request as ready for review April 15, 2019 09:53
@aballano aballano changed the title Added ktlint as code formatter Add Ktlint as code formatter Apr 15, 2019
@raulraja
Copy link
Member

@aballano this is great, let me know when it's ready to be merged or merge at will whenever. thanks 👏 👏

[*.{kt,kts}]
indent_size=2
insert_final_newline=true
max_line_length=off No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also end this file with newline?

@aballano aballano merged commit ce539f2 into master Apr 15, 2019
@aballano aballano deleted the ab/add_ktlint branch April 15, 2019 12:32
@pakoito
Copy link
Member

pakoito commented Apr 15, 2019

🎉

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants