Skip to content

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

@stephengurnett

Description

@stephengurnett

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
}

Metadata

Metadata

Assignees

Labels

bugUnexpected and reproducible misbehavior.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions