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

contrasted_opening_brace false positives in trailing closures and else if statements #5752

Closed
2 tasks done
buresdv opened this issue Aug 14, 2024 · 3 comments · Fixed by #5761
Closed
2 tasks done

Comments

@buresdv
Copy link

buresdv commented Aug 14, 2024

New Issue Checklist

Feature or Enhancement Proposal

I'm using the new contrasted_opening_brace rule. I ran across a potential false positive (at least in my opinion) when this rule is used on trailing closures that include parameters.

Examples include (lifted straight from my codebase):

return allDependencies.map
{ dependency in // <-- Violation here
    .init(name: dependency.fullName, version: dependency.version, directlyDeclared: dependency.declaredDirectly)
}
let originalServicesWithTheirUUIDs: [String: UUID] = services.reduce(into: [:])
{ result, originalService in // <-- Violation here
    result[originalService.name] = originalService.id
}
return AsyncStream
{ continuation in // <-- Violation here
}

I'd expect this rule to not consider these examples violations. Perhaps there could be a setting that would not flag these.

@buresdv
Copy link
Author

buresdv commented Aug 14, 2024

Some closures report a false positive even without the parameters:

Text("add-package.install.wrong-architecture.title")
        .onAppear
        { // <-- Violation here
            packageInstallationProcessStep = .wrongArchitecture
        }
Text(currentMaintenanceStepText)
        .task(priority: .userInitiated)
        { // <-- Violation here
        }

Another potentionally related false positive occurs in long else-if chains (don't judge me 😅 )
Snímek obrazovky 2024-08-14 v 22 44 06

Snímek obrazovky 2024-08-14 v 22 45 37

There's also another potential false positive in this case, which I'm not sure how to describe (perhaps I should make a separate issue for this one?)
Snímek obrazovky 2024-08-14 v 22 49 47

@buresdv buresdv changed the title contrasted_opening_brace false positives in trailing closures with parameters contrasted_opening_brace false positives in trailing closures and else if statements Aug 14, 2024
@buresdv
Copy link
Author

buresdv commented Aug 19, 2024

@SimplyDanny you're the man

@SimplyDanny
Copy link
Collaborator

@buresdv: Formatting rules often rely on heuristics and so does this rule now especially in terms of the fixes I made to cover your reported misbehavior. So you might find other issues afterwards which we need to address in an iterative manner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants