Skip to content

Releases: realm/SwiftLint

0.54.0: Macro-Economic Forces

10 Nov 20:54
f17a4f9
Compare
Choose a tag to compare

Breaking

Experimental

  • None.

Enhancements

  • Add only configuration option to todo rule which allows to specify
    whether the rule shall trigger on TODOs, FIXMEs or both.
    gibachan
    #5233

  • Make unneeded_break_in_switch auto correctable.
    KS1019

  • Speed up closure_parameter_position rule when there are no violations.
    Marcelo Fabri

  • Rewrite cyclomatic_complexity rule using SwiftSyntax.
    Marcelo Fabri

  • Rewrite redundant_void_return rule using SwiftSyntax.
    Also include redundant void return clauses for closures in addition to
    functions. This can be disabled by configuring the rule with
    include_closures: false.
    Marcelo Fabri
    JP Simard

  • Rewrite discouraged_optional_collection rule using SwiftSyntax, catching
    more violations.
    JP Simard

  • Rewrite duplicate_imports rule using SwiftSyntax.
    JP Simard

  • Handle viewIsAppearing in the type_contents_order rule.
    u-abyss
    #5259

  • Rewrite vertical_parameter_alignment_on_call rule using SwiftSyntax, fixing
    some false positives.
    Marcelo Fabri
    #3581

  • Rewrite no_grouping_extension rule using SwiftSyntax.
    Marcelo Fabri

Bug Fixes

  • Fix false positive in implicit_getter rule when using unknown accessors.
    kabiroberai
    #5300

  • Fix correction of explicit_init rule by keeping significant trivia.
    BB9z
    #5289

  • Fix invalid corrections for opaque and existential optionals in
    syntactic_sugar rule.
    SimplyDanny
    #5277

  • Fix false positive in unused_import rule that triggered on
    @_exported imports which could break downstream modules if removed.
    jszumski
    #5242

  • Fix false positive in unused_import rule when using a constructor
    defined in a transitive module.
    jszumski
    #5246


Using Bazel

With bzlmod:

// Pending BCR update
bazel_dep(name = "swiftlint", version = "0.54.0", repo_name = "SwiftLint")

Without bzlmod, put this in your WORKSPACE:

WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "build_bazel_rules_apple",
    sha256 = "9e26307516c4d5f2ad4aee90ac01eb8cd31f9b8d6ea93619fc64b3cbc81b0944",
    url = "https://github.com/bazelbuild/rules_apple/releases/download/2.2.0/rules_apple.2.2.0.tar.gz",
)

load(
    "@build_bazel_rules_apple//apple:repositories.bzl",
    "apple_rules_dependencies",
)

apple_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:extras.bzl",
    "swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

http_archive(
    name = "SwiftLint",
    sha256 = "3a97a7d225c6a39716c48aea88eee38df052f678bf6dad73f62c746a3d9cc10c",
    url = "https://github.com/realm/SwiftLint/releases/download/0.54.0/bazel.tar.gz",
)

load("@SwiftLint//bazel:repos.bzl", "swiftlint_repos")

swiftlint_repos()

load("@SwiftLint//bazel:deps.bzl", "swiftlint_deps")

swiftlint_deps()

Then you can run SwiftLint in the current directory with this command:

bazel run @SwiftLint//:swiftlint -- --help

0.53.0: Laundry List

26 Sep 15:09
6d2e582
Compare
Choose a tag to compare

Breaking

  • Hide all Reporters from SwiftLint's' public interface.
    SimplyDanny

  • The options inlcuded, name and message are from now on ignored in the
    configuration for the private_unit_test rule. The option regex is still
    supported but is deprecated. It's recommended to use the list
    test_parent_classes instead which accepts names of parent test classes.
    SimplyDanny

  • Remove support for disable and enable commands in multiline comments.
    Martin Redington
    #4798

Experimental

  • None.

Enhancements

  • Show specific violation message for the attributes rule when the option
    always_on_line_above or attributes_with_arguments_always_on_line_above
    is involved.
    chrisngabp
    5103

  • Rewrite control_statement rule using SwiftSyntax.
    SimplyDanny

  • Add new non_overridable_class_declaration rule that triggers on class
    function and variable declarations in final classes that are not final
    themselves or private.
    SimplyDanny

  • The Homebrew formula for SwiftLint now also installs completion scripts for
    Bash, Zsh and fish.
    SimplyDanny

  • Add new private_swiftui_state_property opt-in rule to encourage setting
    SwiftUI @State and @StateObject properties to private.
    mt00chikin
    #3173

  • The implicit_return rule now supports the kinds subscript and
    initializer in the included configuration list.
    SimplyDanny

  • Add unneeded_override rule to remove function overrides that only
    call super.
    keith
    5139

  • Show a rule's active YAML configuration in output of
    swiftlint rules <rule>.
    SimplyDanny

  • Add invokeTest() to overridden_super_call defaults.
    DylanBettermannDD

  • Add --config-only option to rules command allowing to print only the YAML
    configuration of a single or all rules.
    SimplyDanny

  • Add --default-config option to rules command allowing to use default
    values for configurations being printed for a single rule or all rules.
    SimplyDanny

  • Add include_bare_init option to the explicit_init rule. include_bare_init
    encourages using named constructors over .init() and type inference.
    Martin Redington
    #5203

  • Improved the reported location and reasons provided for issues
    detected by the invalid_seiftlint_command rule.
    Martin Redington
    #5204

  • 100 is no longer considered to be a magic number by the no_magic_numbers
    rule.
    Martin Redington
    #5215

  • Adds a strict configuration file setting, equivalent to the --strict
    command line option.
    Martin Redington
    #5226

  • Extend implicitly_unwrapped_optional rule with the new mode
    weak_except_iboutlets that only checks weak variables.
    Ricky Tan

Bug Fixes

  • Respect grapheme clusters in counting the number of characters in the collection_alignment rule.
    kishikawakatsumi
    #4837

  • Fix false positive in control_statement rule that triggered on conditions
    with trailing closures where parentheses are recommended by the compiler.
    SimplyDanny
    #5135

  • Fix runtime error when an excluded directory does not exist.
    SimplyDanny
    #5078

  • Support switch expressions used in expression contexts in
    switch_case_alignment rule.
    SimplyDanny
    #5191
    #5227
    #5080

  • Fix bug in prefer_self_in_static_references rule that triggered on
    initializers of computed properties in classes when the property had an
    accessor block.
    SimplyDanny
    #5118

  • Document exclude_ranges option for number_separator rule.
    SimplyDanny

  • Rewrite implicit_return rule with SwiftSyntax fixing a few false positives
    and false negatives in the process.
    SimplyDanny
    #5161

  • Make sure severity is configurable for type_contents_order rule.
    SimplyDanny

  • Bazel: Mark rules_xcodeproj as a development dependency.
    Thi Doãn
    JP Simard
    #4737

  • Fix false negatives for the unneeded_synthesized_initializer rule
    for nested structs in classes.
    Martin Redington
    #5120

  • Fix some unexpected rule enablement interactions between parent and
    child configurations.
    Martin Redington
    #4876

  • The no_magic_numbers rule will not trigger for violations in an
    extension, if the extended class inherits from one of the specified
    test_parent_classes, as long as the class declaration and the
    extension are in the same source file.
    Martin Redington
    #5137

  • Fix false positive in the ns_number_init_as_function_reference rule
    when calling NSNumber.init(value:) directly.
    Marcelo Fabri
    #5172

  • The no_magic_numbers rule will not trigger for bitwise shift
    operations.
    Martin Redington
    #5171

  • The accessibility_label_for_image rule will no longer ignore the
    Image(systemName:) constructor, as many system images do not
    have good accessibility labels.
    Martin Redington
    #5165

  • Fix false positives for superfluous_disable_command rule.
    Martin Redington
    #4798

  • Fix false positive in the test_case_accessibility rule.
    gibachan
    #5211


Using Bazel

With bzlmod:

// Pending BCR update
bazel_dep(name = "swiftlint", version = "0.53.0", repo_name = "SwiftLint")

Without bzlmod, put this in your WORKSPACE:

WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "build_bazel_rules_apple",
    sha256 = "9e26307516c4d5f2ad4aee90ac01eb8cd31f9b8d6ea93619fc64b3cbc81b0944",
    url = "https://github.com/bazelbuild/rules_apple/releases/download/2.2.0/rules_apple.2.2.0.tar.gz",
)

load(
    "@build_bazel_rules_apple//apple:repositories.bzl",
    "apple_rules_dependencies",
)

apple_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:extras.bzl",
    "swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

http_archive(
    name = "SwiftLint",
    sha256 = "75839dc9e8a492a86bb585a3cda3d73b58997d7a14d02f1dba94171766bb8599",
    url = "https://github.com/realm/SwiftLint/releases/download/0.53.0/bazel.tar.gz",
)

load("@SwiftLint//bazel:repos.bzl", "swiftlint_repos")

swiftlint_repos()

load("@SwiftLint//bazel:deps.bzl", "swiftlint_deps")

swiftlint_deps()

Then you can run SwiftLint in the current directory with this command:

bazel run @SwiftLint//:swiftlint -- --help

0.52.4: Lid Switch

06 Jul 18:43
9eaecbe
Compare
Choose a tag to compare

Breaking

  • None.

Experimental

  • None.

Enhancements

  • Handle static spec methods in quick_discouraged_call rule. The method
    type changed from an instance method to a class method in Quick 7.
    SimplyDanny
    #5072

  • Prettify the rule configuration presentation on the command line as well as
    on the website.
    SimplyDanny

Bug Fixes

  • Fix false positives for the unneeded_synthesized_initializer rule, when
    no argument initializers had side-effects.
    Martin Redington
    #5075

  • Ignore switch expressions assigned to variables in switch_case_alignment
    rule.
    SimplyDanny
    #5080

  • Fix auto-correction for the direct_return rule, when statements have
    trailing comments.
    Martin Redington
    #5081

  • Fix false positives for the private_subject rule when creating subjects
    inside initializers.
    kasrababaei

  • Fix false positive for prefer_self_in_static_references when a class
    inherits from another class with generic types.
    kasrababaei


Using Bazel

With bzlmod:

// Pending BCR update: https://github.com/bazelbuild/bazel-central-registry/pull/750
bazel_dep(name = "swiftlint", version = "0.52.4", repo_name = "SwiftLint")

Without bzlmod, put this in your WORKSPACE:

WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "build_bazel_rules_apple",
    sha256 = "9e26307516c4d5f2ad4aee90ac01eb8cd31f9b8d6ea93619fc64b3cbc81b0944",
    url = "https://github.com/bazelbuild/rules_apple/releases/download/2.2.0/rules_apple.2.2.0.tar.gz",
)

load(
    "@build_bazel_rules_apple//apple:repositories.bzl",
    "apple_rules_dependencies",
)

apple_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:extras.bzl",
    "swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

http_archive(
    name = "SwiftLint",
    sha256 = "c6ea58b9c72082cdc1ada4a2d48273ecc355896ed72204cedcc586b6ccb8aca6",
    url = "https://github.com/realm/SwiftLint/releases/download/0.52.4/bazel.tar.gz",
)

load("@SwiftLint//bazel:repos.bzl", "swiftlint_repos")

swiftlint_repos()

load("@SwiftLint//bazel:deps.bzl", "swiftlint_deps")

swiftlint_deps()

Then you can run SwiftLint in the current directory with this command:

bazel run @SwiftLint//:swiftlint -- --help

0.52.3: Duplicate Hampers

22 Jun 15:00
117405c
Compare
Choose a tag to compare

Breaking

  • None.

Experimental

  • None.

Enhancements

  • Make severity for unallowed symbols configurable. The option name is
    unallowed_symbols_severity. It accepts the two values warning and error
    (default) as usual.
    SimplyDanny

  • Mention a rule's identifier in the console message that is printed when the
    rule's associated configuration entry contains invalid values.
    SimplyDanny

  • Silence xct_specific_matcher rule on "one argument asserts" if there are
    potential types or tuples involved in the comparison as types and tuples do
    not conform to Equatable.
    SimplyDanny
    #4990

  • Add grouping option to the sorted_imports rule allowing
    to sort groups of imports defined by their preceding attributes
    (e.g. @testable, @_exported, ...).
    hiltonc

  • Add new --silence-deprecation-warnings flag that silences deprecation
    warnings that would otherwise be printed to the console.
    SimplyDanny
    #4989

  • Do not trigger redundant_self_in_closure rule when another idenfier x in
    scope shadows the field accessed by self.x to avoid semantical changes.
    SimplyDanny
    #5010

  • Rewrite todo rule with SwiftSyntax.
    woxtu

  • Adds an unneeded_synthesized_initializer rule, based on
    swift-format's UseSynthesizedInitializer rule, which warns
    when a defined default or memberwise initializer would have been
    automatically synthesized.
    Martin Redington

Bug Fixes

  • The option validates_start_with_lowercase can now be disabled by setting it
    to off.
    SimplyDanny
    #5036

  • Do not trigger prefer_self_in_static_references rule on typealias
    declarations in classes.
    SimplyDanny
    #5009

  • Do not trigger prefer_self_in_static_references rule on collection types in
    classes, but on initializers like [C]() in all types.
    SimplyDanny
    #5042

  • Fix false positives on redundant_objc_attribute rule for enums
    and private members.
    Martin Redington
    #4633

  • Fix autocorrect for CGIntersectionRect in legacy_cggeometry_functions
    rule.
    Haoocen
    #5023

  • Fix false positives on sorted_first_last rule when first/last have
    a predicate.
    woxtu
    #3023

  • Work around dyld warning about duplicate SwiftSyntax classes with Xcode 15
    betas.
    keith
    JP Simard
    #4782


Using Bazel

With bzlmod:

bazel_dep(name = "swiftlint", version = "0.52.3", repo_name = "SwiftLint")

Without bzlmod, put this in your WORKSPACE:

WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "build_bazel_rules_apple",
    sha256 = "9e26307516c4d5f2ad4aee90ac01eb8cd31f9b8d6ea93619fc64b3cbc81b0944",
    url = "https://github.com/bazelbuild/rules_apple/releases/download/2.2.0/rules_apple.2.2.0.tar.gz",
)

load(
    "@build_bazel_rules_apple//apple:repositories.bzl",
    "apple_rules_dependencies",
)

apple_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:extras.bzl",
    "swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

http_archive(
    name = "SwiftLint",
    sha256 = "20c09504184d2496a4b40bc6f77a03d443fe4ba79b4bbbab61382bc5241d24aa",
    url = "https://github.com/realm/SwiftLint/releases/download/0.52.3/bazel.tar.gz",
)

load("@SwiftLint//bazel:repos.bzl", "swiftlint_repos")

swiftlint_repos()

load("@SwiftLint//bazel:deps.bzl", "swiftlint_deps")

swiftlint_deps()

Then you can run SwiftLint in the current directory with this command:

bazel run @SwiftLint//:swiftlint -- --help

0.52.2: Crisper Clearer Pleats

12 May 15:02
34f5ffa
Compare
Choose a tag to compare

Breaking

  • None.

Experimental

  • None.

Enhancements

  • Exclude simple assignments of the form self.x = x from being reported by
    the redundant_self_in_closure rule.
    SimplyDanny
    #4988

Bug Fixes

  • Make unhandled_throwing_task opt-in instead of enabled by default. The rule
    is still prone to false positives at this point, so this makes enabling the
    rule a conscious decision by end-users.
    JP Simard
    #4987

  • Fix unhandled_throwing_task false positives when the Task is returned or
    where the throwing code is handled in a Result initializer.
    JP Simard
    #4987


Using Bazel

With bzlmod:

bazel_dep(name = "swiftlint", version = "0.52.2", repo_name = "SwiftLint")

Without bzlmod, put this in your WORKSPACE:

WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "build_bazel_rules_apple",
    sha256 = "9e26307516c4d5f2ad4aee90ac01eb8cd31f9b8d6ea93619fc64b3cbc81b0944",
    url = "https://github.com/bazelbuild/rules_apple/releases/download/2.2.0/rules_apple.2.2.0.tar.gz",
)

load(
    "@build_bazel_rules_apple//apple:repositories.bzl",
    "apple_rules_dependencies",
)

apple_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:extras.bzl",
    "swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

http_archive(
    name = "SwiftLint",
    sha256 = "2b95a592304bc377aa29d92683618376975f93553be62f132de7424819f6fc4a",
    url = "https://github.com/realm/SwiftLint/releases/download/0.52.2/bazel.tar.gz",
)

load("@SwiftLint//bazel:repos.bzl", "swiftlint_repos")

swiftlint_repos()

load("@SwiftLint//bazel:deps.bzl", "swiftlint_deps")

swiftlint_deps()

Then you can run SwiftLint in the current directory with this command:

bazel run @SwiftLint//:swiftlint -- --help

0.52.1: Crisp Clear Pleats

11 May 15:15
5616d85
Compare
Choose a tag to compare

0.52.1: Crisp Clear Pleats

Bug Fixes

  • Let the validates_start_with_lowercase option in name configurations
    expect a severity (warning or error). Not setting it disables the check.
    Boolean values are now deprecated. A true value enables the check as an
    error for the time being to keep the previous behavior.
    SimplyDanny
    #2180

  • Fixed a false positive in unhandled_throwing_task.
    kylebshr
    #4984

  • Fix Bazel release tarball for compiling on macOS.
    JP Simard
    #4985

0.52.0: Crisp Clear Pleats

Breaking

  • The attributes rule now expects attributes with arguments to be placed
    on their own line above the declaration they are supposed to influence.
    This applies to attributes with any kinds of arguments including single
    key path arguments which were previously handled in a different way. This
    behavior can be turned off by setting attributes_with_arguments_always_on_line_above
    to `false.
    SimplyDanny
    #4843

  • The internal module structure for SwiftLint has changed to split the
    monolithic SwiftLintFramework into new SwiftLintCore for core linter
    infrastructure, SwiftLintBuiltInRules for built-in rules and
    SwiftLintExtraRules to add your own native rules to SwiftLint.
    JP Simard

Experimental

  • None.

Enhancements

  • Add new superfluous_else rule that triggers on if-statements when an
    attached else-block can be removed, because all branches of the previous
    if-block(s) would certainly exit the current scope already.
    SimplyDanny

  • Add sorted_enum_cases rule which warns when enum cases are not sorted.
    kimdv

  • Add new redundant_self_in_closure rule that triggers in closures on
    explicitly used self when it's actually not needed due to:

    • Strongly captured self ({ [self] in ... })
    • Closure used in a struct declaration (self can always be omitted)
    • Anonymous closures that are directly called ({ ... }()) as they are
      definitly not escaping
    • Weakly captured self with explicit unwrapping

    SimplyDanny
    #59

  • Extend xct_specific_matcher rule to check for boolean asserts on (un)equal
    comparisons. The rule can be configured with the matchers that should trigger
    rule violations. By default, all matchers trigger, but that can be limited to
    just one-argument-asserts or two-argument-asserts.
    SimplyDanny
    JP Simard
    #3726

  • Trigger prefer_self_in_static_references rule on more type references.
    SimplyDanny

  • Adds a new reporters command, to improve discoverability of reporters.
    Martin Redington
    #4819

  • Adds test_parent_classes option to the no_magic_numbers rule.
    Violations within test classes will now be ignored by default.
    Martin Redington
    #4896

  • Stop enforcing calls to super from the override functions setUp(),
    tearDown(), setUpWithError(), and tearDownWithError() in XCTestCase
    subclasses.
    AndrewDMontgomery
    #4875

  • Prepend warning: to error messages so that they show in Xcode.
    whiteio
    #4923

  • The attributes rule received a new boolean option
    attributes_with_arguments_always_on_line_above which is true by default.
    Setting it to false ensures that attributes with arguments like
    @Persisted(primaryKey: true) don't violate the rule if they are on the same
    line with the variable declaration.
    SimplyDanny
    #4843

  • Add new unhandled_throwing_task rule that triggers when a Task with an
    implicit error type has unhandled trys or errors thrown inside its body.
    This results in errors being silently discarded, which may be unexpected.
    See this forum thread for more details: https://forums.swift.org/t/56066
    kylebshr

Bug Fixes

  • Fix lower_acl_than_parent rule rewriter by preserving leading whitespace.
    SimplyDanny
    #4860

  • Ignore block comments in let_var_whitespace rule.
    SimplyDanny
    #4871

  • Fix false positives in indentation_width rule.
    Sven Münnich

  • Do not trigger reduce_boolean on reduce methods with a first named
    argument that is different from into.
    SimplyDanny
    #4894

  • Work around dyld warning about duplicate SwiftSyntax classes.
    keith
    #4782

  • Improve lint times of SwiftLintPlugin by moving the
    excludedPaths(fileManager:) operation out of the linting iterations.
    andyyhope
    #4844


Using Bazel

With bzlmod:

bazel_dep(name = "swiftlint", version = "0.52.1", repo_name = "SwiftLint")

Without bzlmod, put this in your WORKSPACE:

WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "build_bazel_rules_apple",
    sha256 = "9e26307516c4d5f2ad4aee90ac01eb8cd31f9b8d6ea93619fc64b3cbc81b0944",
    url = "https://github.com/bazelbuild/rules_apple/releases/download/2.2.0/rules_apple.2.2.0.tar.gz",
)

load(
    "@build_bazel_rules_apple//apple:repositories.bzl",
    "apple_rules_dependencies",
)

apple_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:extras.bzl",
    "swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

http_archive(
    name = "SwiftLint",
    sha256 = "22973f004310a1e5611ae6d08077e907be4883929d10c049cc0b9846463b3d9a",
    url = "https://github.com/realm/SwiftLint/releases/download/0.52.1/bazel.tar.gz",
)

load("@SwiftLint//bazel:repos.bzl", "swiftlint_repos")

swiftlint_repos()

load("@SwiftLint//bazel:deps.bzl", "swiftlint_deps")

swiftlint_deps()

Then you can run SwiftLint in the current directory with this command:

bazel run @SwiftLint//:swiftlint -- --help

0.52.0: Crisp Clear Pleats

10 May 19:16
97259e2
Compare
Choose a tag to compare

Breaking

  • The attributes rule now expects attributes with arguments to be placed
    on their own line above the declaration they are supposed to influence.
    This applies to attributes with any kinds of arguments including single
    key path arguments which were previously handled in a different way. This
    behavior can be turned off by setting attributes_with_arguments_always_on_line_above
    to `false.
    SimplyDanny
    #4843

  • The internal module structure for SwiftLint has changed to split the
    monolithic SwiftLintFramework into new SwiftLintCore for core linter
    infrastructure, SwiftLintBuiltInRules for built-in rules and
    SwiftLintExtraRules to add your own native rules to SwiftLint.
    JP Simard

Experimental

  • None.

Enhancements

  • Add new superfluous_else rule that triggers on if-statements when an
    attached else-block can be removed, because all branches of the previous
    if-block(s) would certainly exit the current scope already.
    SimplyDanny

  • Add sorted_enum_cases rule which warns when enum cases are not sorted.
    kimdv

  • Add new redundant_self_in_closure rule that triggers in closures on
    explicitly used self when it's actually not needed due to:

    • Strongly captured self ({ [self] in ... })
    • Closure used in a struct declaration (self can always be omitted)
    • Anonymous closures that are directly called ({ ... }()) as they are
      definitly not escaping
    • Weakly captured self with explicit unwrapping

    SimplyDanny
    #59

  • Extend xct_specific_matcher rule to check for boolean asserts on (un)equal
    comparisons. The rule can be configured with the matchers that should trigger
    rule violations. By default, all matchers trigger, but that can be limited to
    just one-argument-asserts or two-argument-asserts.
    SimplyDanny
    JP Simard
    #3726

  • Trigger prefer_self_in_static_references rule on more type references.
    SimplyDanny

  • Adds a new reporters command, to improve discoverability of reporters.
    Martin Redington
    #4819

  • Adds test_parent_classes option to the no_magic_numbers rule.
    Violations within test classes will now be ignored by default.
    Martin Redington
    #4896

  • Stop enforcing calls to super from the override functions setUp(),
    tearDown(), setUpWithError(), and tearDownWithError() in XCTestCase
    subclasses.
    AndrewDMontgomery
    #4875

  • Prepend warning: to error messages so that they show in Xcode.
    whiteio
    #4923

  • The attributes rule received a new boolean option
    attributes_with_arguments_always_on_line_above which is true by default.
    Setting it to false ensures that attributes with arguments like
    @Persisted(primaryKey: true) don't violate the rule if they are on the same
    line with the variable declaration.
    SimplyDanny
    #4843

  • Add new unhandled_throwing_task rule that triggers when a Task with an
    implicit error type has unhandled trys or errors thrown inside its body.
    This results in errors being silently discarded, which may be unexpected.
    See this forum thread for more details: https://forums.swift.org/t/56066
    kylebshr

Bug Fixes

  • Fix lower_acl_than_parent rule rewriter by preserving leading whitespace.
    SimplyDanny
    #4860

  • Ignore block comments in let_var_whitespace rule.
    SimplyDanny
    #4871

  • Fix false positives in indentation_width rule.
    Sven Münnich

  • Do not trigger reduce_boolean on reduce methods with a first named
    argument that is different from into.
    SimplyDanny
    #4894

  • Work around dyld warning about duplicate SwiftSyntax classes.
    keith
    #4782

  • Improve lint times of SwiftLintPlugin by moving the
    excludedPaths(fileManager:) operation out of the linting iterations.
    andyyhope
    #4844


Using Bazel

With bzlmod:

bazel_dep(name = "swiftlint", version = "0.52.0", repo_name = "SwiftLint")

Without bzlmod, put this in your WORKSPACE:

WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "build_bazel_rules_apple",
    sha256 = "9e26307516c4d5f2ad4aee90ac01eb8cd31f9b8d6ea93619fc64b3cbc81b0944",
    url = "https://github.com/bazelbuild/rules_apple/releases/download/2.2.0/rules_apple.2.2.0.tar.gz",
)

load(
    "@build_bazel_rules_apple//apple:repositories.bzl",
    "apple_rules_dependencies",
)

apple_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:extras.bzl",
    "swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

http_archive(
    name = "SwiftLint",
    sha256 = "c5021aff12fd0e0cbf17c232d8f0e28a27ccf886d5a871681cb78f7b30a20faa",
    url = "https://github.com/realm/SwiftLint/releases/download/0.52.0/bazel.tar.gz",
)

load("@SwiftLint//bazel:repos.bzl", "swiftlint_repos")

swiftlint_repos()

load("@SwiftLint//bazel:deps.bzl", "swiftlint_deps")

swiftlint_deps()

Then you can run SwiftLint in the current directory with this command:

bazel run @SwiftLint//:swiftlint -- --help

0.51.0: bzllint

27 Mar 15:45
eb85125
Compare
Choose a tag to compare

0.51.0: bzllint

Breaking

  • Deprecate the unused_capture_list rule in favor of the Swift compiler
    warning. At the same time, make it an opt-in rule.
    Cyberbeni
    #4656

  • Deprecate the inert_defer rule in favor of the Swift compiler warning.
    At the same time, make it an opt-in rule.
    SimplyDanny
    #4615

Experimental

  • None.

Enhancements

  • Add duplicate_conditions rule which warns when a condition is duplicated
    in separate branches of the same branching statement (if-else, or switch).
    1in1
    #4666

  • Add local links to rule descriptions to every rule listed
    in Rule Directory.md.
    kattouf

  • Make forceExclude work with directly specified files.
    jimmya
    #4609

  • Adds all pseudo-rule for opt_in_rules - enables all opt in rules
    that are not listed in disabled_rules
    Martin Redington
    #4540

  • Separate analyzer rules as an independent section in the rule directory of
    the reference.
    Ethan Wong
    #4664

  • Add rule identifier to output of Emoji reporter.
    SimplyDanny
    #4707

  • Interpret strings in excluded option of identifier_name,
    type_name and generic_type_name rules as regex.
    Moly
    #4655

  • Add new direct_return rule that triggers on return statements returning
    variables that have been declared in the statement before only.
    SimplyDanny

  • Add period_spacing opt-in rule that checks periods are not followed
    by 2 or more spaces in comments.
    Julioacarrettoni
    #4624

  • Allow to pass a rule identifier to the swiftlint docs command to open its
    specific documentation website, e.g. swiftlint docs for_where.
    SimplyDanny
    #4707

  • Allow new Quick APIs aroundEach and justBeforeEach for
    quick_discouraged_call.
    David Steinacher
    #4626

  • Add relative-path reporter to generate reports with relative file paths.
    Roya1v
    #4660

  • Let number_separator rule trigger on misplaced separators, e.g. 10_00.
    SimplyDanny
    #4637

  • Rewrite multiline_arguments rule using SwiftSyntax, ignoring trailing
    closures.
    Marcelo Fabri
    #3399
    #3605

  • Speed up linting by up to 6% updating to use a newer version of
    SwiftSyntax.
    JP Simard

  • Catch more valid legacy_multiple violations.
    JP Simard

  • Catch more valid no_magic_numbers violations.
    JP Simard

  • Add blanket_disable_command rule that checks whether
    rules are re-enabled after being disabled.
    Martin Redington
    #4731

  • Add invalid_swiftlint_command rule that validates
    // swiftlint:enable and disable commands.
    Martin Redington
    #4546

  • Improve identifier_name documentation.
    Martin Redington
    #4767

  • Adds include_multiline_strings option to indentation_width rule.
    Martin Redington
    #4248

  • Adds a new summary reporter, that displays the number of violations
    of each rule in a text table.
    Martin Redington

Bug Fixes

  • Report violations in all <scope>_length rules when the error threshold is
    smaller than the warning threshold.
    SimplyDanny
    #4645

  • Consider custom attributes in attributes rule.
    SimplyDanny
    #4599

  • Fix whitespaces issue in auto-fix of redundant_optional_initialization
    rule when multiple variable declaration are involved.
    SimplyDanny
    #4794

  • Stop triggering strict_fileprivate rule on symbols implementing a protocol
    in the same file.
    SimplyDanny
    #4692

  • Fix false positives on private_subject rule when using
    subjects inside functions.
    Marcelo Fabri
    #4643

  • Fix for compiler directives masking subsequent opening_brace
    violations.
    Martin Redington
    #3712

  • Rewrite explicit_type_interface rule with SwiftSyntax fixing a
    false-positive in if-case-let statements.
    SimplyDanny
    #4548

  • Stop triggering unused_capture_list on captured variable that is only
    referenced by a shorthand optional binding (if let capturedVar { ... }).
    SimplyDanny
    #4804

  • Ensure that negative literals in initializers do not trigger
    no_magic_numbers rule.
    SimplyDanny
    #4677

  • Fix caching of indentation_width rule.
    SimplyDanny
    #4121

  • Updated JUnit reporter to output error count and warning count.
    patricks
    #4725

  • Fix correction on lower_acl_than_parent rule for open declarations.
    Marcelo Fabri
    #4753

  • Fix void_return rule to support async and async throws functions.
    Mathias Schreck
    #4772

  • Fix false positives in attributes rule when using property wrappers
    with keypath arguments.
    JP Simard

  • Fix for superfluous_disable_command not being completely disabled
    by disable commands.
    Martin Redington
    #4788

  • Fixed correction for trailing_comma rule wrongly removing trailing
    comments.
    Martin Redington
    #4814


Using Bazel

With bzlmod:

bazel_dep(name = "swiftlint", version = "0.51.0", repo_name = "SwiftLint")

Without bzlmod, put this in your WORKSPACE:

WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "build_bazel_rules_apple",
    sha256 = "9e26307516c4d5f2ad4aee90ac01eb8cd31f9b8d6ea93619fc64b3cbc81b0944",
    url = "https://github.com/bazelbuild/rules_apple/releases/download/2.2.0/rules_apple.2.2.0.tar.gz",
)

load(
    "@build_bazel_rules_apple//apple:repositories.bzl",
    "apple_rules_dependencies",
)

apple_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:extras.bzl",
    "swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

http_archive(
    name = "SwiftLint",
    sha256 = "8369ca218c4c898b7af202e2ec6180062396f659debca49a1d6c66902a3a37c3",
    url = "https://github.com/realm/SwiftLint/releases/download/0.51.0/bazel.tar.gz",
)

load("@SwiftLint//bazel:repos.bzl", "swiftlint_repos")

swiftlint_repos()

load("@SwiftLint//bazel:deps.bzl", "swiftlint_deps")

swiftlint_deps()

Then you can run SwiftLint in the current directory with this command:

bazel run @SwiftLint//:swiftlint -- --help

0.51.0-rc.2: bzllint

20 Feb 23:55
527e2c4
Compare
Choose a tag to compare
0.51.0-rc.2: bzllint Pre-release
Pre-release

This is a prerelease version. It won't be published to Homebrew, CocoaPods or bzlmod. But there are many other ways to install:

  • Downloading the attached SwiftLint.pkg installer and launching it
  • Downloading the attached portable_swiftlint.zip archive, extracting it and moving the binary from portable_swiftlint/swiftlint to /usr/local/bin or elsewhere in your PATH
  • Using Mint: mint install realm/SwiftLint@0.51.0-rc.2
  • Cloning and building from source: git clone https://github.com/realm/SwiftLint.git && cd SwiftLint && git checkout 0.51.0-rc.2 && make install
  • Docker: docker run -it -v `pwd`:`pwd` -w `pwd` ghcr.io/realm/swiftlint:0.51.0-rc.2
  • Bazel: See instructions at the bottom

Changes from 0.50.3: 0.50.3...0.51.0-rc.2
Changes from 0.51.0-rc.1: 0.51.0-rc.1...0.51.0-rc.2


Breaking

  • Deprecate the unused_capture_list rule in favor of the Swift compiler
    warning. At the same time, make it an opt-in rule.
    Cyberbeni
    #4656

  • Deprecate the inert_defer rule in favor of the Swift compiler warning.
    At the same time, make it an opt-in rule.
    SimplyDanny
    #4615

Experimental

  • None.

Enhancements

  • Add local links to rule descriptions to every rule listed
    in Rule Directory.md.
    kattouf

  • Make forceExclude work with directly specified files.
    jimmya
    #issue_number

  • Separate analyzer rules as an independent section in the rule directory of
    the reference.
    Ethan Wong
    #4664

  • Add rule identifier to output of Emoji reporter.
    SimplyDanny
    #4707

  • Interpret strings in excluded option of identifier_name,
    type_name and generic_type_name rules as regex.
    Moly
    #4655

  • Add new direct_return rule that triggers on return statements returning
    variables that have been declared in the statement before only.
    SimplyDanny

  • Add period_spacing opt-in rule that checks periods are not followed
    by 2 or more spaces in comments.
    Julioacarrettoni
    #4624

  • Allow to pass a rule identifier to the swiftlint docs command to open its
    specific documentation website, e.g. swiftlint docs for_where.
    SimplyDanny
    #4707

  • Allow new Quick APIs aroundEach and justBeforeEach for
    quick_discouraged_call.
    David Steinacher
    #4626

  • Add relative-path reporter to generate reports with relative file paths.
    Roya1v
    #4660

  • Let number_separator rule trigger on misplaced separators, e.g. 10_00.
    SimplyDanny
    #4637

  • Rewrite multiline_arguments rule using SwiftSyntax, ignoring trailing
    closures.
    Marcelo Fabri
    #3399
    #3605

  • Speed up linting by up to 6% updating to use a newer version of
    SwiftSyntax.
    JP Simard

  • Catch more valid legacy_multiple violations.
    JP Simard

  • Catch more valid no_magic_numbers violations.
    JP Simard

Bug Fixes

  • Report violations in all <scope>_length rules when the error threshold is
    smaller than the warning threshold.
    SimplyDanny
    #4645

  • Consider custom attributes in attributes rule.
    SimplyDanny
    #4599

  • Stop triggering strict_fileprivate rule on symbols implementing a protocol
    in the same file.
    SimplyDanny
    #4692

  • Fix false positives on private_subject rule when using
    subjects inside functions.
    Marcelo Fabri
    #4643

  • Fix for compiler directives masking subsequent opening_brace
    violations.
    Martin Redington
    #3712

  • Rewrite explicit_type_interface rule with SwiftSyntax fixing a
    false-positive in if-case-let statements.
    SimplyDanny
    #4548

  • Ensure that negative literals in initializers do not trigger
    no_magic_numbers rule.
    SimplyDanny
    #4677

  • Fix caching of indentation_width rule.
    SimplyDanny
    #4121

  • Updated JUnit reporter to output error count and warning count.
    patricks
    #4725

  • Fix correction on lower_acl_than_parent rule for open declarations.
    Marcelo Fabri
    #4753

  • Fix void_return rule to support async and async throws functions.
    Mathias Schreck
    #4772

  • Fix false positives in attributes rule when using property wrappers
    with keypath arguments.
    JP Simard


Using Bazel

Put this in your WORKSPACE:

WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "build_bazel_rules_apple",
    sha256 = "43737f28a578d8d8d7ab7df2fb80225a6b23b9af9655fcdc66ae38eb2abcf2ed",
    url = "https://github.com/bazelbuild/rules_apple/releases/download/2.0.0/rules_apple.2.0.0.tar.gz",
)

load(
    "@build_bazel_rules_apple//apple:repositories.bzl",
    "apple_rules_dependencies",
)

apple_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:extras.bzl",
    "swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

http_archive(
    name = "SwiftLint",
    sha256 = "f0e37c2ca277ef8c50d865cbdb75326592bcba11b786caf1fccc3111e9925e01",
    url = "https://github.com/realm/SwiftLint/releases/download/0.51.0-rc.2/bazel.tar.gz",
)

load("@SwiftLint//bazel:repos.bzl", "swiftlint_repos")

swiftlint_repos()

load("@SwiftLint//bazel:deps.bzl", "swiftlint_deps")

swiftlint_deps()

Then you can run SwiftLint in the current directory with this command:

bazel run @SwiftLint//:swiftlint -- --help

0.51.0-rc.1: bzllint

20 Feb 21:47
b652231
Compare
Choose a tag to compare
0.51.0-rc.1: bzllint Pre-release
Pre-release

This is a prerelease version. It won't be published to Homebrew, CocoaPods or bzlmod. But there are many other ways to install:

  • Downloading the attached SwiftLint.pkg installer and launching it
  • Downloading the attached portable_swiftlint.zip archive, extracting it and moving the binary from portable_swiftlint/swiftlint to /usr/local/bin or elsewhere in your PATH
  • Using Mint: mint install realm/SwiftLint@0.51.0-rc.1
  • Cloning and building from source: git clone https://github.com/realm/SwiftLint.git && cd SwiftLint && git checkout 0.51.0-rc.1 && make install
  • Docker: docker run -it -v `pwd`:`pwd` -w `pwd` ghcr.io/realm/swiftlint:0.51.0-rc.1
  • Bazel: See instructions at the bottom

Changes from 0.50.3: 0.50.3...0.51.0-rc.1


Breaking

  • Deprecate the unused_capture_list rule in favor of the Swift compiler
    warning. At the same time, make it an opt-in rule.
    Cyberbeni
    #4656

  • Deprecate the inert_defer rule in favor of the Swift compiler warning.
    At the same time, make it an opt-in rule.
    SimplyDanny
    #4615

Experimental

  • None.

Enhancements

  • Add local links to rule descriptions to every rule listed
    in Rule Directory.md.
    kattouf

  • Make forceExclude work with directly specified files.
    jimmya
    #issue_number

  • Separate analyzer rules as an independent section in the rule directory of
    the reference.
    Ethan Wong
    #4664

  • Add rule identifier to output of Emoji reporter.
    SimplyDanny
    #4707

  • Interpret strings in excluded option of identifier_name,
    type_name and generic_type_name rules as regex.
    Moly
    #4655

  • Add new direct_return rule that triggers on return statements returning
    variables that have been declared in the statement before only.
    SimplyDanny

  • Add period_spacing opt-in rule that checks periods are not followed
    by 2 or more spaces in comments.
    Julioacarrettoni
    #4624

  • Allow to pass a rule identifier to the swiftlint docs command to open its
    specific documentation website, e.g. swiftlint docs for_where.
    SimplyDanny
    #4707

  • Allow new Quick APIs aroundEach and justBeforeEach for
    quick_discouraged_call.
    David Steinacher
    #4626

  • Add relative-path reporter to generate reports with relative file paths.
    Roya1v
    #4660

  • Let number_separator rule trigger on misplaced separators, e.g. 10_00.
    SimplyDanny
    #4637

  • Rewrite multiline_arguments rule using SwiftSyntax, ignoring trailing
    closures.
    Marcelo Fabri
    #3399
    #3605

  • Speed up linting by up to 6% updating to use a newer version of
    SwiftSyntax.
    JP Simard

  • Catch more valid legacy_multiple violations.
    JP Simard

  • Catch more valid no_magic_numbers violations.
    JP Simard

Bug Fixes

  • Report violations in all <scope>_length rules when the error threshold is
    smaller than the warning threshold.
    SimplyDanny
    #4645

  • Consider custom attributes in attributes rule.
    SimplyDanny
    #4599

  • Stop triggering strict_fileprivate rule on symbols implementing a protocol
    in the same file.
    SimplyDanny
    #4692

  • Fix false positives on private_subject rule when using
    subjects inside functions.
    Marcelo Fabri
    #4643

  • Fix for compiler directives masking subsequent opening_brace
    violations.
    Martin Redington
    #3712

  • Rewrite explicit_type_interface rule with SwiftSyntax fixing a
    false-positive in if-case-let statements.
    SimplyDanny
    #4548

  • Ensure that negative literals in initializers do not trigger
    no_magic_numbers rule.
    SimplyDanny
    #4677

  • Fix caching of indentation_width rule.
    SimplyDanny
    #4121

  • Updated JUnit reporter to output error count and warning count.
    patricks
    #4725

  • Fix correction on lower_acl_than_parent rule for open declarations.
    Marcelo Fabri
    #4753

  • Fix void_return rule to support async and async throws functions.
    Mathias Schreck
    #4772

  • Fix false positives in attributes rule when using property wrappers
    with keypath arguments.
    JP Simard


Using Bazel

Put this in your WORKSPACE:

WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "build_bazel_rules_apple",
    sha256 = "43737f28a578d8d8d7ab7df2fb80225a6b23b9af9655fcdc66ae38eb2abcf2ed",
    url = "https://github.com/bazelbuild/rules_apple/releases/download/2.0.0/rules_apple.2.0.0.tar.gz",
)

load(
    "@build_bazel_rules_apple//apple:repositories.bzl",
    "apple_rules_dependencies",
)

apple_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:extras.bzl",
    "swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

http_archive(
    name = "SwiftLint",
    sha256 = "f44b1e1c9aac0b4febbfae8479fc4e60df099066076fb10dfc0f42fd83731170",
    url = "https://github.com/realm/SwiftLint/releases/download/0.51.0-rc.1/bazel.tar.gz",
)

load("@SwiftLint//bazel:repos.bzl", "swiftlint_repos")

swiftlint_repos()

load("@SwiftLint//bazel:deps.bzl", "swiftlint_deps")

swiftlint_deps()

Then you can run SwiftLint in the current directory with this command:

bazel run @SwiftLint//:swiftlint -- --help