From 17d17e8820428b838b2d16ea289bf70f1751e4f7 Mon Sep 17 00:00:00 2001 From: Martin Redington Date: Mon, 11 Sep 2023 18:58:17 +0100 Subject: [PATCH] Ignore 100 in `no_magic_numbers` rule (#5215) --- CHANGELOG.md | 5 +++++ .../Rules/Idiomatic/NoMagicNumbersRule.swift | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12bda19095e..c2dc39e761f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,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 * Respect grapheme clusters in counting the number of characters in the `collection_alignment` rule. diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/NoMagicNumbersRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/NoMagicNumbersRule.swift index 59ec22d61d8..12008f7af1f 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/NoMagicNumbersRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/NoMagicNumbersRule.swift @@ -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)"), @@ -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 {