question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KotlinPlugin should not enforce .editorconfig of the rootProject to be passed to Ktlint

See original GitHub issue

Current: Creating a .editorconfig at the root of the project with a section name matching a directory name will never match.

Example of project structure:

.editorconfig
build.gradle.kts
src/main/FileWithLintError.kt
src/test/NonToBeChecked.kt

Example of .editorconfig:

root = true

[**/main/**.{kt,kts}]
max_line_length=5

Ktlint will not apply the parameter from the .editorconfig. The purpose here is to have a specific parameter for main sources and another one for test sources.

Expected:: Creating a .editorconfig at the root of the project with a section name matching a directory name will match and apply the parameter from the section.

The issue is that the the .editorconfig from the rootProject will be passed as editorconfig path if one exist

fast forward, this parameter is passed to ktlint in the LintWorkerRunnable :

fast forward, the editor path will be used as alternativeEditorConfig in ktlint

The file path (the file that is being check) will be change, as alternativeEditorConfig is not null: instead of being src/main/FileWithLintError.kt it will be <fullpath of .editorconfig>/FileWithLintError.kt. This new path is used only for section matching, and in this case will not match again the section from our .editorconfigfile. as <fullpath of .editorconfig>/FileWithLintError.kt. will not match against [**/main/**.{kt,kts}]

You can confirm this behaviour (path change of the file analysed) using the test of ktlint: https://github.com/pinterest/ktlint/blob/master/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoaderTest.kt#L267

Proposed workaround: Creating a .editorconfig in all directories excepting in the root directory. It will work only with project with with submodules.

Proposed fixed: The editorconfig path should not be enforced by default but being a parameter of the plugin extension with null value by default (ktlint should find the root editorconfig file anyway).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jeremymailencommented, Aug 19, 2020

I’ll bundle this change with an upgrade to Kotlin 1.4 🤞

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ktlint
Some rules do allow further configuration, but in all cases a reasonable default is set when not provided. ktlint primarily uses the .editorconfig...
Read more >
ktlint not checking kotlin file - Stack Overflow
1 Answer 1 ; import org.jlleitschuh.gradle.ktlint.reporter.ReporterType // for Ktlint reports ; "1.4.10" // Kotlin Compiler ; "1.4.10" // ...
Read more >
Migrate to Kotlin code style
Enable the official code style formatting by default starting from Kotlin 1.3 and only for new projects (old formatting can be enabled manually)....
Read more >
Cleaner pull requests for Kotlin & Java code
Recently I looked into reducing the noise from our pull requests. The bulk of the effort involved setting up a code styling guide, ......
Read more >
diffplug - Bountysource
I started with the Gradle Plugin integration, but once thats done, would be ... This makes it very hard, if not impossible, to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found