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

Class and function header format rules, autocorrection for IndentionRule #137

Merged

Conversation

MyDogTom
Copy link
Contributor

This PR contains

Changes from #126 and #118 are included into current PR.

New rule notes

Applies to class definition (eg. primary constructor), secondary constructor and function.
Wrapping is needed in two cases:

  • line break is already present
  • overall header length exceeds maximum allowed line length

Example

class WithLongClassHeader(parameter1: Int, parameter2: Int, parameter3: Int) {
    constructor(parameter1: Int, parameter2: Int, parameter3: Int) {
    }

    fun withLongDefinition(param1: Int, parameter2: Int, parameter3: Int): String {
        return " "
    }
}

becomes this

class WithLongClassHeader(
    parameter1: Int,
    parameter2: Int,
    parameter3: Int
) {
    constructor(
        parameter1: Int,
        parameter2: Int,
        parameter3: Int
    ) {
    }

    fun withLongDefinition(
        param1: Int,
        parameter2: Int,
        parameter3: Int
    ): String {
        return " "
    }
}

See tests for more examples

Because rule is more strict now
Auto correction is disabled for parameters, because expected indent is not defined (parameter can be indented by multiple of "regular indent")
# Conflicts:
#	ktlint/src/main/kotlin/com/github/shyiko/ktlint/Main.kt
Parameters should be placed either on one line, either each parameter on new line

Extracted indention size definition in separate class. This allows to avoid duplication between rules
# Conflicts:
#	ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRule.kt
…t' into mydogtom/indention-complete

# Conflicts:
#	ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRule.kt
#	ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRuleTest.kt
Applies only when header take more than one line
Because it will be reused in other rules
Because it's responsible for complete header formatting, not only parameters
@shyiko
Copy link
Collaborator

shyiko commented Jan 13, 2018

Thank you, @MyDogTom! Merging right in!

@shyiko shyiko merged commit 2c320de into pinterest:master Jan 13, 2018
@MyDogTom MyDogTom deleted the mydogtom/class-function-header-format branch January 13, 2018 20:32
@stalexxx stalexxx mentioned this pull request Jan 23, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants