diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 210cbb5915..cd9ba72a07 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -5,6 +5,14 @@ steps: - bazel build :swiftlint - echo "+++ Test" - bazel test --test_output=errors //Tests/... + - label: "Build With Strict Concurrency" + commands: + - echo "+++ Add @preconcurrency imports" + - ./tools/add-preconcurrency-imports.sh + - echo "+++ Build" + - bazel build --define strict_concurrency_builtin_rules=true :swiftlint + - echo "--- Clean up" + - git reset --hard - label: "SwiftPM" commands: - echo "+++ Test" diff --git a/BUILD b/BUILD index 75f00b2bbe..c2ca64d5f1 100644 --- a/BUILD +++ b/BUILD @@ -6,17 +6,27 @@ load( "swift_library", ) +config_setting( + name = "strict_concurrency_builtin_rules", + values = {"define": "strict_concurrency_builtin_rules=true"}, +) + copts = [ "-enable-upcoming-feature", "ExistentialAny", ] +strict_concurrency_copts = [ + "-Xfrontend", + "-strict-concurrency=complete", +] + # Targets swift_library( name = "SwiftLintCoreMacrosLib", srcs = glob(["Source/SwiftLintCoreMacros/*.swift"]), - copts = copts, + copts = copts + strict_concurrency_copts, module_name = "SwiftLintCoreMacros", visibility = ["//visibility:public"], deps = [ @@ -28,7 +38,7 @@ swift_library( swift_compiler_plugin( name = "SwiftLintCoreMacros", srcs = glob(["Source/SwiftLintCoreMacros/*.swift"]), - copts = copts, + copts = copts + strict_concurrency_copts, deps = [ "@SwiftSyntax//:SwiftCompilerPlugin_opt", "@SwiftSyntax//:SwiftSyntaxMacros_opt", @@ -38,7 +48,7 @@ swift_compiler_plugin( swift_library( name = "SwiftLintCore", srcs = glob(["Source/SwiftLintCore/**/*.swift"]), - copts = copts, + copts = copts, # TODO: strict_concurrency_copts module_name = "SwiftLintCore", plugins = [ ":SwiftLintCoreMacros", @@ -62,7 +72,10 @@ swift_library( swift_library( name = "SwiftLintBuiltInRules", srcs = glob(["Source/SwiftLintBuiltInRules/**/*.swift"]), - copts = copts, + copts = copts + select({ + ":strict_concurrency_builtin_rules": strict_concurrency_copts, + "//conditions:default": [], + }), module_name = "SwiftLintBuiltInRules", visibility = ["//visibility:public"], deps = [ @@ -76,6 +89,7 @@ swift_library( "Source/SwiftLintExtraRules/Exports.swift", "@swiftlint_extra_rules//:extra_rules", ], + copts = copts + strict_concurrency_copts, module_name = "SwiftLintExtraRules", visibility = ["//visibility:public"], deps = [ @@ -88,7 +102,7 @@ swift_library( srcs = glob( ["Source/SwiftLintFramework/**/*.swift"], ), - copts = copts, + copts = copts + strict_concurrency_copts, module_name = "SwiftLintFramework", visibility = ["//visibility:public"], deps = [ @@ -101,7 +115,7 @@ swift_library( swift_library( name = "swiftlint.library", srcs = glob(["Source/swiftlint/**/*.swift"]), - copts = copts, + copts = copts, # TODO: strict_concurrency_copts module_name = "swiftlint", visibility = ["//visibility:public"], deps = [ @@ -114,7 +128,7 @@ swift_library( swift_binary( name = "swiftlint", - copts = copts, + copts = copts + strict_concurrency_copts, visibility = ["//visibility:public"], deps = [ ":swiftlint.library", diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/DiscouragedNoneNameRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/DiscouragedNoneNameRule.swift index 5a38578b4c..57860059e1 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/DiscouragedNoneNameRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/DiscouragedNoneNameRule.swift @@ -4,7 +4,7 @@ import SwiftSyntax struct DiscouragedNoneNameRule: OptInRule { var configuration = SeverityConfiguration(.warning) - static var description = RuleDescription( + static let description = RuleDescription( identifier: "discouraged_none_name", name: "Discouraged None Name", description: "Enum cases and static members named `none` are discouraged as they can conflict with " + diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/LegacyRandomRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/LegacyRandomRule.swift index 261462c527..5b0686589b 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/LegacyRandomRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/LegacyRandomRule.swift @@ -4,7 +4,7 @@ import SwiftSyntax struct LegacyRandomRule: Rule { var configuration = SeverityConfiguration(.warning) - static var description = RuleDescription( + static let description = RuleDescription( identifier: "legacy_random", name: "Legacy Random", description: "Prefer using `type.random(in:)` over legacy functions", diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ShorthandOptionalBindingRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ShorthandOptionalBindingRule.swift index 203a993c67..ed50d0beba 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ShorthandOptionalBindingRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/ShorthandOptionalBindingRule.swift @@ -4,7 +4,7 @@ import SwiftSyntax struct ShorthandOptionalBindingRule: OptInRule { var configuration = SeverityConfiguration(.warning) - static var description = RuleDescription( + static let description = RuleDescription( identifier: "shorthand_optional_binding", name: "Shorthand Optional Binding", description: "Use shorthand syntax for optional binding", diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/DuplicatedKeyInDictionaryLiteralRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/DuplicatedKeyInDictionaryLiteralRule.swift index bd0480e0c7..48ff81fd12 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/DuplicatedKeyInDictionaryLiteralRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/DuplicatedKeyInDictionaryLiteralRule.swift @@ -4,7 +4,7 @@ import SwiftSyntax struct DuplicatedKeyInDictionaryLiteralRule: Rule { var configuration = SeverityConfiguration(.warning) - static var description = RuleDescription( + static let description = RuleDescription( identifier: "duplicated_key_in_dictionary_literal", name: "Duplicated Key in Dictionary Literal", description: "Dictionary literals with duplicated keys will crash at runtime", diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedCaptureListRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedCaptureListRule.swift index f42a6d9e24..17f0fb617d 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedCaptureListRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedCaptureListRule.swift @@ -12,7 +12,7 @@ private func warnDeprecatedOnce() { struct UnusedCaptureListRule: SwiftSyntaxRule, OptInRule { var configuration = SeverityConfiguration(.warning) - static var description = RuleDescription( + static let description = RuleDescription( identifier: "unused_capture_list", name: "Unused Capture List", description: "Unused reference in a capture list should be removed", diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedClosureParameterRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedClosureParameterRule.swift index 97a8145eec..26523c241e 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedClosureParameterRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedClosureParameterRule.swift @@ -1,4 +1,4 @@ -import SwiftSyntax +@preconcurrency import SwiftSyntax import SwiftSyntaxBuilder @SwiftSyntaxRule(explicitRewriter: true) diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/ValidIBInspectableRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/ValidIBInspectableRule.swift index 7cab2dbf39..7ded48d717 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/ValidIBInspectableRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/ValidIBInspectableRule.swift @@ -109,7 +109,7 @@ struct ValidIBInspectableRule: Rule { ] ) - fileprivate static var supportedTypes: Set = { + fileprivate static let supportedTypes: Set = { // "You can add the IBInspectable attribute to any property in a class declaration, // class extension, or category of type: boolean, integer or floating point number, string, // localized string, rectangle, point, size, color, range, and nil." diff --git a/Source/SwiftLintBuiltInRules/Rules/Performance/ReduceIntoRule.swift b/Source/SwiftLintBuiltInRules/Rules/Performance/ReduceIntoRule.swift index 0c8e8a54ec..e7269ea5a1 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Performance/ReduceIntoRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Performance/ReduceIntoRule.swift @@ -4,7 +4,7 @@ import SwiftSyntax struct ReduceIntoRule: OptInRule { var configuration = SeverityConfiguration(.warning) - static var description = RuleDescription( + static let description = RuleDescription( identifier: "reduce_into", name: "Reduce into", description: "Prefer `reduce(into:_:)` over `reduce(_:_:)` for copy-on-write types", diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/CollectionAlignmentRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/CollectionAlignmentRule.swift index 6d6e946cc6..3d34029eb2 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/CollectionAlignmentRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/CollectionAlignmentRule.swift @@ -4,7 +4,7 @@ import SwiftSyntax struct CollectionAlignmentRule: OptInRule { var configuration = CollectionAlignmentConfiguration() - static var description = RuleDescription( + static let description = RuleDescription( identifier: "collection_alignment", name: "Collection Element Alignment", description: "All elements in a collection literal should be vertically aligned", diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/DirectReturnRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/DirectReturnRule.swift index c486deb4ec..9a730fbfd4 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/DirectReturnRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/DirectReturnRule.swift @@ -4,7 +4,7 @@ import SwiftSyntax struct DirectReturnRule: OptInRule { var configuration = SeverityConfiguration(.warning) - static var description = RuleDescription( + static let description = RuleDescription( identifier: "direct_return", name: "Direct Return", description: "Directly return the expression instead of assigning it to a variable first", diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/NonOverridableClassDeclarationRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/NonOverridableClassDeclarationRule.swift index d841e7e652..fa407544c9 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/NonOverridableClassDeclarationRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/NonOverridableClassDeclarationRule.swift @@ -4,7 +4,7 @@ import SwiftSyntax struct NonOverridableClassDeclarationRule: SwiftSyntaxCorrectableRule, OptInRule { var configuration = NonOverridableClassDeclarationConfiguration() - static var description = RuleDescription( + static let description = RuleDescription( identifier: "non_overridable_class_declaration", name: "Class Declaration in Final Class", description: """ diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/PreferSelfInStaticReferencesRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/PreferSelfInStaticReferencesRule.swift index 2554a4a0d0..6484f83d3b 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/PreferSelfInStaticReferencesRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/PreferSelfInStaticReferencesRule.swift @@ -4,7 +4,7 @@ import SwiftSyntax struct PreferSelfInStaticReferencesRule: SwiftSyntaxCorrectableRule, OptInRule { var configuration = SeverityConfiguration(.warning) - static var description = RuleDescription( + static let description = RuleDescription( identifier: "prefer_self_in_static_references", name: "Prefer Self in Static References", description: "Use `Self` to refer to the surrounding type name", diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/RedundantSelfInClosureRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/RedundantSelfInClosureRule.swift index b4267fd133..6d37360be1 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/RedundantSelfInClosureRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/RedundantSelfInClosureRule.swift @@ -4,7 +4,7 @@ import SwiftSyntax struct RedundantSelfInClosureRule: SwiftSyntaxCorrectableRule, OptInRule { var configuration = SeverityConfiguration(.warning) - static var description = RuleDescription( + static let description = RuleDescription( identifier: "redundant_self_in_closure", name: "Redundant Self in Closure", description: "Explicit use of 'self' is not required", diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/SuperfluousElseRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/SuperfluousElseRule.swift index de7353aca1..ac090a818a 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/SuperfluousElseRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/SuperfluousElseRule.swift @@ -4,7 +4,7 @@ import SwiftSyntax struct SuperfluousElseRule: OptInRule { var configuration = SeverityConfiguration(.warning) - static var description = RuleDescription( + static let description = RuleDescription( identifier: "superfluous_else", name: "Superfluous Else", description: "Else branches should be avoided when the previous if-block exits the current scope", diff --git a/tools/add-preconcurrency-imports.sh b/tools/add-preconcurrency-imports.sh new file mode 100755 index 0000000000..acef5af261 --- /dev/null +++ b/tools/add-preconcurrency-imports.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +files=( +"Source/SwiftLintBuiltInRules/Rules/Idiomatic/PrivateOverFilePrivateRule.swift" +"Source/SwiftLintBuiltInRules/Rules/Idiomatic/ToggleBoolRule.swift" +"Source/SwiftLintBuiltInRules/Rules/Style/EmptyEnumArgumentsRule.swift" +"Source/SwiftLintBuiltInRules/Rules/Style/OptionalEnumCaseMatchingRule.swift" +"Source/SwiftLintBuiltInRules/Rules/Style/TrailingCommaRule.swift" +) + +for file in "${files[@]}"; do + sed -i '' -e 's/import SwiftSyntax$/@preconcurrency import SwiftSyntax/g' "$file" +done