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 consider_default_literal_types_redundant option to RedundantTypeAnnotationRule #4756

Merged
Prev Previous commit
Next Next commit
Improve implementation
garricn committed May 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 13b368153a89a3225ac57b891423807c7da27004
Original file line number Diff line number Diff line change
@@ -234,14 +234,14 @@ private extension TypeAnnotationSyntax {
// Consider the type annotation redundant if `considerLiteralsRedundant` is true and the expression is one of
// the supported compiler-inferred literals.
if considerLiteralsRedundant {
return isCompilerInferredLiteral(expression: initializer)
return isCompilerInferredLiteral(initializer)
SimplyDanny marked this conversation as resolved.
Show resolved Hide resolved
}
return initializer.accessedNames.contains(type.trimmedDescription)
}

// Returns true if the expression is one of the supported compiler-inferred literals.
private func isCompilerInferredLiteral(expression: ExprSyntax) -> Bool {
return switch expression {
private func isCompilerInferredLiteral(_ expr: ExprSyntax) -> Bool {
SimplyDanny marked this conversation as resolved.
Show resolved Hide resolved
switch expr {
SimplyDanny marked this conversation as resolved.
Show resolved Hide resolved
case let expr where expr.is(BooleanLiteralExprSyntax.self):
type.trimmedDescription == "Bool"
case let expr where expr.is(FloatLiteralExprSyntax.self):