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 multiple_closures_with_trailing_closure rule #1802

Merged
merged 1 commit into from
Aug 28, 2017
Merged

Add multiple_closures_with_trailing_closure rule #1802

merged 1 commit into from
Aug 28, 2017

Conversation

u2606
Copy link
Contributor

@u2606 u2606 commented Aug 27, 2017

As described in #1801, the Multiple Closures with Trailing Closure rule disallows trailing closure syntax when passing more than one closure argument to a function. This is my first PR for SwiftLint, so I’m certainly open to feedback.

Fixes #1801.

@SwiftLintBot
Copy link

SwiftLintBot commented Aug 27, 2017

48 Warnings
⚠️ This PR introduced a violation in Firefox: /Users/distiller/SwiftLint/osscheck/Firefox/Client/Frontend/Browser/QRCodeViewController.swift:148:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/SwiftLint/osscheck/Firefox/Client/Frontend/Browser/TabManager.swift:697:16: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/SwiftLint/osscheck/Firefox/Client/Frontend/Browser/TopTabsViewController.swift:417:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/SwiftLint/osscheck/Firefox/Client/Frontend/Browser/TabTrayController.swift:594:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Kickstarter: /Users/distiller/SwiftLint/osscheck/Kickstarter/Kickstarter-iOS/Views/Controllers/ProjectActivityViewControllerTests.swift:57:51: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Kickstarter: /Users/distiller/SwiftLint/osscheck/Kickstarter/Library/ViewModels/BackingCellViewModelTests.swift:54:51: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Kickstarter: /Users/distiller/SwiftLint/osscheck/Kickstarter/Library/ViewModels/ProjectActivitiesViewModelTests.swift:186:52: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Kickstarter: /Users/distiller/SwiftLint/osscheck/Kickstarter/Library/ViewModels/ProjectActivitiesViewModelTests.swift:199:51: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Moya: /Users/distiller/SwiftLint/osscheck/Moya/Tests/MoyaProvider+ReactiveSpec.swift:215:81: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Moya: /Users/distiller/SwiftLint/osscheck/Moya/Tests/MoyaProvider+ReactiveSpec.swift:260:100: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Moya: /Users/distiller/SwiftLint/osscheck/Moya/Tests/MoyaProvider+RxSpec.swift:101:81: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Moya: /Users/distiller/SwiftLint/osscheck/Moya/Tests/MoyaProvider+RxSpec.swift:153:100: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Moya: /Users/distiller/SwiftLint/osscheck/Moya/Tests/MoyaProvider+RxSpec.swift:195:102: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Moya: /Users/distiller/SwiftLint/osscheck/Moya/Tests/MoyaProviderIntegrationTests.swift:27:77: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Moya: /Users/distiller/SwiftLint/osscheck/Moya/Tests/MoyaProviderIntegrationTests.swift:31:89: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Moya: /Users/distiller/SwiftLint/osscheck/Moya/Tests/MoyaProviderIntegrationTests.swift:35:87: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Moya: /Users/distiller/SwiftLint/osscheck/Moya/Tests/MoyaProviderIntegrationTests.swift:39:96: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Moya: /Users/distiller/SwiftLint/osscheck/Moya/Tests/MoyaProviderSpec.swift:629:81: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Moya: /Users/distiller/SwiftLint/osscheck/Moya/Tests/MoyaProviderSpec.swift:702:100: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in Moya: /Users/distiller/SwiftLint/osscheck/Moya/Tests/MoyaProviderSpec.swift:820:98: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/Classes/Services/AccountSettingsService.swift:105:52: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/Classes/ViewRelated/Aztec/ViewControllers/AztecPostViewController.swift:2342:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/Classes/ViewRelated/Aztec/ViewControllers/AztecPostViewController.swift:2942:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/Classes/ViewRelated/Post/PostPostViewController.swift:122:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/Classes/ViewRelated/Post/AbstractPostListViewController.swift:924:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/DomainsServiceTests.swift:37:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/AppRatingUtilityTests.swift:299:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaFileManagerTests.swift:113:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaFileManagerTests.swift:126:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaThumbnailExporterTests.swift:25:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaThumbnailExporterTests.swift:50:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaURLExporterTests.swift:28:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaURLExporterTests.swift:66:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaURLExporterTests.swift:91:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaImageExporterTests.swift:24:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaImageExporterTests.swift:43:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaImageExporterTests.swift:63:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaImageExporterTests.swift:84:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaImageExporterTests.swift:105:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaImageExporterTests.swift:124:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaImageExporterTests.swift:146:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaImageExporterTests.swift:168:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaImageExporterTests.swift:192:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaImageExporterTests.swift:217:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaImageExporterTests.swift:240:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/MediaImageExporterTests.swift:260:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/NotificationSettingsServiceTests.swift:37:16: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/WordPressTest/OHHTTPStubs+Helpers.swift:12:12: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)
12 Messages
📖 Linting Aerial with this PR took 0.37s vs 0.35s on master (5% slower)
📖 Linting Alamofire with this PR took 2.48s vs 2.41s on master (2% slower)
📖 Linting Firefox with this PR took 10.57s vs 10.25s on master (3% slower)
📖 Linting Kickstarter with this PR took 16.12s vs 15.56s on master (3% slower)
📖 Linting Moya with this PR took 1.19s vs 1.16s on master (2% slower)
📖 Linting Nimble with this PR took 1.42s vs 1.38s on master (2% slower)
📖 Linting Quick with this PR took 0.47s vs 0.46s on master (2% slower)
📖 Linting Realm with this PR took 2.24s vs 2.15s on master (4% slower)
📖 Linting SourceKitten with this PR took 0.86s vs 0.85s on master (1% slower)
📖 Linting Sourcery with this PR took 3.79s vs 3.67s on master (3% slower)
📖 Linting Swift with this PR took 10.5s vs 10.05s on master (4% slower)
📖 Linting WordPress with this PR took 9.55s vs 9.33s on master (2% slower)

Generated by 🚫 Danger

@codecov-io
Copy link

codecov-io commented Aug 27, 2017

Codecov Report

Merging #1802 into master will increase coverage by 0.02%.
The diff coverage is 95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1802      +/-   ##
==========================================
+ Coverage   88.24%   88.26%   +0.02%     
==========================================
  Files         226      227       +1     
  Lines       11178    11218      +40     
==========================================
+ Hits         9864     9902      +38     
- Misses       1314     1316       +2
Impacted Files Coverage Δ
Tests/SwiftLintFrameworkTests/RulesTests.swift 100% <100%> (ø) ⬆️
...ules/MultipleClosuresWithTrailingClosureRule.swift 94.73% <94.73%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3b004e1...6fca21c. Read the comment docs.

return [
StyleViolation(ruleDescription: type(of: self).description,
severity: configuration.severity,
location: Location(file: file, byteOffset: call.offset))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think it would be better if we added the violation to the trailing closure? For example:

foo.something(param1: { $0 }) { $0 + 1 }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense to me. I had initially put the violation at the start of the function call because that's where it is for trailing_closure, but I think the start of the trailing closure is more precise.

Copy link
Collaborator

@marcelofabri marcelofabri left a comment

Choose a reason for hiding this comment

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

Thanks for you contribution 💯

Could you please just rebase and generate the docs again?

Multiple Closures with Trailing Closure rule disallows trailing closure
syntax when passing more than one closure argument to a function.

Fixes #1801.
@u2606
Copy link
Contributor Author

u2606 commented Aug 28, 2017

Rebased and docs regenerated.

Note that I also added // swiftlint:disable file_length to Tests/SwiftLintFrameworkTests/RulesTests.swift, because this commit together with the recent changes to master cause that file to exceed the 400 line limit.

@marcelofabri marcelofabri merged commit 25d70b5 into realm:master Aug 28, 2017
@marcelofabri
Copy link
Collaborator

Thanks @erikstrottmann 🚀

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.

4 participants