denoland / deno_lint

Blazing fast linter for JavaScript and TypeScript written in Rust
https://lint.deno.land/
MIT License
1.51k stars 163 forks source link

feature request (lint): Warn user when they're trying to use `for in` with an array #1283

Open xyzshantaram opened 2 months ago

xyzshantaram commented 2 months ago

You are going full speed writing that new piece of code you want. You need to iterate over an array, but suddenly TS complains saying you've got the wrong type for your array member.

image

You spend fifteen minutes puzzling it out, before you message the team. There can't be anything wrong with your code, it's 3 lines! Is this a bug in TypeScript?

A coworker points it out. You have just been bit by an ancient failing of JavaScript: for ... in instead of for ... of.


I just ran into this scenario and I was thinking it would be awesome if the linter could warn you of this. It's already in typescript-eslint (no-for-in-array), but since Deno is all about DX and it's not very DX-friendly to have to set up a second linter outside your LSP, I thought I would ask.

Basically, deno lint could display an error like "Use of for ... in to iterate over an array, did you mean for ... of?" I don't know how difficult it would be to implement, but it would definitely be nice to have.

Thanks in advance!

petamoriken commented 2 months ago

Unfortunately, deno_lint cannot handle TypeScript types at the moment https://github.com/denoland/deno_lint/issues/556