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 single_test_class opt-in rule #1780

Merged
merged 5 commits into from
Aug 17, 2017

Conversation

ornithocoder
Copy link
Contributor

@ornithocoder ornithocoder commented Aug 16, 2017

Implements #1779 (Limit number of QuickSpecs and XCTestCases in file to one).

@SwiftLintBot
Copy link

SwiftLintBot commented Aug 16, 2017

44 Warnings
⚠️ Make sure that the docs are updated by running the Generate docs scheme.
⚠️ This PR introduced a violation in Firefox: /StoragePerfTests/StoragePerfTests.swift#L35:1: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Firefox: /StoragePerfTests/StoragePerfTests.swift#L56:1: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Nimble: /Tests/NimbleTests/Matchers/BeAKindOfTest.swift#L10:7: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Nimble: /Tests/NimbleTests/Matchers/BeAKindOfTest.swift#L59:7: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Nimble: /Tests/NimbleTests/Matchers/BeLogicalTest.swift#L32:7: warning: Single Test Class Violation: 4 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Nimble: /Tests/NimbleTests/Matchers/BeLogicalTest.swift#L125:7: warning: Single Test Class Violation: 4 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Nimble: /Tests/NimbleTests/Matchers/BeLogicalTest.swift#L161:7: warning: Single Test Class Violation: 4 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Nimble: /Tests/NimbleTests/Matchers/BeLogicalTest.swift#L236:7: warning: Single Test Class Violation: 4 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickFocusedTests/FocusedTests.swift#L28:1: warning: Single Test Class Violation: 3 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickFocusedTests/FocusedTests.swift#L43:1: warning: Single Test Class Violation: 3 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickFocusedTests/FocusedTests.swift#L54:7: warning: Single Test Class Violation: 3 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/BeforeSuiteTests.swift#L7:1: warning: Single Test Class Violation: 3 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/BeforeSuiteTests.swift#L15:1: warning: Single Test Class Violation: 3 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/BeforeSuiteTests.swift#L23:7: warning: Single Test Class Violation: 3 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/BeforeEachTests.swift#L16:1: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/BeforeEachTests.swift#L53:7: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/BehaviorTests.swift#L6:1: warning: Single Test Class Violation: 4 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/BehaviorTests.swift#L12:1: warning: Single Test Class Violation: 4 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/BehaviorTests.swift#L21:1: warning: Single Test Class Violation: 4 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/BehaviorTests.swift#L38:7: warning: Single Test Class Violation: 4 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/AfterEachTests.swift#L16:1: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/AfterEachTests.swift#L68:7: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/Configuration/AfterEach/Configuration+AfterEachTests.swift#L5:1: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/Configuration/AfterEach/Configuration+AfterEachTests.swift#L16:7: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/Configuration/BeforeEach/Configuration+BeforeEachTests.swift#L5:1: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/Configuration/BeforeEach/Configuration+BeforeEachTests.swift#L13:7: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/CrossReferencingSpecs.swift#L7:1: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/CrossReferencingSpecs.swift#L14:1: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/DescribeTests.swift#L7:7: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/DescribeTests.swift#L19:1: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/SharedExamples+BeforeEachTests.swift#L19:1: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/SharedExamples+BeforeEachTests.swift#L27:7: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/PendingTests.swift#L15:1: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/PendingTests.swift#L34:7: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/SharedExamplesTests.swift#L6:1: warning: Single Test Class Violation: 4 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/SharedExamplesTests.swift#L12:1: warning: Single Test Class Violation: 4 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/SharedExamplesTests.swift#L19:1: warning: Single Test Class Violation: 4 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/SharedExamplesTests.swift#L36:7: warning: Single Test Class Violation: 4 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/ItTests.swift#L5:1: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Quick: /Tests/QuickTests/QuickTests/FunctionalTests/ItTests.swift#L108:7: warning: Single Test Class Violation: 2 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Sourcery: /Templates/Tests/Context/LinuxMain.swift#L12:1: warning: Single Test Class Violation: 3 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Sourcery: /Templates/Tests/Context/LinuxMain.swift#L22:1: warning: Single Test Class Violation: 3 test classes found in this file. (single_test_class)
⚠️ This PR introduced a violation in Sourcery: /Templates/Tests/Context/LinuxMain.swift#L33:1: warning: Single Test Class Violation: 3 test classes found in this file. (single_test_class)
12 Messages
📖 Linting Aerial with this PR took 0.37s vs 0.38s on master (2% faster)
📖 Linting Alamofire with this PR took 2.37s vs 2.55s on master (7% faster)
📖 Linting Firefox with this PR took 9.98s vs 10.88s on master (8% faster)
📖 Linting Kickstarter with this PR took 14.77s vs 16.46s on master (10% faster)
📖 Linting Moya with this PR took 1.01s vs 1.1s on master (8% faster)
📖 Linting Nimble with this PR took 1.37s vs 1.46s on master (6% faster)
📖 Linting Quick with this PR took 0.44s vs 0.46s on master (4% faster)
📖 Linting Realm with this PR took 2.08s vs 2.2s on master (5% faster)
📖 Linting SourceKitten with this PR took 0.78s vs 0.85s on master (8% faster)
📖 Linting Sourcery with this PR took 3.59s vs 3.8s on master (5% faster)
📖 Linting Swift with this PR took 10.45s vs 10.68s on master (2% faster)
📖 Linting WordPress with this PR took 9.63s vs 9.86s on master (2% faster)

Generated by 🚫 Danger

@ornithocoder ornithocoder changed the title Add quick_single_spec opt-in rule Add single_test_class opt-in rule Aug 16, 2017
Implements realm#1779 (Limit number of QuickSpecs in file to one).
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.

Just some nitpicks, but this looks great in general!


private func toViolation(in file: File,
configuration: SeverityConfiguration,
numberOfSpecs: Int) -> ([String: SourceKitRepresentable]) -> StyleViolation? {
Copy link
Collaborator

Choose a reason for hiding this comment

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

change numberOfSpecs to numberOfTestClasses (or any other name to avoid using specs)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not applicable anymore.

}
}

private func toViolation(in file: File,
Copy link
Collaborator

Choose a reason for hiding this comment

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

what do you think about changing this method name? For me, toSomething usually means that the method will use self as input and convert it to Something.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, just now I've realized that it returns a function. Do we really need that? I think it just makes harder to read and the benefits are not so evident.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree. it's a simple function and doesn't need to be isolated. changing it to a closure.

}

private func toViolation(in file: File,
configuration: SeverityConfiguration,
Copy link
Collaborator

Choose a reason for hiding this comment

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

you don't need to pass the configuration here since it's a property anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not applicable anymore.

}
}

private func testClasses() -> [String] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this could be a let to avoid being created everytime (or even declared in testClasses(in:)).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


private func testClasses(in file: File) -> [[String: SourceKitRepresentable]] {
return file.structure.dictionary.substructure.filter {
!$0.inheritedTypes.filter { testClasses().contains($0) }.isEmpty
Copy link
Collaborator

@marcelofabri marcelofabri Aug 16, 2017

Choose a reason for hiding this comment

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

you probably should check if the type is a class as well (just in case ¯\(ツ)/¯)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done :-)

@marcelofabri marcelofabri merged commit 49475d3 into realm:master Aug 17, 2017
@marcelofabri
Copy link
Collaborator

Thanks @ornithocoder! 🚀

@ornithocoder
Copy link
Contributor Author

You're welcome @marcelofabri! :-) Thank you for the code review!

@ornithocoder ornithocoder deleted the quick_spec_limit branch August 17, 2017 08:53
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