0

Is it possible that javascript linter will tell if regex will allways produce nonempty match?

s.match(/\w*/)[0]           // valid
s.match(/\w+/)[0]           // invalid
s.match(/id(\d{7})/)[1]     // invalid
s.match(/id(\d{7})|$/)[1]   // valid

PS: Same question in Russian.

Qwertiy
  • 19,681
  • 15
  • 61
  • 128

1 Answers1

1

No, eslint cannot analyze code like this at least out of the box.

Code linting is a type of static analysis that is frequently used to find problematic patterns or code that doesn’t adhere to certain style guidelines.

https://eslint.org/docs/about/

Maybe you could write a plugin to validate those cases.

Wayrex
  • 2,027
  • 1
  • 14
  • 25
  • 1
    Is it possible to validate such thing for any regex? Or specified problem is equal to [halting problem](https://en.wikipedia.org/wiki/Halting_problem)? – Qwertiy Jun 05 '18 at 15:07