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

Add unused_control_flow_label rule #2545

Merged
merged 5 commits into from
Jan 6, 2019
Merged

Add unused_control_flow_label rule #2545

merged 5 commits into from
Jan 6, 2019

Conversation

marcelofabri
Copy link
Collaborator

Fixes #2227

Adding as a default rule because I think there shouldn't be false positives. Let's wait for oss-check.

@jpsim
Copy link
Collaborator

jpsim commented Jan 5, 2019

Thanks for doing this! I haven't reviewed yet, but here are some edge cases we should make sure to support:

if #available(iOS 11, *) {} else {
  // Impossible to negate an `#available` condition
}

if case .loading = state {} else {
  // Impossible to negate a case binding
}

@jpsim
Copy link
Collaborator

jpsim commented Jan 5, 2019

Oops, disregard my comment, I completely misunderstood what this rule was validating 😅

@SwiftLintBot
Copy link

SwiftLintBot commented Jan 5, 2019

12 Messages
📖 Linting Aerial with this PR took 2.18s vs 2.17s on master (0% slower)
📖 Linting Alamofire with this PR took 4.64s vs 4.95s on master (6% faster)
📖 Linting Firefox with this PR took 16.76s vs 16.07s on master (4% slower)
📖 Linting Kickstarter with this PR took 27.07s vs 23.28s on master (16% slower)
📖 Linting Moya with this PR took 2.51s vs 2.18s on master (15% slower)
📖 Linting Nimble with this PR took 2.48s vs 2.01s on master (23% slower)
📖 Linting Quick with this PR took 0.71s vs 0.64s on master (10% slower)
📖 Linting Realm with this PR took 4.44s vs 4.11s on master (8% slower)
📖 Linting SourceKitten with this PR took 1.42s vs 1.32s on master (7% slower)
📖 Linting Sourcery with this PR took 5.97s vs 5.39s on master (10% slower)
📖 Linting Swift with this PR took 38.1s vs 32.39s on master (17% slower)
📖 Linting WordPress with this PR took 27.25s vs 23.09s on master (18% slower)

Generated by 🚫 Danger

Copy link
Collaborator

@jpsim jpsim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a shitty implementation of correction if you're interested in using it as a prototype for adding real correction support. See unused_control_flow_label-shitty-correctable

CHANGELOG.md Outdated
@@ -27,6 +27,11 @@
`.last(where: { /* ... */ })` is more efficient.
[Marcelo Fabri](https://github.com/marcelofabri)

* Add `unused_control_flow_label` rule to validate that control flow labels are
being used.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/being used/used/

@marcelofabri
Copy link
Collaborator Author

I thought about adding autocorrection but given how rare it’s to use control labels, I thought that maybe it would be better to let a human evaluate if the right fix is to remove the label (vs using it)

@jpsim
Copy link
Collaborator

jpsim commented Jan 6, 2019

IMO it’s easier to review corrections & revert if necessary than to go through the warnings and manually fix them.

@marcelofabri
Copy link
Collaborator Author

Fair enough, will do that later 👍

@marcelofabri
Copy link
Collaborator Author

Pushed 41868b3 with a few changes on your prototype (I wouldn't call it shitty though 😅)

@jpsim
Copy link
Collaborator

jpsim commented Jan 6, 2019

Thanks! Gonna do another quick review pass.

@jpsim
Copy link
Collaborator

jpsim commented Jan 6, 2019

Ran OSSCheck locally since performance numbers from CI were concerning, but got -3% to +3%.

and inline firstToken(afterByteOffset:)
They're already ordered last to first in the file from the sorting
applied in `violationRanges(in file:)`
Copy link
Collaborator

@jpsim jpsim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 made some tiny changes

@marcelofabri marcelofabri merged commit 8b11489 into realm:master Jan 6, 2019
@marcelofabri
Copy link
Collaborator Author

Thanks @jpsim 🎉

@marcelofabri marcelofabri deleted the unused_control_flow_label branch January 6, 2019 09:46
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.

3 participants