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

no_magic_numbers false positive for enum cases with a negative value #4677

Closed
stephengurnett opened this issue Jan 9, 2023 · 0 comments · Fixed by #4679
Closed

no_magic_numbers false positive for enum cases with a negative value #4677

stephengurnett opened this issue Jan 9, 2023 · 0 comments · Fixed by #4679
Assignees
Labels
bug Unexpected and reproducible misbehavior.

Comments

@stephengurnett
Copy link

stephengurnett commented Jan 9, 2023

New Issue Checklist

Describe the bug

Negative numbers (except for -1) will trigger the no_magic_numbers - e.g. case negative = -2. Equivalent positive numbers (e.g. 2) are fine.

Complete output when running SwiftLint, including the stack trace and command used
swiftlint lint Example.swift --enable-all-rules
Linting Swift files at paths Example.swift
Linting 'Example.swift' (1/1)
The `anyobject_protocol` rule is now deprecated and will be completely removed in a future release.
./Example.swift:3:22: warning: No Magic Numbers Violation: Magic numbers should be replaced by named constants. (no_magic_numbers)
Done linting! Found 1 violation, 0 serious in 1 file.

Environment

  • SwiftLint version (run swiftlint version to be sure)? 0.50.3

  • Installation method used (Homebrew, CocoaPods, building from source, etc)? Portable

  • Paste your configuration file: None

  • Are you using nested configurations? No

  • Which Xcode version are you using (check xcodebuild -version)? 14.2

  • Do you have a sample that shows the issue?echo "internal enum Example {\n case positive = 2\n case negative = -2\n}" | swiftlint lint --no-cache --use-stdin --enable-all-rules

enum Example: Int {
    case positive = 2
    case negative = -2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants