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
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
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.