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

Add new rule to rewrite the class signature #1349

Closed
fzyzcjy opened this issue Jan 25, 2022 · 5 comments · Fixed by #2119
Closed

Add new rule to rewrite the class signature #1349

fzyzcjy opened this issue Jan 25, 2022 · 5 comments · Fixed by #2119

Comments

@fzyzcjy
Copy link

fzyzcjy commented Jan 25, 2022

EDIT: I can workaround by avoiding writing code like this (instead let the constructor be at the same line with class name). I just want to report it so you can know that it happens, but please make this a low priority.


Hi thanks for the lib! For the following code, intellij idea thinks there should be 4 spaces at (message: String?) while ktlint thinks 0.

cat ~/temp/a.kt && java -jar /Users/tom/opt/ktlint-0.44.0-20220123.092956-49-all.jar ~/temp/a.kt --debug       
package hello

class MyException
    (message: String?) : RuntimeException(message)
[DEBUG] Discovered reporter with "baseline" id.
[DEBUG] Discovered reporter with "checkstyle" id.
[DEBUG] Discovered reporter with "json" id.
[DEBUG] Discovered reporter with "html" id.
[DEBUG] Discovered reporter with "plain" id.
[DEBUG] Discovered reporter with "sarif" id.
[DEBUG] Initializing "plain" reporter with {verbose=false, color=false, color_name=DARK_GRAY}
[DEBUG] Rule with id 'standard:max-line-length' should run after the rule with id 'experimental:trailing-comma'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
[DEBUG] Rules will be executed in order below (unless disabled):
           - standard:filename, 
           - standard:final-newline, 
           - standard:chain-wrapping, 
           - standard:colon-spacing, 
           - standard:comma-spacing, 
           - standard:comment-spacing, 
           - standard:curly-spacing, 
           - standard:dot-spacing, 
           - standard:import-ordering, 
           - standard:keyword-spacing, 
           - standard:modifier-order, 
           - standard:no-blank-line-before-rbrace, 
           - standard:no-consecutive-blank-lines, 
           - standard:no-empty-class-body, 
           - 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:op-spacing, 
           - standard:parameter-list-wrapping, 
           - standard:paren-spacing, 
           - standard:range-spacing, 
           - standard:string-template, 
           - standard:indent, 
           - standard:max-line-length
[DEBUG] Checking /Users/tom/temp/a.kt
Resolving .editorconfig files for /Users/tom/temp/a.kt file path
Loaded .editorconfig: []
/Users/tom/temp/a.kt:1:1: class MyException should be declared in a file named MyException.kt (cannot be auto-corrected)
/Users/tom/temp/a.kt:4:1: Unexpected indentation (4) (should be 0)
[DEBUG] 784ms / 1 file(s) / 2 error(s)
@fzyzcjy fzyzcjy changed the title Indentation disagree with Intellij IDEA Indentation disagree with Intellij IDEA for code like class A\n() Jan 26, 2022
@paul-dingemans
Copy link
Collaborator

A new rule needs to be written to format class headers accordingly to the https://kotlinlang.org/docs/coding-conventions.html#class-headers

@paul-dingemans paul-dingemans changed the title Indentation disagree with Intellij IDEA for code like class A\n() Add new rule to rewrite the class signature Jan 26, 2022
@paul-dingemans
Copy link
Collaborator

paul-dingemans commented Jan 26, 2022

Duplicates #1097, #941

@romtsn
Copy link
Collaborator

romtsn commented Jan 27, 2022

We should close it if it's a duplicate I think

@georgi-mirchev
Copy link

Any updates on this one?

@paul-dingemans
Copy link
Collaborator

Any updates on this one?

Nope. Also it is not likely to be picked up soon, at least not by me. Please feel free to contribute if you would like to have this on short term.

@paul-dingemans paul-dingemans added this to the 1.0 (Yeah!) milestone Apr 16, 2023
@paul-dingemans paul-dingemans self-assigned this Jul 3, 2023
paul-dingemans added a commit that referenced this issue Jul 9, 2023
…consistent format. In code style `ktlint_official`, super types are always wrapped to a separate line. In other code styles, super types are only wrapped in classes having multiple super types. Especially for code style `ktlint_official` the class headers are rewritten in a more consistent format.

Closes #875
Closes #1349
paul-dingemans added a commit that referenced this issue Jul 21, 2023
* Add rule `class-signature`. This rule rewrites the class header to a consistent format. In code style `ktlint_official`, super types are always wrapped to a separate line. In other code styles, super types are only wrapped in classes having multiple super types. Especially for code style `ktlint_official` the class headers are rewritten in a more consistent format.

Closes #875
Closes #1349

* Add disallowed comments locations for value argument, type argument, value parameter and type parameter lists so that the ClassSignatureRule does not need to check for this

* Fix indentation for class having explicit constructor in ktlint_official code style
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.

4 participants