-
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
extension of test class should NOT trigger no_magic_numbers rule #5137
Comments
We're seeing this too on a scaled up commercial system where putting a |
As normal (and fast) SwiftLint rules operate on syntax-level only, it's impossible to know to which class, struct, ... declaration an extension belongs to. It only sees an extension called With some effort, this can perhaps be improved by tracking declarations in a single file but this will definitely not be supported across file boundaries. |
@JulyKikuAkita @johnkaplantech - are your extensions in the same file, or different files? I can probably get this to work for single files, but if that's not going to help you at all ... |
-Thank you for addressing that, work for single files will definitely help most of the scenarios. Our extensions for tests are usually at the same file, but for readability, there's some scenarios that we moved the extension to a different file.
|
Nested configurations are probably the easiest way to resolve this for extensions that are not in the same source file as the class declaration. Alternatively, you could just run SwiftLint twice - once with one config for your source files, and with another config for your test files. I think this |
New Issue Checklist
Describe the bug
no_magic_numbers
should not trigger in test code #4896 that no_magic_number rules should not apply to Tests, that only works within the test class but not extension of the test class.Complete output when running SwiftLint, including the stack trace and command used
Environment
We use default settings so "XCTestCase" should by default ignored by no_magic_number rule
no
xcodebuild -version
)?Xcode 14.3 Build version 14E222b
echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
to quickly test if your example is really demonstrating the issue. If your example is more
complex, you can use
swiftlint lint --path [file here] --no-cache --enable-all-rules
.The text was updated successfully, but these errors were encountered: