mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
* Compile with `-strict-concurrency=complete` Only in Bazel for now, because this is considered an unsafe flag in SwiftPM which would lead to warnings for downstream consumers of SwiftLint using SwiftPM. Some imports of SwiftSyntax need the `@preconcurrency` annotation until https://github.com/apple/swift-syntax/pull/2322 is available in a release. The following SwiftLint libraries have `-strict-concurrency=complete` applied: * SwiftLintCoreMacros * SwiftLintBuiltInRules * SwiftLintExtraRules The following SwiftLint libraries don't have the flag applied and need to be migrated: * SwiftLintCore * swiftlint (CLI target) So really the rules and macros are now being compiled with `-strict-concurrency=complete`, but the core infrastructure of SwiftLint is not. Still, given that Swift 6 will eventually make these warnings errors by default, it's good to prevent issues from creeping in earlier rather than later. * Add CI job to build with strict concurrency
41 lines
1.3 KiB
Swift
41 lines
1.3 KiB
Swift
import SwiftSyntax
|
|
|
|
@SwiftSyntaxRule
|
|
struct LegacyRandomRule: Rule {
|
|
var configuration = SeverityConfiguration<Self>(.warning)
|
|
|
|
static let description = RuleDescription(
|
|
identifier: "legacy_random",
|
|
name: "Legacy Random",
|
|
description: "Prefer using `type.random(in:)` over legacy functions",
|
|
kind: .idiomatic,
|
|
nonTriggeringExamples: [
|
|
Example("Int.random(in: 0..<10)"),
|
|
Example("Double.random(in: 8.6...111.34)"),
|
|
Example("Float.random(in: 0 ..< 1)")
|
|
],
|
|
triggeringExamples: [
|
|
Example("↓arc4random()"),
|
|
Example("↓arc4random_uniform(83)"),
|
|
Example("↓drand48()")
|
|
]
|
|
)
|
|
}
|
|
|
|
private extension LegacyRandomRule {
|
|
final class Visitor: ViolationsSyntaxVisitor<ConfigurationType> {
|
|
private static let legacyRandomFunctions: Set<String> = [
|
|
"arc4random",
|
|
"arc4random_uniform",
|
|
"drand48"
|
|
]
|
|
|
|
override func visitPost(_ node: FunctionCallExprSyntax) {
|
|
if let function = node.calledExpression.as(DeclReferenceExprSyntax.self)?.baseName.text,
|
|
Self.legacyRandomFunctions.contains(function) {
|
|
violations.append(node.positionAfterSkippingLeadingTrivia)
|
|
}
|
|
}
|
|
}
|
|
}
|