-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Mildm8nnered skip unit tests in magic numbers rule #4897
Mildm8nnered skip unit tests in magic numbers rule #4897
Conversation
Should be resolved by #4897 |
} | ||
|
||
private extension ClassDeclSyntax { | ||
func isTestClass(testParentClasses: Set<String>) -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The isXCTestCase
already exists on ClassDeclSyntax
objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have remembered that :-)
"""), | ||
Example(""" | ||
class FooTests: XCTestCase { | ||
class Bar { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nested classes are discussable if they are not themselves test classes. But I agree that this rule should be disabled in test code generally. So ignoring them as well is fine.
CHANGELOG.md
Outdated
@@ -31,6 +31,11 @@ | |||
[Martin Redington](https://github.com/mildm8nnered) | |||
[#4819](https://github.com/realm/SwiftLint/issues/4819) | |||
|
|||
* Adds `test_parent_classes` option to the `magic_numbers` rule. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Adds `test_parent_classes` option to the `magic_numbers` rule. | |
* Adds `test_parent_classes` option to the `no_magic_numbers` rule. |
CR comments addressed |
Thank you for the fast implementation! |
WIP
Fixes #4896
Adds a
test_parent_classes
to the Magic Number Rule.Violations within a class that inherits directly from one of the specified parent classes (by default
XCTestCase
andQuickSpec
) will be ignored.This includes violations within inner classes of a class that inherits directly from one of the specified parent classes.
If users wish to detect violations of the rule within unit tests, they can simply set
test_parent_classes
to[]
.I also "aligned" some of the labels in other classes that also use a similar configuration (actually the same configuration, but typealiased). In some places we were referring to
testClasses
, which is actuallytestParentClasses
.