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

Update documentation for TrailingComma rules #5513

Merged
merged 5 commits into from Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -166,3 +166,6 @@ target/
/website/docs/rules/*.md
/website/static/kdoc
/website/docs/gettingstarted/_cli-options.md

# Jenv
.java-version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure this should be .gitignored. I'm actually in favor of having a .java-version in the root folder

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but everyone's .java-version content will be different depending on the exact minor/patch version

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe open a separate PR for this? I'm otherwise happy to merge this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we should move this to another pr. This PR is the last thing that we need to release 1.22.0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but everyone's .java-version content will be different depending on the exact minor/patch version

You should be able to have just the major version (like 11) inside .java-version and that will be picked up correctly by jenv

Expand Up @@ -3,22 +3,32 @@ package io.gitlab.arturbosch.detekt.formatting.wrappers
import com.pinterest.ktlint.core.api.UsesEditorConfigProperties
import com.pinterest.ktlint.ruleset.standard.TrailingCommaOnCallSiteRule
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.config
import io.gitlab.arturbosch.detekt.api.configWithAndroidVariants
import io.gitlab.arturbosch.detekt.api.internal.AutoCorrectable
import io.gitlab.arturbosch.detekt.api.internal.Configuration
import io.gitlab.arturbosch.detekt.formatting.FormattingRule

/**
* See [ktlint docs](https://pinterest.github.io/ktlint/rules/standard/) for documentation.
*
* The default config comes from ktlint and follows these conventions:
* - [Kotlin coding convention](https://kotlinlang.org/docs/coding-conventions.html#trailing-commas) recommends
* trailing comma encourage the use of trailing commas at the declaration site and
* leaves it at your discretion for the call site.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'd suggested adding a reference to the Android style guide? Though that style guide doesn't say anything about trailing commas, so I expect we will get some issues raised.

Perhaps instead it can be made clear that the defaults match upstream ktlint.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will emphasize ktlint here

* - [Android Kotlin style guide](https://developer.android.com/kotlin/style-guide) does not include
* trailing comma usage yet.
*/
@AutoCorrectable(since = "1.22.0")
class TrailingCommaOnCallSite(config: Config) : FormattingRule(config) {

override val wrapping = TrailingCommaOnCallSiteRule()
override val issue = issueFor("Rule to mandate/forbid trailing commas at call sites")

@Configuration("Defines whether a trailing comma (or no trailing comma) should be enforced at call sites")
private val useTrailingCommaOnCallSite by config(false)
@Configuration("Defines whether trailing commas are required (true) or forbidden (false) at call sites")
private val useTrailingCommaOnCallSite by configWithAndroidVariants(
defaultValue = true,
defaultAndroidValue = false,
)

override fun overrideEditorConfigProperties(): Map<UsesEditorConfigProperties.EditorConfigProperty<*>, String> =
mapOf(
Expand Down
Expand Up @@ -3,22 +3,32 @@ package io.gitlab.arturbosch.detekt.formatting.wrappers
import com.pinterest.ktlint.core.api.UsesEditorConfigProperties
import com.pinterest.ktlint.ruleset.standard.TrailingCommaOnDeclarationSiteRule
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.config
import io.gitlab.arturbosch.detekt.api.configWithAndroidVariants
import io.gitlab.arturbosch.detekt.api.internal.AutoCorrectable
import io.gitlab.arturbosch.detekt.api.internal.Configuration
import io.gitlab.arturbosch.detekt.formatting.FormattingRule

/**
* See [ktlint docs](https://pinterest.github.io/ktlint/rules/standard/) for documentation.
*
* The default config comes from ktlint and follows these conventions:
* - [Kotlin coding convention](https://kotlinlang.org/docs/coding-conventions.html#trailing-commas) recommends
* trailing comma encourage the use of trailing commas at the declaration site and
* leaves it at your discretion for the call site.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above

* - [Android Kotlin style guide](https://developer.android.com/kotlin/style-guide) does not include
* trailing comma usage yet.
*/
@AutoCorrectable(since = "1.22.0")
class TrailingCommaOnDeclarationSite(config: Config) : FormattingRule(config) {

override val wrapping = TrailingCommaOnDeclarationSiteRule()
override val issue = issueFor("Rule to mandate/forbid trailing commas at declaration sites")

@Configuration("Defines whether a trailing comma (or no trailing comma) should be enforced at declaration sites")
private val useTrailingCommaOnDeclarationSite by config(false)
@Configuration("Defines whether trailing commas are required (true) or forbidden (false) at declaration sites")
private val useTrailingCommaOnDeclarationSite by configWithAndroidVariants(
defaultValue = true,
defaultAndroidValue = false,
)

override fun overrideEditorConfigProperties(): Map<UsesEditorConfigProperties.EditorConfigProperty<*>, String> =
mapOf(
Expand Down
4 changes: 2 additions & 2 deletions detekt-formatting/src/main/resources/config/config.yml
Expand Up @@ -182,11 +182,11 @@ formatting:
TrailingCommaOnCallSite:
active: false
autoCorrect: true
useTrailingCommaOnCallSite: false
useTrailingCommaOnCallSite: true
TrailingCommaOnDeclarationSite:
active: false
autoCorrect: true
useTrailingCommaOnDeclarationSite: false
useTrailingCommaOnDeclarationSite: true
TypeArgumentListSpacing:
active: false
autoCorrect: true
Expand Down