SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

legacy_objc_type rule triggers on NSNumber in the context of NumberFormatter which requires it

Open tylerbarnesTrexis opened this issue 4 years ago • 3 comments

New Issue Checklist

Describe the bug

legacy_objc_type rule triggers on NSNumber in the context of NumberFormatter

Complete output when running SwiftLint, including the stack trace and command used
% swiftlint
Linting Swift files in current working directory
Linting 
...
Linting
warning: Legacy Objective-C Reference Type Violation: Prefer Swift value types to bridged Objective-C reference types (legacy_objc_type)
Done linting! Found 1 violation, 0 serious in files.

Environment

  • SwiftLint version: 0.44.0
  • Installation method used: Homebrew and SPM via Custom Package
  • Paste your configuration file:
only_rules:
  - legacy_objc_type
// This triggers a violation:
NumberFormatter.string(from: Double as NSNumber)

Originally posted by @PH9 in https://github.com/realm/SwiftLint/issues/3555#issuecomment-811875997

tylerbarnesTrexis avatar Sep 22 '21 00:09 tylerbarnesTrexis

We recently ran into this as well with the following APIs.

CraigSiemens avatar Jun 13 '22 16:06 CraigSiemens

In my opinion, there is nothing we can really do about that. When working with certain frameworks it is simply unavoidable to reference these types in some way. The rule is opt-in and can be disabled by comments in the code in case of (rare) exceptions.

SimplyDanny avatar Sep 03 '22 15:09 SimplyDanny

I got an error for NSNumber violation so changed: NSNumber.init(value: someValue) to NSNumber.(value: someValue)

Worked !

userException avatar Dec 07 '22 13:12 userException