Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: realm/SwiftLint
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.56.1
Choose a base ref
...
head repository: realm/SwiftLint
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.56.2
Choose a head ref
  • 14 commits
  • 27 files changed
  • 3 contributors

Commits on Aug 6, 2024

  1. Add new changelog section

    SimplyDanny committed Aug 6, 2024
    Copy the full SHA
    4a83c36 View commit details

Commits on Aug 8, 2024

  1. Update "Publish to BCR" config

    SimplyDanny committed Aug 8, 2024
    Copy the full SHA
    d192357 View commit details

Commits on Aug 18, 2024

  1. Fix spurious Bazel build errors (#5756)

    SimplyDanny authored Aug 18, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    cffb331 View commit details
  2. Add Swift builds running on macOS 13 (#5734)

    SimplyDanny authored Aug 18, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    fac9599 View commit details
  3. Update Bazel bzlmod dependencies for rules_swift 2.x support (#5736)

    Co-authored-by: Danny Mösch <danny.moesch@icloud.com>
    luispadron and SimplyDanny authored Aug 18, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a0a69a6 View commit details
  4. Bump rexml from 3.2.8 to 3.3.3 (#5757)

    Bumps the bundler group with 1 update in the / directory: [rexml](https://github.com/ruby/rexml).
    
    
    Updates `rexml` from 3.2.8 to 3.3.3
    - [Release notes](https://github.com/ruby/rexml/releases)
    - [Changelog](https://github.com/ruby/rexml/blob/master/NEWS.md)
    - [Commits](ruby/rexml@v3.2.8...v3.3.3)
    
    ---
    updated-dependencies:
    - dependency-name: rexml
      dependency-type: indirect
      dependency-group: bundler
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Aug 18, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    5454bc3 View commit details

Commits on Aug 19, 2024

  1. Ignore initializers with attributes in `unneeded_synthesized_initiali…

    …zer` rule (#5758)
    SimplyDanny authored Aug 19, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    21b1a03 View commit details
  2. Check all nested if expressions in contrasted_opening_brace rule (#…

    SimplyDanny authored Aug 19, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    314c91f View commit details
  3. Align left closure brace with associated parent function call (#5760)

    SimplyDanny authored Aug 19, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d5f7f9c View commit details
  4. Align left brace of additional trailing closures with right brace of …

    …previous trailing closure (#5761)
    SimplyDanny authored Aug 19, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    74f4778 View commit details

Commits on Aug 20, 2024

  1. Trigger on empty closure blocks in no_empty_block rule (#5763)

    SimplyDanny authored Aug 20, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    9d07110 View commit details

Commits on Aug 21, 2024

  1. Silence unneeded_override rule on methods and initializers with att…

    …ributes (#5764)
    SimplyDanny authored Aug 21, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    f3bdd27 View commit details
  2. Silence prefer_key_path rule on macro expansion expressions (#5765)

    SimplyDanny authored Aug 21, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c8a9065 View commit details

Commits on Aug 22, 2024

  1. Release 0.56.2

    SimplyDanny committed Aug 22, 2024
    Copy the full SHA
    a24488f View commit details
Showing with 257 additions and 79 deletions.
  1. +0 −3 .bcr/config.yml
  2. +5 −0 .bcr/metadata.template.json
  3. +1 −1 .bcr/presubmit.yml
  4. +0 −2 .buildkite/pipeline.yml
  5. +45 −0 CHANGELOG.md
  6. +4 −4 Gemfile.lock
  7. +7 −7 MODULE.bazel
  8. +2 −2 Package.resolved
  9. +3 −3 Package.swift
  10. +28 −1 Source/SwiftLintBuiltInRules/Rules/Idiomatic/NoEmptyBlockRule.swift
  11. +4 −4 Source/SwiftLintBuiltInRules/Rules/Idiomatic/PreferKeyPathRule.swift
  12. +2 −4 Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededSynthesizedInitializerRule.swift
  13. +6 −0 Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnneededSynthesizedInitializerRuleExamples.swift
  14. +1 −1 Source/SwiftLintBuiltInRules/Rules/Lint/ArrayInitRule.swift
  15. +2 −2 Source/SwiftLintBuiltInRules/Rules/Lint/UnneededOverrideRule.swift
  16. +7 −0 Source/SwiftLintBuiltInRules/Rules/Lint/UnneededOverrideRuleExamples.swift
  17. +22 −22 Source/SwiftLintBuiltInRules/Rules/Lint/UnusedDeclarationRule.swift
  18. +1 −0 Source/SwiftLintBuiltInRules/Rules/RuleConfigurations/NoEmptyBlockConfiguration.swift
  19. +32 −2 Source/SwiftLintBuiltInRules/Rules/Style/ContrastedOpeningBraceRule.swift
  20. +66 −0 Source/SwiftLintBuiltInRules/Rules/Style/ContrastedOpeningBraceRuleExamples.swift
  21. +4 −1 Source/SwiftLintCore/Extensions/QueuedPrint.swift
  22. +1 −1 Source/SwiftLintCore/Extensions/SwiftLintFile+Cache.swift
  23. +2 −2 Source/SwiftLintCore/Models/RuleConfigurationDescription.swift
  24. +1 −1 Source/SwiftLintCore/Models/Version.swift
  25. +1 −1 Tests/SwiftLintFrameworkTests/NoEmptyBlockConfigurationTests.swift
  26. +10 −1 azure-pipelines.yml
  27. +0 −14 tools/add-preconcurrency-imports.sh
3 changes: 0 additions & 3 deletions .bcr/config.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .bcr/metadata.template.json
Original file line number Diff line number Diff line change
@@ -5,6 +5,11 @@
"email": "jp@jpsim.com",
"github": "jpsim",
"name": "JP Simard"
},
{
"email": "danny.moesch@icloud.com",
"github": "SimplyDanny",
"name": "Danny Mösch"
}
],
"repository": [
2 changes: 1 addition & 1 deletion .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ tasks:
platform: ubuntu2004
environment:
CC: "clang"
SWIFT_VERSION: "5.8.1"
SWIFT_VERSION: "5.10"
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
PATH: "$PATH:$SWIFT_HOME/usr/bin"
shell_commands: *shell_commands
2 changes: 0 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@ steps:
- 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"
45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
## 0.56.2: Heat Pump Dryer

#### Breaking

* None.

#### Experimental

* None.

#### Enhancements

* None.

#### Bug Fixes

* Ignore initializers with attributes in `unneeded_synthesized_initializer` rule.
[SimplyDanny](https://github.com/SimplyDanny)
[#5153](https://github.com/realm/SwiftLint/issues/5153)

* Silence `prefer_key_path` rule on macro expansion expressions.
[SimplyDanny](https://github.com/SimplyDanny)
[#5744](https://github.com/realm/SwiftLint/issues/5744)

* Check `if` expressions nested arbitrarily deep in `contrasted_opening_brace` rule.
[SimplyDanny](https://github.com/SimplyDanny)
[#5752](https://github.com/realm/SwiftLint/issues/5752)

* Align left closure brace with associated parent function call in `contrasted_opening_brace` rule.
[SimplyDanny](https://github.com/SimplyDanny)
[#5752](https://github.com/realm/SwiftLint/issues/5752)

* Align left brace of additional trailing closures with right brace of previous trailing closure
in `contrasted_opening_brace` rule.
[SimplyDanny](https://github.com/SimplyDanny)
[#5752](https://github.com/realm/SwiftLint/issues/5752)

* Trigger on empty closure blocks in `no_empty_block` rule.
[SimplyDanny](https://github.com/SimplyDanny)
[#5762](https://github.com/realm/SwiftLint/issues/5762)

* Silence `unneeded_override` rule on methods and initializers with attributes.
[SimplyDanny](https://github.com/SimplyDanny)
[#5753](https://github.com/realm/SwiftLint/issues/5753)

## 0.56.1: Heat Pump Dryer

#### Breaking
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -122,8 +122,8 @@ GEM
public_suffix (4.0.7)
rchardet (1.8.0)
redcarpet (3.6.0)
rexml (3.2.8)
strscan (>= 3.0.9)
rexml (3.3.3)
strscan
rouge (4.3.0)
ruby-macho (2.5.1)
ruby2_keywords (0.0.5)
@@ -144,13 +144,13 @@ GEM
unicode-display_width (2.4.2)
xcinvoke (0.3.0)
liferaft (~> 0.0.6)
xcodeproj (1.22.0)
xcodeproj (1.25.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
rexml (~> 3.2.4)
rexml (>= 3.3.2, < 4.0)

PLATFORMS
arm64-darwin-21
14 changes: 7 additions & 7 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module(
name = "swiftlint",
version = "0.56.1",
version = "0.56.2",
compatibility_level = 1,
repo_name = "SwiftLint",
)

bazel_dep(name = "apple_support", version = "1.16.0", repo_name = "build_bazel_apple_support")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_apple", version = "3.6.0", repo_name = "build_bazel_rules_apple")
bazel_dep(name = "rules_swift", version = "1.18.0", repo_name = "build_bazel_rules_swift")
bazel_dep(name = "sourcekitten", version = "0.35.0", repo_name = "com_github_jpsim_sourcekitten")
bazel_dep(name = "swift-syntax", version = "600.0.0-prerelease-2024-07-24", repo_name = "SwiftSyntax")
bazel_dep(name = "swift_argument_parser", version = "1.3.1", repo_name = "sourcekitten_com_github_apple_swift_argument_parser")
bazel_dep(name = "rules_apple", version = "3.8.0", repo_name = "build_bazel_rules_apple")
bazel_dep(name = "rules_swift", version = "2.1.1", repo_name = "build_bazel_rules_swift")
bazel_dep(name = "sourcekitten", version = "0.36.0", repo_name = "com_github_jpsim_sourcekitten")
bazel_dep(name = "swift-syntax", version = "600.0.0-prerelease-2024-08-14", repo_name = "SwiftSyntax")
bazel_dep(name = "swift_argument_parser", version = "1.3.1.1", repo_name = "sourcekitten_com_github_apple_swift_argument_parser")
bazel_dep(name = "yams", version = "5.1.3", repo_name = "sourcekitten_com_github_jpsim_yams")

swiftlint_repos = use_extension("//bazel:repos.bzl", "swiftlint_repos_bzlmod")
@@ -31,4 +31,4 @@ use_repo(apple_cc_configure, "local_config_apple_cc")

# Dev Dependencies

bazel_dep(name = "rules_xcodeproj", version = "1.13.0", dev_dependency = True)
bazel_dep(name = "rules_xcodeproj", version = "2.6.1", dev_dependency = True)
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax.git",
"state" : {
"revision" : "82a453c2dfa335c7e778695762438dfe72b328d2",
"version" : "600.0.0-prerelease-2024-07-24"
"revision" : "515f79b522918f83483068d99c68daeb5116342d",
"version" : "600.0.0-prerelease-2024-08-14"
}
},
{
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.1"),
.package(url: "https://github.com/swiftlang/swift-syntax.git", exact: "600.0.0-prerelease-2024-07-24"),
.package(url: "https://github.com/swiftlang/swift-syntax.git", exact: "600.0.0-prerelease-2024-08-14"),
.package(url: "https://github.com/jpsim/SourceKitten.git", .upToNextMinor(from: "0.35.0")),
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.6"),
.package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", from: "0.9.0"),
@@ -172,8 +172,8 @@ let package = Package(
package.targets.append(
.binaryTarget(
name: "SwiftLintBinary",
url: "https://github.com/realm/SwiftLint/releases/download/0.56.1/SwiftLintBinary-macos.artifactbundle.zip",
checksum: "146ef723e83d301b9f1ef647dc924a55dae293887e633618e76f8cb526292f0c"
url: "https://github.com/realm/SwiftLint/releases/download/0.56.2/SwiftLintBinary-macos.artifactbundle.zip",
checksum: "197df93d7f5041d8cd46d6902a34ad57914efe1b5b50635995f3b9065f2c3ffd"
)
)
#endif
Original file line number Diff line number Diff line change
@@ -92,6 +92,18 @@ struct NoEmptyBlockRule: OptInRule {
while i < 10 {}
""", configuration: ["disabled_block_types": ["statement_blocks"]]),
Example("""
f { _ in /* comment */ }
f { _ in // comment
}
f { _ in
// comment
}
"""),
Example("""
f {}
{}()
""", configuration: ["disabled_block_types": ["closure_blocks"]]),
],
triggeringExamples: [
Example("""
@@ -130,6 +142,12 @@ struct NoEmptyBlockRule: OptInRule {
while i < 10 ↓{}
"""),
Example("""
f ↓{}
"""),
Example("""
Button ↓{} label: ↓{}
"""),
]
)
}
@@ -142,7 +160,14 @@ private extension NoEmptyBlockRule {
}
}

func validate(node: CodeBlockSyntax) {
override func visitPost(_ node: ClosureExprSyntax) {
if configuration.enabledBlockTypes.contains(.closureBlocks),
node.signature?.inKeyword.trailingTrivia.containsComments != true {
validate(node: node)
}
}

func validate(node: some BracedSyntax & WithStatementsSyntax) {
guard node.statements.isEmpty,
!node.leftBrace.trailingTrivia.containsComments,
!node.rightBrace.leadingTrivia.containsComments else {
@@ -162,6 +187,8 @@ private extension CodeBlockSyntax {
.initializerBodies
case .forStmt, .doStmt, .whileStmt, .repeatStmt, .ifExpr, .catchClause, .deferStmt:
.statementBlocks
case .closureExpr:
.closureBlocks
case .guardStmt:
// No need to handle this case since Empty Block of `guard` is compile error.
nil
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ struct PreferKeyPathRule: OptInRule {
Example("[1, 2, 3].reduce(1) { $0 + $1 }", configuration: extendedMode),
Example("f.map(1) { $0.a }"),
Example("f.filter({ $0.a }, x)"),
Example("#Predicate { $0.a }"),
],
triggeringExamples: [
Example("f.map ↓{ $0.a }"),
@@ -174,10 +175,9 @@ private extension ClosureExprSyntax {
}

func isInvalid(restrictToStandardFunctions: Bool) -> Bool {
if keyPathInParent == \FunctionCallExprSyntax.calledExpression {
return true
}
if parent?.is(MultipleTrailingClosureElementSyntax.self) == true {
guard keyPathInParent != \FunctionCallExprSyntax.calledExpression,
let parentKind = parent?.kind,
![.macroExpansionExpr, .multipleTrailingClosureElement].contains(parentKind) else {
return true
}
if let call = parent?.as(LabeledExprSyntax.self)?.parent?.parent?.as(FunctionCallExprSyntax.self) {
Original file line number Diff line number Diff line change
@@ -112,7 +112,7 @@ private extension StructDeclSyntax {
self.initializerParameters($0.parameterList, match: varDecls) &&
(($0.parameterList.isEmpty && hasNoSideEffects($0.body)) ||
initializerBody($0.body, matches: varDecls)) &&
initializerModifiers($0.modifiers, match: varDecls) && !$0.isInlinable
initializerModifiers($0.modifiers, match: varDecls) && $0.attributes.isEmpty
}
}

@@ -236,9 +236,7 @@ private extension InitializerDeclSyntax {
var hasThrowsOrRethrowsKeyword: Bool {
signature.effectSpecifiers?.throwsClause?.throwsSpecifier != nil
}
var isInlinable: Bool {
attributes.contains(attributeNamed: "inlinable")
}

var parameterList: FunctionParameterListSyntax {
signature.parameterClause.parameters
}
Original file line number Diff line number Diff line change
@@ -244,6 +244,12 @@ enum UnneededSynthesizedInitializerRuleExamples {
init() {}
}
""", excludeFromDocumentation: true),
Example("""
struct Foo {
@available(*, unavailable)
init() {}
}
"""),
]

static let triggering = [
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftSyntax

@SwiftSyntaxRule
struct ArrayInitRule: OptInRule {
struct ArrayInitRule: OptInRule, @unchecked Sendable {
var configuration = SeverityConfiguration<Self>(.warning)

static let description = RuleDescription(
Original file line number Diff line number Diff line change
@@ -89,8 +89,8 @@ private extension OverridableDecl {
return false
}

// Assume having @available changes behavior.
if attributes.contains(attributeNamed: "available") {
// Assume attributes change behavior.
guard attributes.isEmpty else {
return false
}

Original file line number Diff line number Diff line change
@@ -17,6 +17,13 @@ struct UnneededOverrideRuleExamples {
}
"""),
Example("""
class Foo {
@objc override func bar() {
super.bar()
}
}
"""),
Example("""
class Foo {
override func bar() {
super.bar()
44 changes: 22 additions & 22 deletions Source/SwiftLintBuiltInRules/Rules/Lint/UnusedDeclarationRule.swift
Original file line number Diff line number Diff line change
@@ -121,6 +121,20 @@ private extension SwiftLintFile {
editorOpen: SourceKittenDictionary,
compilerArguments: [String],
configuration: UnusedDeclarationConfiguration) -> UnusedDeclarationRule.DeclaredUSR? {
// Skip initializers, deinit, enum cases and subscripts since we can't reliably detect if they're used.
let declarationKindsToSkip: Set<SwiftDeclarationKind> = [
.enumelement,
.extensionProtocol,
.extension,
.extensionEnum,
.extensionClass,
.extensionStruct,
.functionConstructor,
.functionDestructor,
.functionSubscript,
.genericTypeParam,
]

guard let stringKind = indexEntity.kind,
stringKind.starts(with: "source.lang.swift.decl."),
!stringKind.contains(".accessor."),
@@ -196,6 +210,14 @@ private extension SwiftLintFile {
}

private func shouldIgnoreEntity(_ indexEntity: SourceKittenDictionary, relatedUSRsToSkip: Set<String>) -> Bool {
let declarationAttributesToSkip: Set<SwiftDeclarationAttributeKind> = [
.ibaction,
.main,
.nsApplicationMain,
.override,
.uiApplicationMain,
]

if indexEntity.shouldSkipIndexEntityToWorkAroundSR11985() ||
indexEntity.shouldSkipRelated(relatedUSRsToSkip: relatedUSRsToSkip) ||
indexEntity.enclosedSwiftAttributes.contains(where: declarationAttributesToSkip.contains) ||
@@ -321,25 +343,3 @@ private extension SourceKittenDictionary {
return nil
}
}

// Skip initializers, deinit, enum cases and subscripts since we can't reliably detect if they're used.
private let declarationKindsToSkip: Set<SwiftDeclarationKind> = [
.enumelement,
.extensionProtocol,
.extension,
.extensionEnum,
.extensionClass,
.extensionStruct,
.functionConstructor,
.functionDestructor,
.functionSubscript,
.genericTypeParam,
]

private let declarationAttributesToSkip: Set<SwiftDeclarationAttributeKind> = [
.ibaction,
.main,
.nsApplicationMain,
.override,
.uiApplicationMain,
]
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ struct NoEmptyBlockConfiguration: SeverityBasedRuleConfiguration {
case functionBodies = "function_bodies"
case initializerBodies = "initializer_bodies"
case statementBlocks = "statement_blocks"
case closureBlocks = "closure_blocks"

static let all = Set(allCases)
}
Loading