I thought I'd collect some rules I'd like to see that are impossible with the current ESLint. For posterity.
RegExp#exec() over String#match() - Requires type analysis..includes() over .indexOf() - While it's possible today with some assumption. It's not perfect and would be improved with some type analysis..startsWith()/.endsWith() over regex/indexOf/slice/etc - Only the regex case is possible today. With type analysis, we could do all the cases in that issue.Comment on other things that would be cool if ESLint didn't have its current limits.
Flow can already be compiled to JavaScript, that's how we run in the browser (https://flowtype.org/try/), if you want to experiment with doing eslint rules that consume Flow I can help you out with that.
I suspect it will be slower than you want because Flow is more meant for incremental checks with a server running in the background. Where eslint can get away with starting up cold. It's not _that_ slow, but you will notice the difference.
That'd be really awesome! I'd love to work on that!
Added it to my team's backlog.
Writing rules targeted at TypeScript and taking advantage of its type information would solve many of these problems.
I'm playing around with the new Typescript eslint parser, and I think I'd like to try my hand at a POC implementation of some of these. Will still have to ignore non or untyped nodes, but I think many of these are possible now with @typescript-eslint
@RichiCoder1 Awesome! 馃憤
I would be happy to host them over at eslint-plugin-unicorn if you want.
- Prefer
RegExp#exec()overString#match()- Requires type analysis.
https://github.com/typescript-eslint/typescript-eslint/issues/283
- Prefer
.includes()over.indexOf()- While it's possible today with some assumption. It's not perfect and would be improved with some type analysis.
https://github.com/typescript-eslint/typescript-eslint/issues/284
- Prefer
.startsWith()/.endsWith()over regex/indexOf/slice/etc - Only the regex case is possible today. With type analysis, we could do all the cases in that issue.
https://github.com/typescript-eslint/typescript-eslint/issues/285
Most helpful comment
Writing rules targeted at TypeScript and taking advantage of its type information would solve many of these problems.
https://twitter.com/sindresorhus/status/1089602422236864512