Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested disable commands #5796

Conversation

mildm8nnered
Copy link
Collaborator

Addresses #5788

The problem is that Regions are created with all of the rule identifiers that are disabled in them, with a new region being created for each swiftlint: command, more or less.

So an inner region may have multiple rules disabled, when disabled commands are nested, but not all of those rules might be violated within that specific region.

I guess people don't actually nest commands much in practice, at least for custom rules, or this would have created more noise.

This was not as hard to fix as I was afraid it might have been.

The basic idea is to remap the regions before passing them to superfluousDisableCommandViolations, so that the new regions describe the specific region that an individual rule is disabled within.

We could just calculate the regions that way in the first place, but the regions are used in multiple places, and I didn't want to interfere with any of the other call-sites right now.

Needs more tests in CustomRulesTests for sure.

Probably doesn't need to be a public method, if we're only using it for superfluousDisableCommandViolations - I just started with it there, and wanted it exposed right now - the RegionTests changes can probably go as well, once CustomRulesTests have more coverage, but I just wanted to make sure I'd got it right in all the existing cases and some new ones.

@mildm8nnered mildm8nnered force-pushed the mildm8nnered-fix-nested-disable-commands branch from 6a083a9 to 57511ee Compare September 15, 2024 21:51
@SwiftLintBot
Copy link

1 Warning
⚠️ If this is a user-facing change, please include a CHANGELOG entry to credit yourself!
You can find it at CHANGELOG.md.
17 Messages
📖 Linting Aerial with this PR took 0.93s vs 0.94s on main (1% faster)
📖 Linting Alamofire with this PR took 1.28s vs 1.28s on main (0% slower)
📖 Linting Brave with this PR took 7.46s vs 7.45s on main (0% slower)
📖 Linting DuckDuckGo with this PR took 5.0s vs 5.0s on main (0% slower)
📖 Linting Firefox with this PR took 11.04s vs 11.04s on main (0% slower)
📖 Linting Kickstarter with this PR took 10.03s vs 10.04s on main (0% faster)
📖 Linting Moya with this PR took 0.53s vs 0.55s on main (3% faster)
📖 Linting NetNewsWire with this PR took 2.55s vs 2.55s on main (0% slower)
📖 Linting Nimble with this PR took 0.77s vs 0.77s on main (0% slower)
📖 Linting PocketCasts with this PR took 8.71s vs 8.7s on main (0% slower)
📖 Linting Quick with this PR took 0.43s vs 0.44s on main (2% faster)
📖 Linting Realm with this PR took 4.7s vs 4.72s on main (0% faster)
📖 Linting Sourcery with this PR took 2.36s vs 2.36s on main (0% slower)
📖 Linting Swift with this PR took 4.63s vs 4.59s on main (0% slower)
📖 Linting VLC with this PR took 1.25s vs 1.26s on main (0% faster)
📖 Linting Wire with this PR took 18.18s vs 18.28s on main (0% faster)
📖 Linting WordPress with this PR took 11.82s vs 11.79s on main (0% slower)

Here's an example of your CHANGELOG entry:

* Fix nested disable commands.  
  [mildm8nnered](https://github.com/mildm8nnered)
  [#issue_number](https://github.com/realm/SwiftLint/issues/issue_number)

note: There are two invisible spaces after the entry's text.

Generated by 🚫 Danger

@mildm8nnered
Copy link
Collaborator Author

Replaced by #5797

@mildm8nnered mildm8nnered deleted the mildm8nnered-fix-nested-disable-commands branch October 26, 2024 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants