2

I'm trying to write a new rule around array subscripting uses in SwiftLint, but I can't seem to get the information I need. So for the following example Swift code:

let arr = [1, 2, 3]
let dict = [1: "hi", 2: "bye"]
arr[2]
dict[2]

I want a rule that will warn me that arr[2] could crash but not dict[2] (so I don't think a regex rule will work).

I tried playing with SourceKitten from the command line and couldn't find any way to get information about an array subscript access. I also tried making my own ASTRule in SwiftLint and had it create a warning on every single line, but the warnings only appeared on declarations, not expressions, and I can't find any existing ASTRules that don't relate to declarations, so I don't know where to start.

Nick Shelley
  • 271
  • 3
  • 8

0 Answers0