-
Notifications
You must be signed in to change notification settings - Fork 506
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
Fixes/1078/statement wrap after semi #2065
Fixes/1078/statement wrap after semi #2065
Conversation
0ee341d
to
72b6361
Compare
Add multiple entries, enums and assertions
ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/ReporterAggregator.kt
Show resolved
Hide resolved
...ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRule.kt
Show resolved
Hide resolved
...ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRule.kt
Show resolved
Hide resolved
...set-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRuleTest.kt
Outdated
Show resolved
Hide resolved
...set-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRuleTest.kt
Outdated
Show resolved
Hide resolved
...set-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRuleTest.kt
Outdated
Show resolved
Hide resolved
val lambda: () -> Unit = { } | ||
} | ||
""".trimIndent() | ||
wrappingRuleAssertThat(code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In tests like this also add .addAdditionalRuleProvider { NoSemicolonsRule() }
so that the formatted result also has cleaned up the unwanted semicolon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But as per the doc of addAdditionalRuleProvider
, it runs before the rule which is getting unit tested An additional rule provider for a rule which actually is executed before the rule under test,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not always lead to problems. You can always try to add it anyways and document it like below:
.hasLintViolations(
// Some violations below are only reported during linting but not on formatting. After wrapping the
// nullable type, there is no need to wrap the parameters.
LintViolation(2, 12, "Expected new line before function type as it does not fit on a single line"),
LintViolation(2, 13, "Parameter should start on a newline"),
LintViolation(2, 24, "Parameter should start on a newline"),
LintViolation(2, 35, "Parameter should start on a newline"),
LintViolation(2, 44, "Missing newline before \")\""),
LintViolation(2, 53, "Expected new line after function type as it does not fit on a single line"),
).isFormattedAs(formattedCode)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added addAdditionalRuleProvider
and it really cleaned semicolons 😅 It seems even after An additional rule provider for a rule which actually is executed before the rule under test,
due to constraints NoSemicolonsRule
make sure that it is run after the WrappingRuleTest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I have not added addAdditionalRuleProvider
as I also wanted to test this rule w/o NoSemicolonsRule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Downside is that it is now sometime confusing why the NoSemicolonsRule
is not present in some test while it is added in other tests. As the default behavior of ktlint is to run both rules, I prefer to add the rule because the formattedCode in that case looks closest to the normal behavior of ktlint.
But when there is a specific need in a test to also validate the end result in case the rule is disabled, then I would suggest to make it explicit in the name of the test or with a comment why the the NoSemicolonsRule
is not added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this makes more sense. I have added one TC Given two variables run without NoSemicolonsRule
...set-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRuleTest.kt
Outdated
Show resolved
Hide resolved
...set-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRuleTest.kt
Outdated
Show resolved
Hide resolved
Split TCs into smaller ones Rename `insertNewLineBeforeSemi` to `insertNewLineAfterSemi`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tnx for addessing the review comments. The tests are way more readable now. I adressed one more issue.
...set-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRuleTest.kt
Outdated
Show resolved
Hide resolved
Create a TC w/o `addAdditionalRuleProvider` Rename `INDEX` enum to `FOO` enums
Tnx for the contributation @atulgpt ! |
Description
Add the
SEMICOLON
branch inWrappingRule
and insert a newline after the semicolonFixes: #1078
Checklist
CHANGELOG.md
is updated