javascript linter 是否有可能判断正则表达式是否总是产生非空匹配?
s.match(/\w*/)[0] // valid
s.match(/\w+/)[0] // invalid
s.match(/id(\d{7})/)[1] // invalid
s.match(/id(\d{7})|$/)[1] // valid
最佳答案
不,eslint 不能分析这样的代码,至少不能开箱即用。
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/
也许您可以编写一个插件来验证这些情况。
关于javascript - 验证匹配不能为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50687816/