Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Cannot apply default formatting Kotest\StringSpec when migrate from 1.0.1 -> 1.3.0 #2722

Closed
ievgen-kapinos opened this issue Jun 28, 2024 · 5 comments

Comments

@ievgen-kapinos
Copy link

Hi, there!

My team uses in Kotlin projects:

  • Linter: ktlint with codestyle ktlint_code_style = ktlint_official .
  • Formatting via intelliJ Idea IDE plugin Ktlint and Gradle pluginorg.jlleitschuh.gradle.ktlint
  • Test tool: Kotest with StringSpec test style.

Now my team uses ktlint version 1.0.1 (hardcoded in IDE plugin and Gradle plugin). All tests look like it is described in Kotest documentation. See https://kotest.io/docs/framework/testing-styles.html#string-spec

When I try to migrate ktlint to version 1.3.0 all tests have to be reformatted (with extra indent), because they violate rule https://pinterest.github.io/ktlint/1.3.0/rules/standard/#class-signature.

Screenshot 2024-06-28 at 13 46 00

I've tried to set ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than=2 but it did not help.

Issue happens due to approach how tests to be written. It is expected that test classes to be inherited from kotest class. On printscreen above it is StringSpec. This class should be initialised with single argument, lambda function which should contain full code of unit test.

Expected Behavior

class MyTests : StringSpec({
    "strings.length should return size of string" {
        "hello".length shouldBe 5
    }
})

Current Behavior

class MyTests : 
    StringSpec({
        "strings.length should return size of string" {
            "hello".length shouldBe 5
        }
})

Additional information

  • Same problem exist not only with StringSpec test style of the Kotest, but most of them.

We have a tons of tests. Please help to keep them as is.

@paul-dingemans
Copy link
Collaborator

For now, most practical approach will be to disable the class-signature rule. If you want to, you can do this only for test code, or for the entire project.

@ievgen-kapinos
Copy link
Author

Hi @paul-dingemans

It is nice to find you as a maintaner of this repo as well. I appreciate your contribution to community.

I agree with you, it will work as temporary workaround. But in case of multi-module project, let's say 7 sub-modules, we have 7 folders with Tests. Each of them requires copy of .editorconfig file. But if we have many projects like that, then number of files will explode. I have to admit, in some cases (like mine), it is also possible to target all test files in single root .editorconfig file by adding a section [*Test.{kt,kts}].

Anyway, for the latest ktlint it is non-official formatting. Disabling official rules looks smelly.

Could you consider to add support for this case in next versions of ktlint?

Arguments are:

  • It was okay in version 1.0.1
  • Kotest is a popular test framework with lot of extensions. Version 1.3.0 forces useless extra indent of the "full body" of each test file. These files can be really long.
  • There are no benefits put super class/interface on new line, if it is ony one (no other interfaces declared). I suppose, if it will be implemented, then problem with extra indent will be sloved automatically.

@paul-dingemans
Copy link
Collaborator

It was okay in version 1.0.1

You can still upgrade to 1.2.1 in. which the class-signature rule was still experimental.

  • There are no benefits put super class/interface on new line, if it is ony one (no other interfaces declared). I suppose, if it will be implemented, then problem with extra indent will be sloved automatically.

See #2423, #2710 and #2711. I will close this issue as it will not be resolved until the aforementioned issues are resolved. That might take quit a long while though. Until that time, disabling the class-signature is the best you can do, although it feels smelly.

@paul-dingemans paul-dingemans closed this as not planned Won't fix, can't repro, duplicate, stale Jun 29, 2024
@ievgen-kapinos
Copy link
Author

Yeah. I understand the pain and lack of time. As I've understood, you considering this as a "problem".
In this case it is better not to close this issue, but keep it in a backlog.

@paul-dingemans
Copy link
Collaborator

you considering this as a "problem"

Personally I do not consider it a problem but a conscious choice. But as you can read in #2423 there are more people not agreeing with that. Once, and if that issue is resolved, this issue is resolved as well which is the reason that I closed it as being duplicate.

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

No branches or pull requests

2 participants