SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

VerticalWhitespaceClosingBracesRule: Add specialized configuration.

Open benjamin-kramer opened this issue 2 years ago • 5 comments

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
}

benjamin-kramer avatar Apr 10 '22 07:04 benjamin-kramer

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

SwiftLintBot avatar Apr 10 '22 07:04 SwiftLintBot

@jpsim Could you please assign someone to review this?

benjamin-kramer avatar Apr 20 '22 12:04 benjamin-kramer

@SimplyDanny Made the corrections you suggested. Let me know whether to squash & rebase.

benjamin-kramer avatar Aug 28 '22 08:08 benjamin-kramer

Let me know whether to squash & rebase.

Yes, please rebase.

jpsim avatar Aug 29 '22 19:08 jpsim

Fixed, squashed and rebased.

Note that I added the .removingViolationMarkers() again for the tests to pass.

benjamin-kramer avatar Sep 11 '22 14:09 benjamin-kramer

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?

benjamin-kramer avatar Sep 28 '22 12:09 benjamin-kramer

Are you on Xcode 14/Swift 5.7?

SimplyDanny avatar Sep 28 '22 13:09 SimplyDanny

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.

benjamin-kramer avatar Sep 28 '22 16:09 benjamin-kramer

Xcode 13.4, Swift 5.6.1.

On HEAD, you need to build with Swift 5.7 now, see CHANGELOG.

SimplyDanny avatar Sep 28 '22 17:09 SimplyDanny

Fixed and squashed.

benjamin-kramer avatar Sep 29 '22 07:09 benjamin-kramer

Thank you for all the (re-)work and your patience, @benjamin-kramer!

SimplyDanny avatar Sep 29 '22 18:09 SimplyDanny

@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 avatar Nov 20 '22 09:11 benjamin-kramer

@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

jpsim avatar Nov 24 '22 15:11 jpsim

Thanks! I verified that this works. Doesn't explain the lack of documentation though.

benjamin-kramer avatar Nov 24 '22 16:11 benjamin-kramer

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.

jpsim avatar Nov 25 '22 16:11 jpsim

Fixing the docs in https://github.com/realm/SwiftLint/pull/4594

jpsim avatar Nov 25 '22 16:11 jpsim