pinterest / ktlint

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

Do not wrap nested reference expressions in `chain-method-continuation` rule #2602

Closed Kolyall closed 7 months ago

Kolyall commented 8 months ago

Version 1.2.1

gradle.properties: android.nonTransitiveRClass=true

Rules:

[{*.gradle.kts,*.kt,*.kts,*.main.kts}]
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
ij_kotlin_align_multiline_parameters = true
ij_kotlin_align_multiline_parameters_in_calls = true
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_block_comment_add_space = true
ij_kotlin_call_parameters_new_line_after_left_paren = true
ij_kotlin_call_parameters_right_paren_on_new_line = true
ij_kotlin_call_parameters_wrap = split_into_lines
ij_kotlin_catch_on_new_line = false
ij_kotlin_class_annotation_wrap = split_into_lines
ij_kotlin_else_on_new_line = false
ij_kotlin_enum_constants_wrap = split_into_lines
ij_kotlin_extends_list_wrap = split_into_lines
ij_kotlin_field_annotation_wrap = split_into_lines
ij_kotlin_finally_on_new_line = false
ij_kotlin_if_rparen_on_new_line = false
ij_kotlin_import_nested_classes = false
ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^
ij_kotlin_insert_whitespaces_in_simple_one_line_method = true
ij_kotlin_keep_blank_lines_in_code = 1
ij_kotlin_keep_blank_lines_in_declarations = 1
ij_kotlin_lbrace_on_next_line = false
ij_kotlin_line_comment_add_space = true
ij_kotlin_line_comment_add_space_on_reformat = true
ij_kotlin_method_annotation_wrap = split_into_lines
ij_kotlin_method_parameters_new_line_after_left_paren = true
ij_kotlin_method_parameters_right_paren_on_new_line = true
ij_kotlin_method_parameters_wrap = split_into_lines
ij_kotlin_name_count_to_use_star_import = 2147483647
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
ij_kotlin_packages_to_use_import_on_demand = kotlinx.android.synthetic.**
ij_kotlin_parameter_annotation_wrap = split_into_lines
ij_kotlin_space_after_comma = true
ij_kotlin_space_after_extend_colon = true
ij_kotlin_space_after_type_colon = true
ij_kotlin_space_before_catch_parentheses = true
ij_kotlin_space_before_comma = false
ij_kotlin_space_before_extend_colon = true
ij_kotlin_space_before_for_parentheses = true
ij_kotlin_space_before_if_parentheses = true
ij_kotlin_space_before_lambda_arrow = true
ij_kotlin_space_before_type_colon = false
ij_kotlin_space_before_when_parentheses = true
ij_kotlin_space_before_while_parentheses = true
ij_kotlin_spaces_around_additive_operators = true
ij_kotlin_spaces_around_assignment_operators = true
ij_kotlin_spaces_around_equality_operators = true
ij_kotlin_spaces_around_function_type_arrow = true
ij_kotlin_spaces_around_logical_operators = true
ij_kotlin_spaces_around_multiplicative_operators = true
ij_kotlin_spaces_around_range = false
ij_kotlin_spaces_around_relational_operators = true
ij_kotlin_spaces_around_unary_operator = false
ij_kotlin_spaces_around_when_arrow = true
ij_kotlin_use_custom_formatting_for_modifiers = true

# KtLint configuration
ktlint_code_style = ktlint_official
ktlint_experimental = enabled
ktlint_standard_package-name = disabled
ktlint_standard_function-expression-body = disabled
ktlint_standard_max-line-length = disabled
ktlint_standard_backing-property-naming = disabled
ktlint_standard_property-naming = disabled
ktlint_standard_no-consecutive-comments = disabled
ktlint_standard_kdoc = disabled
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_filename = disabled
ktlint_standard_comment-wrapping = disabled
ktlint_standard_if-else-wrapping = disabled
ktlint_standard_enum-entry-name-case = disabled
ktlint_standard_no-empty-file = disabled
ktlint_standard_value-parameter-comment = disabled
ktlint_standard_class-naming = disabled
ktlint_standard_value-argument-comment = disabled
ktlint_standard_function-naming = disabled

ktlint_standard_binary-expression-wrapping = disabled
ktlint_standard_no-empty-first-line-in-class-body = disabled
ktlint_standard_no-single-line-block-comment = disabled
ktlint_standard_multiline-if-else = enabled
ktlint_standard_no-blank-line-before-rbrace = enabled
ktlint_standard_no-blank-lines-in-chained-method-calls = enabled
ktlint_standard_no-consecutive-blank-lines = enabled
ktlint_standard_no-empty-class-body = enabled
ktlint_standard_no-empty-first-line-in-method-block = disabled
ktlint_standard_no-line-break-after-else = enabled
ktlint_standard_no-line-break-before-assignment = enabled
ktlint_standard_no-multi-spaces = enabled
ktlint_standard_no-semi = enabled
ktlint_standard_no-unit-return = enabled
ktlint_standard_no-unused-imports = enabled
ktlint_standard_spacing-around-angle-brackets = enabled
ktlint_standard_annotation-spacing = enabled
ktlint_standard_spacing-between-declarations-with-annotations = enabled
ktlint_standard_spacing-between-declarations-with-comments = enabled
ktlint_standard_colon-spacing = enabled
ktlint_standard_comma-spacing = enabled
ktlint_standard_comment-spacing = enabled
ktlint_standard_curly-spacing = enabled
ktlint_standard_dot-spacing = enabled
ktlint_standard_double-colon-spacing = enabled
ktlint_standard_function-return-type-spacing = enabled
ktlint_standard_function-start-of-body-spacing = enabled
ktlint_standard_function-type-reference-spacing = enabled
ktlint_standard_fun-keyword-spacing = enabled
ktlint_standard_kdoc-wrapping = enabled
ktlint_standard_keyword-spacing = enabled
ktlint_standard_modifier-list-spacing = enabled
ktlint_standard_nullable-type-spacing = enabled
ktlint_standard_op-spacing = enabled
ktlint_standard_parameter-list-spacing = enabled
ktlint_standard_paren-spacing = enabled
ktlint_standard_range-spacing = enabled
ktlint_standard_spacing-between-function-name-and-opening-parenthesis = enabled
ktlint_standard_try-catch-finally-spacing = enabled
ktlint_standard_type-argument-list-spacing = enabled
ktlint_standard_type-parameter-list-spacing = enabled
ktlint_standard_unary-op-spacing = enabled
ktlint_standard_string-template = disabled
ktlint_standard_string-template-indent = disabled
# ktlint_standard_trailing-comma-on-call-site = enabled
ktlint_standard_trailing-comma-on-call-site = disabled
# ktlint_standard_trailing-comma-on-declaration-site = enabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
ktlint_standard_type-argument-comment = enabled
ktlint_standard_type-parameter-comment = enabled
ktlint_standard_unnecessary-parentheses-before-trailing-lambda = enabled
ktlint_standard_value-argument-comment = enabled
ktlint_standard_value-parameter-comment = enabled
ktlint_standard_argument-list-wrapping = enabled
ktlint_argument_list_wrapping_ignore_when_parameter_count_greater_or_equal_than = 1
# ktlint_standard_chain-wrapping = enabled
ktlint_standard_chain-wrapping = disabled
ktlint_standard_comment-wrapping = enabled
ktlint_standard_context-receiver-wrapping = enabled
ktlint_standard_enum-wrapping = enabled
ktlint_standard_if-else-wrapping = enabled
ktlint_standard_multiline-expression-wrapping = enabled
ktlint_standard_parameter-list-wrapping = disabled
ktlint_standard_parameter-wrapping = disabled
ktlint_standard_property-wrapping = disabled
ktlint_standard_statement-wrapping = enabled
ktlint_standard_wrapping = disabled

In result:


enum class ActionType(
    val nameType: Int
) {
    FIRST(
        com.basic
            .R
            .string
            .basic__first
    ),
    SECOND(
        com.uikit
            .R
            .string
            .uikit__second
    ),
 }

But expected:

enum class ActionType(
    val nameType: Int
) {
    FIRST(
        com.basic.R.string.basic__first
    ),
    SECOND(
        com.uikit.R.string.uikit__second
    ),
 }
paul-dingemans commented 7 months ago

Tnx for reporting. In #2455 the chain-method-continuation rule was changed to ignore simple reference expression. Your example contains a nested reference expression which also should be ignored.

I have changed the title of the issue to make it better findable for other users that experience the same problem.

Kolyall commented 7 months ago

@paul-dingemans how can I resolve my issue? any configuration should be changed?

paul-dingemans commented 7 months ago

If it is just a single case in which it happens, you might consider to suppress it.