0

I have a custom SwiftLint action to flag up print() statements:

custom_rules:
    disable_print:
      included: ".*\\.swift"
      name: "print usage"
      regex: "((\\bprint)|(Swift\\.print))\\s*\\("
      message: "Don't use print"
      severity: error

It works but it also flags whenever I have a print() statement specified in a documentation comment like this:

/// some comment mentioning print("hello") <- Error here
func myFunc() {}

How can I alter the regex so it ignores the print statement whenever it's in a documentation comment?

halfer
  • 19,824
  • 17
  • 99
  • 186
Tometoyou
  • 7,792
  • 12
  • 62
  • 108
  • Why do you flag print statements in the first place? Wouldn't it be easier to disable the rule for specific places in comments? – Sulthan Mar 11 '22 at 18:42
  • @Sulthan Because I don't want them inside my swift package. I've no idea if that's easier or not – Tometoyou Mar 11 '22 at 18:49

1 Answers1

1

It seems that a custom rule can specify what type of code will match. The property is called match_kinds, example from Swiftlint Readme:

match_kinds: # SyntaxKinds to match. optional.
   - comment
   - identifier

Specifying identifier should be enough for your use case.

Sulthan
  • 128,090
  • 22
  • 218
  • 270