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 rule should ignore 100 #5215

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
[Martin Redington](https://github.com/mildm8nnered)
[#5204](https://github.com/realm/SwiftLint/issues/5204)

* 100 is no longer considered to be a magic number by the `no_magic_numbers`
rule.
[Martin Redington](https://github.com/mildm8nnered)
[#5215](https://github.com/realm/SwiftLint/issues/5215)

#### Bug Fixes

* Fix false positive in `control_statement` rule that triggered on conditions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ struct NoMagicNumbersRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule
Example("let foo = 1 << 2"),
Example("let foo = 1 >> 2"),
Example("let foo = 2 >> 2"),
Example("let foo = 2 << 2")
Example("let foo = 2 << 2"),
Example("let a = b / 100.0")
],
triggeringExamples: [
Example("foo(↓321)"),
Expand Down Expand Up @@ -167,7 +168,7 @@ private extension TokenSyntax {
guard let number = Double(text.replacingOccurrences(of: "_", with: "")) else {
return false
}
if [0, 1].contains(number) {
if [0, 1, 100].contains(number) {
return false
}
guard let grandparent = parent?.parent else {
Expand Down