pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.19k stars 505 forks source link

Allow making requests to engine with raw .editorconfig string, disabling .editorconfig IO. #2537

Closed mgroth0 closed 7 months ago

mgroth0 commented 8 months ago

Description

Fixes https://github.com/pinterest/ktlint/issues/2532

Allows the API user to make requests to the engine with a raw .editorconfig string in like so:

Code.fromSnippet(
                content = "kotlinCode",
                editorConfig = "[*]\nktlint_simple-test_a = disabled",
)
// or
Code.fromSnippetWithPath(
                content = "kotlinCode",
                virtualPath = "/virtual/path.kt", // no .editorconfig IO, but used in `standard:filename`
                editorConfig = "[*]\nktlint_simple-test_a = disabled",
)

This should allow the API user to completely avoid the engine from doing any IO at all in relation to .editorconfig files, providing more flexibility possible(not measured) performance gains, and stability.

Added one simple test to verify that the .editorconfig string is correctly applied. However, more tests and refining the current test would be good.

Did not modify or add any documentation yet.

This is a rough draft. It might be controversial, so I kept it minimal just as an example. If it looks good as is, it just needs better tests and documentation. But I expect reviewers might have opinions on how this should be implemented in a way that enhances flexibility while minimizing confusion and complexity for API users.

Note that the virtualPath for fromSnippetWithPath is still useful and sometimes neccesary, as it gets used in rules that use the file path such as standard:filename.

Checklist

Before submitting the PR, please check following (checks which are not relevant may be ignored):

Documentation is updated. See difference between snapshot and release documentation

paul-dingemans commented 7 months ago

As documented in #2532 this feature will not be integrated in ktlint. The idea behind this request seems valid, but the targeted user group is way too small for this moment. Next to that, the proposed change causes multiple breaking changes for the existing integrators.