Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Introduce codestyle set #548

Closed
Tapchicoma opened this issue Jul 29, 2019 · 3 comments
Closed

Introduce codestyle set #548

Tapchicoma opened this issue Jul 29, 2019 · 3 comments

Comments

@Tapchicoma
Copy link
Collaborator

Proposal

Ktlint should introduce codestyle-set concept. Codestyle-set will contain set of rules, that would be used by ktlint on linting/formatting the code.

Such approach:

Implementation details

Each codestyle-set should have a unique name and contain list of rule ids. Codestyle-set could extend another codestyle-set by adding (removing (?)) rules to the parent one.

Built-in

Ktlint should provide built-in codestyle-sets:

  • "official" (default) provides official Kotlin styleguide and should works the same way as IDEA Kotlin code style formatting
  • "official-experimental" - adds experimental rules on top of "official" codestyle-set
  • "android" - provides official Android Kotlin styleguide support
  • "android-experimental" - adds experimental rules on top of "android" codestyle-set

.Editorconfig

User should be able to define and use custom codestyle-set, using .editorconfig file:

[*.{kt,kts}]
codestyle-set-define=my-kotlin-style-name:final-newline,chain-wrapping,no-unit-return
codestyle-set-define=my-kotlin-style-name-extended:my-kotlin-style-name:no-unused-imports,comma-spacing
codestyle-set=my-kotlin-style-name

where codestyle-set-define has following format:

codestyle-set-define=<set name>:<optional parent set name>:<list of rule ids separated by comma>

.Editorconfig can contain several codestyle-set entries, but only last one codestyle-set entry will be used by Ktlint.
Nested .editorconfig files could override codestyle-set entry used in parent .editorconfig.

Command line

Usage of codestyle-set in command line looks similar to how it is done in .editorconfig file:

$ ktlint --codestyle-set-define=my-kotlin-style-name:official:final-newline,chain-wrapping,no-unit-return --codestyle-set=my-kotlin-style-name

Deprecations

--android CLI flag should be replace by "android" codestyle-set

@paul-dingemans
Copy link
Collaborator

Deprecations

--android CLI flag should be replace by "android" codestyle-set

With #1488 the .editorconfig property ktlint_code_style is introduced making this command line flag redundant. This flag might be removed in a future release.

I see no reason for further implementation of "flexible" code style rules. As no one else has attempted to introduce this in the last 3 years, the issue is closed.

@paul-dingemans paul-dingemans closed this as not planned Won't fix, can't repro, duplicate, stale Jun 18, 2022
@paul-dingemans paul-dingemans unpinned this issue Jun 18, 2022
@idntfy
Copy link

idntfy commented Jun 18, 2022

@paul-dingemans as it was described in the ticket from which this ticket is originated, .editorconfig is not a scalable option, this is why the flag is requested. You can read more details here: #533

The problem with ktlint is that it is android-centric and doesn't use official code style. In our company we use kotlin for backend for hundreds of services, not for android. With the proposed option of having it in editorconfig, the file that does nothing else but just sets the official kotlin code style, has to be copied through hundreds of projects. With the flag, it is just a matter of adding it to the one place, a parent-pom, to have consistency of configuration across all the projects.

@paul-dingemans
Copy link
Collaborator

@paul-dingemans as it was described in the ticket from which this ticket is originated, .editorconfig is not a scalable option, this is why the flag is requested. You can read more details here: #533

In last couple of years, the focus is shifting more and more towards .editorconfig settings. From a maintenance perspective te shere varity of CLI and API flags is becoming unmaintainable. So we are going to phaseout more and more of those flag in favour of .editorconfig properties.

The problem with ktlint is that it is android-centric and doesn't use official code style.

I don't believe this is true. The default code style if the official Kotlin codestyle. If you want to use android codestyle this has to be specified on the command line or a special flag. When not specifying the ktlint_code_style property in .editorconfig then the offical Kotlin code style is used.

In case your company does not use .editorconfig at all, you might want to look into the CLI/API flag that allows to specify a additional .editorconfig file. This could be the same file for your entire company and as of that can be maintained in a single place. But please do note that it will take precedence on any .editorconfig file that is specified in any of the subprojects.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants