This product is not supported for your selected Datadog site. ().
このページは日本語には対応しておりません。随時翻訳に取り組んでいます。
翻訳に関してご質問やご意見ございましたら、お気軽にご連絡ください

Metadata

ID: swift-code-style/increment-decrement-single-stmt

Language: Unknown

Severity: Notice

Category: Best Practices

Description

Increments (++) or decrements (--) should be single statements. This rule is important because it helps to avoid confusion and potential errors in your code. When increments or decrements are combined with other operations, it can be difficult to understand the order in which the operations are performed. This can lead to unexpected results and bugs in your code.

Non-Compliant Code Examples

foo = ++bar - baz--
foo = bar++

foo(bar++)

Compliant Code Examples

++foo
bar++
--foo
func factorial(_ n: Int) -> Int {
    guard n >= 0 else {
        foo++
    }
    --bar
    return n == 0 ? 1 : n * factorial(n - 1)
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

シームレスな統合。 Datadog Code Security をお試しください