Search code examples
regexswiftlint

Attributes in SwiftLint custom regex-based rules


I am creating custom rule for SwiftLint that checks the spelling of color. I need this to be case insensitive.

I am currently matching using regex: "([C|c]olour)" but I would like to use the case insensitive modifier /i. I have tried the following rule but it doesn't work:

custom_rules:
  color_us_english:
    regex: "(colour)/i"
    message: "Use US English spelling to match Apple's API."
    severity: warning

How do you use modifiers in SwiftLint?


Solution

  • It could be that the following is not supported:

    "(colour)/i"
    

    Please try:

    "(?i)(colour)"
    

    Have a look at this example.