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

Wrapping rule not working from cli #2170

Closed
atulgpt opened this issue Aug 8, 2023 · 1 comment · Fixed by #2178
Closed

Wrapping rule not working from cli #2170

atulgpt opened this issue Aug 8, 2023 · 1 comment · Fixed by #2178
Assignees
Milestone

Comments

@atulgpt
Copy link
Contributor

atulgpt commented Aug 8, 2023

Expected Behavior

For the code below

package com.pinterest.ktlint.ruleset.standard.rules.test

public fun foo() { var result = 0
}

when running the command ktlint -F --experimental it should be formatted as the below code

package com.pinterest.ktlint.ruleset.standard.rules.test

public fun foo() {
    var result = 0
}

Observed Behavior

Ran the command ktlint -F --experimental --log-level=debug but nothing happened

The output of the above command
02:47:26.411 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintCommandLine - Add editor config override to allow the experimental rule set
02:47:26.429 [main] INFO com.pinterest.ktlint.cli.internal.KtlintCommandLine - Enable default patterns [**/*.kt, **/*.kts]
02:47:26.433 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered RuleSetProviderV3 with id 'standard' in ktlint JAR
02:47:26.539 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'baseline' in ktlint JAR
02:47:26.539 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'plain' in ktlint JAR
02:47:26.539 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'checkstyle' in ktlint JAR
02:47:26.539 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'json' in ktlint JAR
02:47:26.539 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'format' in ktlint JAR
02:47:26.539 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'html' in ktlint JAR
02:47:26.539 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'plain-summary' in ktlint JAR
02:47:26.539 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintServiceLoader - Discovered ReporterProviderV2 with id 'sarif' in ktlint JAR
02:47:26.540 [main] DEBUG com.pinterest.ktlint.cli.internal.ReporterAggregator - Initializing "plain" reporter with {plain=true, color=false, color_name=DARK_GRAY, format=true}
02:47:26.544 [main] DEBUG com.pinterest.ktlint.cli.internal.FileUtils - Start walkFileTree from directory: '/Users/atulgup/Learning/open_source/ktlint/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/test'
02:47:26.547 [main] DEBUG com.pinterest.ktlint.cli.internal.FileUtils - Discovered 1 files to be processed in 3 ms
02:47:26.558 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine - Starting with formatting file 'T.kt'
02:47:26.815 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.EditorConfigLoader - Effective editorconfig properties for file '/Users/atulgup/Learning/open_source/ktlint/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/test/T.kt':
        indent_style: space
        indent_size: 4
        max_line_length: 140
        end_of_line: lf
        charset: utf-8
        trim_trailing_whitespace: true
        insert_final_newline: true
        tab_width: 4
        ktlint_code_style: ktlint_official
        ktlint_ignore_back_ticked_identifier: true
        ktlint_standard: enabled
        ktlint_experimental: enabled
        ij_kotlin_packages_to_use_import_on_demand: unset
        ij_kotlin_name_count_to_use_star_import: 99
        ij_kotlin_name_count_to_use_star_import_for_members: 99
02:47:26.829 [pool-1-thread-1] DEBUG com.pinterest.ktlint.rule.engine.internal.RuleProviderSorter - Rules will be executed in order below:
           - standard:annotation-spacing, 
           - standard:chain-wrapping, 
           - standard:class-naming, 
           - standard:colon-spacing, 
           - standard:comma-spacing, 
           - standard:comment-spacing, 
           - standard:comment-wrapping, 
           - standard:context-receiver-wrapping, 
           - standard:curly-spacing, 
           - standard:discouraged-comment-location, 
           - standard:dot-spacing, 
           - standard:double-colon-spacing, 
           - standard:enum-entry-name-case, 
           - standard:enum-wrapping, 
           - standard:filename, 
           - standard:final-newline, 
           - standard:fun-keyword-spacing, 
           - standard:function-naming, 
           - standard:function-return-type-spacing, 
           - standard:function-start-of-body-spacing, 
           - standard:function-type-reference-spacing, 
           - standard:if-else-bracing, 
           - standard:import-ordering, 
           - standard:kdoc-wrapping, 
           - standard:keyword-spacing, 
           - standard:modifier-list-spacing, 
           - standard:modifier-order, 
           - standard:multiline-expression-wrapping, 
           - standard:multiline-if-else, 
           - standard:no-blank-line-before-rbrace, 
           - standard:no-blank-line-in-list, 
           - standard:no-blank-lines-in-chained-method-calls, 
           - standard:no-consecutive-blank-lines, 
           - standard:no-consecutive-comments, 
           - standard:no-empty-class-body, 
           - standard:no-empty-first-line-in-class-body, 
           - standard:no-empty-first-line-in-method-block, 
           - standard:no-line-break-after-else, 
           - standard:no-line-break-before-assignment, 
           - standard:no-multi-spaces, 
           - standard:no-semi, 
           - standard:no-trailing-spaces, 
           - standard:no-unit-return, 
           - standard:no-unused-imports, 
           - standard:no-wildcard-imports, 
           - standard:nullable-type-spacing, 
           - standard:op-spacing, 
           - standard:package-name, 
           - standard:parameter-list-spacing, 
           - standard:parameter-list-wrapping, 
           - standard:parameter-wrapping, 
           - standard:paren-spacing, 
           - standard:property-naming, 
           - standard:property-wrapping, 
           - standard:range-spacing, 
           - standard:spacing-around-angle-brackets, 
           - standard:spacing-between-declarations-with-annotations, 
           - standard:spacing-between-declarations-with-comments, 
           - standard:spacing-between-function-name-and-opening-parenthesis, 
           - standard:string-template, 
           - standard:try-catch-finally-spacing, 
           - standard:type-argument-list-spacing, 
           - standard:type-parameter-list-spacing, 
           - standard:unary-op-spacing, 
           - standard:unnecessary-parentheses-before-trailing-lambda, 
           - standard:annotation, 
           - standard:if-else-wrapping, 
           - standard:no-single-line-block-comment, 
           - standard:wrapping, 
           - standard:argument-list-wrapping, 
           - standard:function-signature, 
           - standard:trailing-comma-on-call-site, 
           - standard:trailing-comma-on-declaration-site, 
           - standard:indent, 
           - standard:block-comment-initial-star-alignment, 
           - standard:string-template-indent, 
           - standard:max-line-length
02:47:26.853 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintCommandLine - Finished processing in 423ms / 1 file(s) scanned / 0 error(s) found
02:47:26.855 [main] DEBUG com.pinterest.ktlint.cli.internal.KtlintCommandLine - Exit ktlint with exit code: 0

Steps to Reproduce

I am able to produce this with the below code

package com.pinterest.ktlint.ruleset.standard.rules.test

public fun foo() { var result = 0
}

Surprisingly below TC is passing

@Test
fun `Given a code with wrong formatted`() {
    val code =
        """
        public fun foo() { var result = 0
        }
        """.trimIndent()
    val formattedCode =
        """
        public fun foo() {
            var result = 0
        }
        """.trimIndent()
    wrappingRuleAssertThat(code)
        .addAdditionalRuleProvider { NoSemicolonsRule() }
        .isFormattedAs(formattedCode)
}

Your Environment

  • Version of ktlint used: 0.50.0
  • Relevant parts of the .editorconfig settings: I didn't provide any .editorconfig and ran this inside the ktlint repo
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): Using CLI from Homebrew
  • Version of Gradle used (if applicable): 8.2.1
  • Operating System and version: macOS Monterey Version 12.3(Apple silicon)
@paul-dingemans
Copy link
Collaborator

Yesterday, I discovered exact same problem and created #2176 for it. The rule is missing in the StandardRuleProvider which was not discovered by the unit tests as the class StatementWrapping is missing the Rule suffix.

@paul-dingemans paul-dingemans added this to the 1.0 (Yeah!) milestone Aug 12, 2023
@paul-dingemans paul-dingemans self-assigned this Aug 12, 2023
paul-dingemans added a commit that referenced this issue Aug 12, 2023
 Closes #2170

 Align names of Rule classes, file and `RULE_ID` constants

 Closes #2176

 Do not wrap a single line enum class

 Closes #2177
paul-dingemans added a commit that referenced this issue Aug 12, 2023
* Add rule `statement-wrapping` to the `StandardRuleSetProvider` and remove `statement-wrapping` rule from release docs (`0.50`) as the rule is not run by Ktlint CLI

 Closes #2170

 Align names of Rule classes, file and `RULE_ID` constants

 Closes #2176

 Do not wrap a single line enum class

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

Successfully merging a pull request may close this issue.

2 participants