pomsky icon indicating copy to clipboard operation
pomsky copied to clipboard

Linter

Open Aloso opened this issue 3 years ago • 0 comments

Is your feature request related to a problem? Please describe.

These days, many languages have top-notch tooling to help the developer write idiomatic, easy-to-understand code. Pomsky should be no exception.

Describe the solution you'd like

A linter, part of pomsky-bin and the VS code extension, which gives the developer useful suggestions.

Lints that I'd like to have:

  • [ ] Unreachable alternative: ('ab' | 'abc')
    • Since the first alternative always matches when the second would also match, the second alternative is never reached and therefore useless
  • [ ] Empty expression: let x = ; or ()
    • Also detects when the input is completely empty, or contains only let bindings
  • [ ] Unnecessary modifier: 'a'? lazy or enable greedy; 'a' greedy
  • [ ] Unnecessary parentheses: ('ab')?
  • [ ] Unnecessary repetition: ('x'?)? or 'x'{1}
  • [ ] Unnecessary repetition chain: 'a'{2}{5}
    • Could be written with a single repetition
  • [ ] Impossible forward reference: ::1 :('x')
    • Since the reference is not in a repeated group together with the referenced expression, it can never match successfully
  • [ ] Too lazy repetition: C* or 'x'* C
    • The lazy repetition is not followed by a "terminator"; a terminator is an expression that is not a subset of the repeated expression. For example, C is not a terminator for 'x'?, because it always matches when 'x' would match
    • This should not trigger the lint
      • 'x'* C 'y'
      • ('x'* C) 'y'
  • [ ] Exponential backtracking
    • This might be difficult to detect correctly in all situations, but a solution with many false negatives and few false positives is better than nothing
  • [ ] Too many numbered capturing groups: :('a') :('a') :('a') :('a') :('a') :('a') :('a') :('a') :('a') :('a') :('a') :('a')
    • Threshold should be configurable

Aloso avatar Aug 02 '22 13:08 Aloso