From 1b68a456fb75add6f4d0dbd141b3433fce4c4a0a Mon Sep 17 00:00:00 2001 From: Martin Redington Date: Sat, 9 Sep 2023 02:52:57 +0100 Subject: [PATCH 1/2] `no_magic_numbers` rule should ignore 100 --- CHANGELOG.md | 5 +++++ .../Rules/Idiomatic/NoMagicNumbersRule.swift | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4973552c4a..0b6de18761 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/NoMagicNumbersRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/NoMagicNumbersRule.swift index 59ec22d61d..74c997779c 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 { From 007226eb52358ed88536cf9f049708259cfee148 Mon Sep 17 00:00:00 2001 From: Martin Redington Date: Sat, 9 Sep 2023 02:59:04 +0100 Subject: [PATCH 2/2] Fixed trailing commas --- .../Rules/Idiomatic/NoMagicNumbersRule.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/NoMagicNumbersRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/NoMagicNumbersRule.swift index 74c997779c..12008f7af1 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/NoMagicNumbersRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/NoMagicNumbersRule.swift @@ -73,7 +73,7 @@ struct NoMagicNumbersRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule Example("let foo = 1 >> 2"), Example("let foo = 2 >> 2"), Example("let foo = 2 << 2"), - Example("let a = b / 100.0"), + Example("let a = b / 100.0") ], triggeringExamples: [ Example("foo(↓321)"),