SwiftLint
SwiftLint copied to clipboard
VerticalWhitespaceClosingBracesRule: Add specialized configuration.
This solves issue #3940
Replace the SeverityConfiguration
with a new VerticalWhitespaceClosingBracesConfiguration
, which includes severity
and only_enforce_before_trivial_lines
.
Vertical whitespace may be important for readability when the line with the closing brace is not a trivial one.
The configuration only_enforce_before_trivial_lines
allows not enforcing the rule in such cases.
E.g.
if someCondition {
// do something
// do something
} else if ... {
// do something
// do something
// do something
} else {
// do something
// do something
}
1 Warning | |
---|---|
:warning: | This PR may need tests. |
12 Messages | |
---|---|
:book: | Linting Aerial with this PR took 0.93s vs 0.94s on main (1% faster) |
:book: | Linting Alamofire with this PR took 1.16s vs 1.16s on main (0% slower) |
:book: | Linting Firefox with this PR took 5.39s vs 5.4s on main (0% faster) |
:book: | Linting Kickstarter with this PR took 7.62s vs 7.69s on main (0% faster) |
:book: | Linting Moya with this PR took 0.5s vs 0.5s on main (0% slower) |
:book: | Linting Nimble with this PR took 0.48s vs 0.48s on main (0% slower) |
:book: | Linting Quick with this PR took 0.21s vs 0.21s on main (0% slower) |
:book: | Linting Realm with this PR took 10.01s vs 10.02s on main (0% faster) |
:book: | Linting SourceKitten with this PR took 0.37s vs 0.38s on main (2% faster) |
:book: | Linting Sourcery with this PR took 1.88s vs 1.89s on main (0% faster) |
:book: | Linting Swift with this PR took 3.62s vs 3.61s on main (0% slower) |
:book: | Linting WordPress with this PR took 9.03s vs 9.03s on main (0% slower) |
Generated by :no_entry_sign: Danger
@jpsim Could you please assign someone to review this?
@SimplyDanny Made the corrections you suggested. Let me know whether to squash & rebase.
Let me know whether to squash & rebase.
Yes, please rebase.
Fixed, squashed and rebased.
Note that I added the .removingViolationMarkers()
again for the tests to pass.
Fixed, squashed and rebased. I'm experiencing technical difficulties after the rebase (I can't manage to run the tests locally due to various missing packages), and some of the tests fail with seemingly unrelated problems. Any idea what's going on here?
Are you on Xcode 14/Swift 5.7?
Xcode 13.4, Swift 5.6.1. In this guide, under "Building And Running Locally", the xcode version seems somewhat out of date, and doesn't explain how to run just the tests. When I try to do it (with a clean git status, and after deleting Xcode's derived data) I get:
cannot find 'swiftparse_parser_set_language_version' in scope cannot find 'swiftparse_parser_set_enable_bare_slash_regex_literal' in scope
When trying the command line version (swift build
) I get:
error: artifact of binary target 'lib_InternalSwiftSyntaxParser' has changed checksum; this is a potential security risk so the new artifact won't be downloaded error: artifact of binary target '_InternalSwiftSyntaxParser' has changed checksum; this is a potential security risk so the new artifact won't be downloaded
In any case, the CI system also has errors that seem unrelated to the changes in this PR.
Fixed and squashed.
Thank you for all the (re-)work and your patience, @benjamin-kramer!
@SimplyDanny
I just downloaded the latest release, that includes this PR.
When running swiftlint rules
I don't see the configuration I added (nor is it mentioned here). Why is this?
Edit:
Also tried running swiftlint
with a configuration file (.swiftlint.yml
) containing:
opt_in_rules:
- vertical_whitespace_closing_braces:
only_enforce_before_trivial_lines: true
And the rule doesn't run. It does run as expected when using the configuration:
opt_in_rules:
- vertical_whitespace_closing_braces
Am I doing this wrong, or did I fail to properly add the configuration in the PR?
@benjamin-kramer
When configuring rules, it needs to be done in a top-level yaml section:
opt_in_rules:
- vertical_whitespace_closing_braces
vertical_whitespace_closing_braces:
only_enforce_before_trivial_lines: true
Thanks! I verified that this works. Doesn't explain the lack of documentation though.
Doesn't explain the lack of documentation though.
Because the configuration description which is used to generate the docs is overridden to N/A
: https://github.com/realm/SwiftLint/blob/60ad710b7f1ecb7edac8102cae0f2be6acf94f25/Source/SwiftLintFramework/Rules/Style/VerticalWhitespaceClosingBracesRule.swift#L60
I'll fix this shortly.
Fixing the docs in https://github.com/realm/SwiftLint/pull/4594