Swiftlint: inclusive_language false positives: Triggering terms as substrings of identifiers

Created on 8 Nov 2020  路  3Comments  路  Source: realm/SwiftLint

New Issue Checklist

Describe the bug

We have a project that deals with payments provided by Mastercard and as such it is common to have code such as:

let mastercard = newWalletItem(for: .mastercard)

This triggers a violation of the inclusive_language rule as the identifier contains a triggering term as a substring.

Is it possible to the break triggering terms in identifiers using camel case so let masterThread is a violation but let mastercard is not?

Complete output when running SwiftLint, including the stack trace and command used

N/A

Environment

  • SwiftLint version: 0.41.0
  • Installation method used: CocoaPods
  • Paste your configuration file:
    N/A - Default rule

  • Are you using nested configurations?
    N/A

  • Which Xcode version are you using (check xcodebuild -version)?
    Xcode 12.1

  • Do you have a sample that shows the issue?

// This triggers a violation:
`let mastercard = newWalletItem(for: .mastercard)`
public enum WalletItemType: String {
    case visa = "VISA"
    // This triggers a violation:
    case mastercard = "MASTERCARD"
}
bug

Most helpful comment

@jpsim Yah, I'd be happy to take a look at this.

All 3 comments

Thanks for the report. @daltonclaybrook do you think you could build in tokenization based on camel/snake casing?

@jpsim Yah, I'd be happy to take a look at this.

Is it possible to set an exception somewhere in SwiftLint's config for terms we cannot control, such as mastercard?

Edit: see https://github.com/realm/SwiftLint/pull/3439

Was this page helpful?
0 / 5 - 0 ratings