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

Incorrect indent for a property that wraps to two lines and has a custom getter or setter #1335

Closed
dmytroKarataiev opened this issue Jan 11, 2022 · 0 comments · Fixed by #1468

Comments

@dmytroKarataiev
Copy link

Expected Behavior

When a property wraps to two lines and has a custom getter or setter it should have the following indents:

    private var savedAdapterState: PerformanceSpinnerSelections? =
        savedStateHandle.get<PerformanceSpinnerSelections>(SAVED_ADAPTER_STATE)
            set(value) {
                field = value
                savedStateHandle.set(SAVED_ADAPTER_STATE, value)
            }

Observed Behavior

That's what ktlint wants:

    private var savedAdapterState: PerformanceSpinnerSelections? =
        savedStateHandle.get<PerformanceSpinnerSelections>(SAVED_ADAPTER_STATE)
        set(value) {
                field = value
                savedStateHandle.set(SAVED_ADAPTER_STATE, value)
            }

That's what Android Studio wants:

    private var savedAdapterState: PerformanceSpinnerSelections? =
        savedStateHandle.get<PerformanceSpinnerSelections>(SAVED_ADAPTER_STATE)
        set(value) {
            field = value
            savedStateHandle.set(SAVED_ADAPTER_STATE, value)
        }

Steps to Reproduce

The code above or really any code where a property is very long and has a custom setter/getter would work.

Your Environment

  • Version of ktlint used: 0.43.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): custom gradle task from the ktlint documentation
  • Version of Gradle used (if applicable): Android tools build gradle 4.2.2, gradle 7.0.1
  • Operating System and version: mac os big sur (11.6)
@paul-dingemans paul-dingemans added this to the 0.46.0 milestone Mar 17, 2022
paul-dingemans pushed a commit to paul-dingemans/ktlint that referenced this issue May 12, 2022
paul-dingemans added a commit that referenced this issue May 20, 2022
)

* Fix indentation of the body block/expression of the getter/setter of a property when that property is followed by an initializer on a separate line.

Closes #1335

* cleanup

Closes #1335

* Remove tests related to other (yet unresolved) issue

* Remove unused import

* merge master

Co-authored-by: = <=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants