News for hackers. Stuff that matters.
Re:Starting a TypeScript Project in 2021 by meheleventyone on Wednesday April 21, 2021 @09:43AM (#26889582)
I’m curious about the value of eslint for TypeScript. I’ve not really found myself wanting from the coverage provided by tsc.
Re:Starting a TypeScript Project in 2021 by halfmatthalfcat on Wednesday April 21, 2021 @09:50AM (#26889661)
To be honest, I was really happy with TSLint. The amount of configuration and scaffolding around ESLint is a big turnoff from me compared to how easy it was to get TSLint going.
Re:Starting a TypeScript Project in 2021 by WorldMaker on Wednesday April 21, 2021 @04:29PM (#26895030)
A lot of the most common TSLint "boxed" configurations have direct ESLint relatives at this point. For one opinionated example there is eslint-config-standard-with-typescript [1]. Using a prepared config like that is just as easy as using one built for TSLint. (It's an "extends" field that does most of the work.)

Though I admit I've kind of moved more towards even more opinionated Prettier than ESLint lately.

[1] https://www.npmjs.com/package/eslint-config-standard-with-ty...

Re:Starting a TypeScript Project in 2021 by thealfreds on Wednesday April 21, 2021 @10:26AM (#26890089)
It's useful if you have a custom eslint ruleset you want to apply to your ts projects. Some of those rules aren't always available on tslint.

Mostly helpful to keep a shared ruleset across projects.

Re:Starting a TypeScript Project in 2021 by andrew_ on Wednesday April 21, 2021 @09:57AM (#26889765)
The larger the pool of engineers on a project (or the larger a team size) the more important consistent formatting becomes. It may not be relevant for individual projects (though I'd disagree with that as well), but it makes maintenance of projects under larger teams, including distributed teams, a heck of a lot easier.
Re:Starting a TypeScript Project in 2021 by maga on Wednesday April 21, 2021 @11:27AM (#26890915)
prettier?
Re:Starting a TypeScript Project in 2021 by twistedpair on Wednesday April 21, 2021 @07:32PM (#26896720)
To us, the biggest value is auto-refactoring the code to comply w/ styleguides and rules. There are many great rules in eslint that cover most known anti-patterns. For a start, just grab the .eslintrc.json from the microsoft/typescript repo.

We've hooked up "eslint --fix" and "prettier --write" to "npm run fix".

One command before committing and you comply with all our coding rules. Easy, peasy. We tie the combined checks into "npm run check", and run this in CI/CD, so we know only compliant code is merge. Check!

Most other lang tools _won't_ do this. Take PMD or Checkstyle for Java. They'll just fail your build, but won't make your code compliant.

Finally, if you decide you want to add a new code convention to your repos, it's just a one liner: "npm run fix". It doesn't get much easier.

Re:Starting a TypeScript Project in 2021 by metachris on Wednesday April 21, 2021 @10:10AM (#26889918)
IDE integration is one benefit, as in VS Code showing the linting issues without compiling.
Re:Starting a TypeScript Project in 2021 by meheleventyone on Wednesday April 21, 2021 @10:24AM (#26890078)
I’m all for IDE integration but feel duty bound to point out tsc does this as well.
Re:Starting a TypeScript Project in 2021 by striking on Wednesday April 21, 2021 @12:17PM (#26891625)
Have you tried some of the type info based rules in typescript-eslint? They're fantastic.

No floating promises, no bad templating, etc.

Re:Starting a TypeScript Project in 2021 by meheleventyone on Wednesday April 21, 2021 @12:34PM (#26891892)
No but the replies here make me think I should definitely give it a go. So thanks for the info everybody!
Re:Starting a TypeScript Project in 2021 by dtech on Wednesday April 21, 2021 @10:33AM (#26890161)
Linting is not the same as typechecking. Take a look at the default available rules [1]. For example number == NaN is valid Javascript, but 99.9% of the time an error. Or you might want to require always using === over ==.

Generally, linting is things that are valid in the language, but still better to do otherwise.

[1] https://eslint.org/docs/rules/

Re:Starting a TypeScript Project in 2021 by meheleventyone on Wednesday April 21, 2021 @10:38AM (#26890231)
I’m aware of the difference just wondering what benefits people have found. Catching == versus === is a good one.
Re:Starting a TypeScript Project in 2021 by ponyous on Wednesday April 21, 2021 @12:30PM (#26891817)
import order, empty function bodies, leading underscores in different scenarios (if you have such conventions), sort object keys (not just alphabetically, but by use, eg. shorthands last { name: 'Jim', surname }...)

There is some overlap and it's not as crucial to have a good linter as it used to be.

Re:Starting a TypeScript Project in 2021 by GORRILA on Wednesday April 21, 2021 @11:09AM (#26890653)
Two common rules I like to enforce are no nested ternaries and no unused variables.
Re:Starting a TypeScript Project in 2021 by maga on Wednesday April 21, 2021 @11:29AM (#26890944)
tsconfig's noUnusedLocals can help you with the last one.
Re:Starting a TypeScript Project in 2021 by city41 on Wednesday April 21, 2021 @12:57PM (#26892248)
And it allows you to opt out when needed by starting the variable with an underscore, which is much nicer than eslint-disable-next-line...
Re:Starting a TypeScript Project in 2021 by DEiE on Wednesday April 21, 2021 @01:41PM (#26892947)
Re:Starting a TypeScript Project in 2021 by city41 on Wednesday April 21, 2021 @01:49PM (#26893048)
Ah nice, I didn't know that. Thanks.
Re:Starting a TypeScript Project in 2021 by city41 on Wednesday April 21, 2021 @09:51AM (#26889675)
I use eslint for things like catching left behind debugger and console statements.
Re:Starting a TypeScript Project in 2021 by madeofpalk on Wednesday April 21, 2021 @10:09AM (#26889901)
e.g. ban `any`, which you cannot do with tsc.