0.50.0: Artisanal Clothes Pegs
Breaking
-
SwiftLint now requires Swift 5.7 or higher to build.
JP Simard -
Exclude
weak_delegate
rule from autocorrection due to behavioral changes
leading to potential undefined behavior or bugs.
SimplyDanny
#3577 -
The
anyobject_protocol
rule is now deprecated and will be completely removed
in a future release because it is now handled by the Swift compiler.
JP Simard -
Built-in SwiftLint rules are no longer marked as
public
in
SwiftLintFramework. This only impacts the programmatic API for the
SwiftLintFramework module.
JP Simard
Experimental
- None.
Enhancements
-
SwiftSyntax libraries have been updated from the previous 5.6 release and now
use the new parser written in Swift.
Swift 5.7+ features should now be parsed more accurately.
We've also measured an improvement in lint times of up to 15%.
This should also fix some deployment issues where the exact version of the
internal SwiftSyntax parser needed to be available.
If you notice any unexpected changes to lint results, please file an issue on
the SwiftLint issue tracker. We can look into it and if it's a SwiftSyntax
parser regression we can re-file it upstream.
JP Simard
#4031 -
Rewrite some rules with SwiftSyntax, fixing some false positives and catching
more violations:anonymous_argument_in_multiline_closure
array_init
attributes
balanced_xctest_lifecycle
block_based_kvo
class_delegate_protocol
closing_brace
closure_body_length
closure_parameter_position
collection_alignment
comment_spacing
computed_accessors_order
conditional_returns_on_newline
contains_over_filter_count
contains_over_filter_is_empty
contains_over_first_not_nil
contains_over_range_nil_comparison
convenience_type
deployment_target
discarded_notification_center_observer
discouraged_assert
discouraged_direct_init
discouraged_none_name
discouraged_object_literal
discouraged_optional_boolean
duplicate_enum_cases
duplicated_key_in_dictionary_literal
dynamic_inline
empty_collection_literal
empty_count
empty_enum_arguments
empty_parameters
empty_parentheses_with_trailing_closure
empty_string
enum_case_associated_values_count
explicit_enum_raw_value
explicit_init
explicit_top_level_acl
fallthrough
file_name
first_where
flatmap_over_map_reduce
for_where
force_try
force_unwrapping
function_body_length
function_default_parameter_at_end
function_parameter_count
generic_type_name
ibinspectable_in_extension
identical_operands
implicit_getter
implicitly_unwrapped_optional
inclusive_language
inert_defer
is_disjoint
joined_default_parameter
large_tuple
last_where
legacy_cggeometry_functions
legacy_constant
legacy_constructor
legacy_hashing
legacy_multiple
legacy_nsgeometry_functions
legacy_objc_type
legacy_random
lower_acl_than_parent
multiline_arguments_brackets
multiline_parameters
multiple_closures_with_trailing_closure
no_extension_access_modifier
no_fallthrough_only
no_space_in_method_call
notification_center_detachment
nslocalizedstring_key
nslocalizedstring_require_bundle
nsobject_prefer_isequal
number_separator
object_literal
operator_whitespace
optional_enum_case_matching
orphaned_doc_comment
overridden_super_call
override_in_extension
pattern_matching_keywords
prefer_nimble
prefer_self_in_static_references
prefer_self_type_over_type_of_self
prefer_zero_over_explicit_init
prefixed_toplevel_constant
private_action
private_outlet
private_over_fileprivate
private_subject
private_unit_test
prohibited_interface_builder
prohibited_super_call
protocol_property_accessors_order
quick_discouraged_focused_test
quick_discouraged_pending_test
raw_value_for_camel_cased_codable_enum
reduce_boolean
reduce_into
redundant_discardable_let
redundant_nil_coalescing
redundant_objc_attribute
redundant_optional_initialization
redundant_set_access_control
redundant_string_enum_value
required_deinit
required_enum_case
return_arrow_whitespace
self_in_property_initialization
shorthand_operator
single_test_class
sorted_first_last
static_operator
strict_fileprivate
strong_iboutlet
switch_case_alignment
switch_case_on_newline
test_case_accessibility
toggle_bool
trailing_comma
trailing_semicolon
type_body_length
type_name
unneeded_break_in_switch
unneeded_parentheses_in_closure_argument
unowned_variable_capture
untyped_error_in_catch
unused_capture_list
unused_closure_parameter
unused_control_flow_label
unused_enumerated
unused_optional_binding
unused_setter_value
valid_ibinspectable
vertical_parameter_alignment
weak_delegate
xct_specific_matcher
xctfail_message
Marcelo Fabri
SimplyDanny
JP Simard
#2915
-
The "body length" family of rules have changed how they calculate body
line count to be significantly more correct and intuitive. However,
this is likely to require adjustments to your configuration or disable
commands to account for the changes.
JP Simard -
Add ability to filter rules for
generate-docs
subcommand.
kattouf -
Add new
excludes_trivial_init
configuration formissing_docs
rule
to exclude initializers without any parameters.
Marcelo Fabri
#4107 -
Add new
ns_number_init_as_function_reference
rule to catchNSNumber.init
andNSDecimalNumber.init
being used as function references since it
can cause the wrong initializer to be used, causing crashes. See
swiftlang/swift#51036 for more info.
Marcelo Fabri -
Add
accessibility_trait_for_button
rule to warn if a SwiftUI
View has a tap gesture added to it without having the button or
link accessibility trait.
Ryan Cole -
Add methods from SE-0348 to
UnusedDeclarationRule
.
JP Simard -
Include the configured
bind_identifier
inself_binding
violation
messages.
JP Simard -
The
self_binding
rule now catches shorthand optional bindings (for example
if let self {}
) when using abind_identifier
different thanself
.
Marcelo Fabri -
Add
library_content_provider
file type tofile_types_order
rule
to allowLibraryContentProvider
to be ordered independent frommain_type
.
dahlborn -
Add
test_parent_classes
option totest_case_accessibility
rule, which
allows detection in subclasses of XCTestCase.
Martin Redington
#4200 -
Add a new
shorthand_optional_binding
opt-in rule that triggers in Swift 5.7
when a shadowing optional binding is created in anif
orguard
statement.
SimplyDanny
#4202 -
Use SwiftSyntax instead of SourceKit to determine if a file has parser errors
before applying corrections. This speeds up corrections significantly when
none of the rules use SourceKit.
JP Simard -
Add Swift Package Build Tool Plugin with support for Swift Packages
and Xcode projects.
Johannes Ebeling
#3679
#3840 -
Make
private_unit_test
rule correctable.
SimplyDanny -
Disregard whitespace differences in
identical_operands
rule. That is, the rule
now also triggers if the left-hand side and the right-hand side of an operation
only differ in trivia.
SimplyDanny -
Print violations in realtime if
--progress
and--output
are both set.
JP Simard -
Trigger
prefer_self_in_static_references
rule on more type references like:- Key paths (e.g.
\MyType.myVar
->\Self.myVar
) - Computed properties (e.g.
var i: Int { MyType.myVar )
->var i: Int { Self.myVar }
) - Constructor calls (e.g.
MyType()
->Self()
)
- Key paths (e.g.
-
Update
for_where
rule, adding a new configuration
allow_for_as_filter
to allow usingfor in
with a singleif
inside
when there's areturn
statement inside theif
's body.
Marcelo Fabri
#4040 -
quick_discouraged_call
,quick_discouraged_focused_test
and
quick_discouraged_pending_test
rules now trigger on subclasses of
QuickSpec
.
Marcelo Fabri
#4420 -
The
type_name
rule now validates protocol declarations by default.
You can opt-out by using thevalidate_protocols
key in your configuration:type_name: validate_protocols: false
-
Report how much memory was used when
--benchmark
is specified.
JP Simard -
Adds
NSError
to the list of types indiscouraged_direct_init
.
jszumski
#4508 -
Fix SwiftLint support on Xcode Cloud.
JagCesar
westerlund
#4484 -
Add
no_magic_numbers
rule to avoid "Magic Numbers".
Henrik Storch
#4031 -
Add new option
only_enforce_before_trivial_lines
to
vertical_whitespace_closing_braces
rule. It restricts
the rule to apply only before trivial lines (containing
only closing braces, brackets and parentheses). This
allows empty lines before non-trivial lines of code
(e.g. if-else-statements).
benjamin-kramer
#3940
Bug Fixes
-
Respect
validates_start_with_lowercase
option when linting function names.
Chris Brakebill
#2708 -
Do not report variables annotated with
@NSApplicationDelegateAdaptor
and
@WKExtensionDelegateAdaptor
inweak_delegate
rule.
Till Hainbach
#3598
#3611 -
Fix false-positives related to the
willMove
lifecycle method in
type_contents_order
rule.
SimplyDanny
#3478 -
Do no longer autocorrect usage of
NSIntersectionRect
inlegacy_nsgeometry_functions
rule.
SimplyDanny
#3703 -
Fix Analyzer rules in Xcode 14.
SimplyDanny
#4208 -
Add column for SourceKit usage to
rules
command.
JP Simard -
Make
nsobject_prefer_isequal
rule work for nested@objc
classes. Also consider
the@objcMembers
annotation.
SimplyDanny -
Print fixed content at most once to STDOUT.
SimplyDanny
#4211 -
Fix fatal error when content given via STDIN is corrected in the
trailing_newline
rule.
SimplyDanny
#4234 -
Fix false-positives from
multiline_arguments_brackets
when a function call has a
single line trailing closure.
CraigSiemens
#4510
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 = "f94e6dddf74739ef5cb30f000e13a2a613f6ebfa5e63588305a71fce8a8a9911",
url = "https://github.com/bazelbuild/rules_apple/releases/download/1.1.3/rules_apple.1.1.3.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 = "c99be76ea5efd6ff7e60b6df8a11b709d50c75dfdbd6fb429de9bbe9e45cdb1f",
url = "https://github.com/realm/SwiftLint/releases/download/0.50.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