DEV Community

Discussion on: Using ESLint and Prettier in a TypeScript Project

Collapse
 
gyandeeps profile image
Gyandeep Singh • Edited

Just curious about your opinion on if you need to use a linter to check code if you use typescript in strict mode. For styles, for sure using prettier makes sens to me.

Collapse
 
robertcoopercode profile image
Robert Cooper • Edited

Good question. Using a linter allows you to check on a lot of stuff that isn't covered by the TypeScript compiler. For example, if you take a look at some of these ESLint rules for TypeScript code, you'll find a lot of rules related to code style that can be enforced with a linter.

Here are a few examples:

  • @typescript-eslint/explicit-function-return-type: Require explicit return types on functions and class methods
  • @typescript-eslint/generic-type-naming: Enforces naming of generic type variables
  • @typescript-eslint/no-array-constructor: Disallow generic Array constructors
  • @typescript-eslint/no-unused-vars: Disallow unused variables
Collapse
 
gyandeeps profile image
Gyandeep Singh

all of the rules above are again kinda of stylistic (last one is already covered directly by typescript). If something is wrong, typescript will tell u during compile regardless whether you specify function return type explicitly or not.. I also depend on computer types in typescript (maybe thats why i think like this for linter with strict mode)

Thread Thread
 
robertcoopercode profile image
Robert Cooper • Edited

Well if you don't mind having the code written in a project not conform to code style rules, then a linter is of no value. You just might have a large variance in the way code is structured/ordered, variables are named, and other code style related things.

When I'm working on a project, I prefer to look at the code base and have it look like it was all written by the same person. A linter helps achieve this in my opinion.

Thread Thread
 
braposo profile image
Bernardo Raposo

And there's still things like no explicit any that can be enforced by the linter.

Thread Thread
 
ca0v profile image
Corey Alix

This is also a tsconfig option. What use is eslint really? Tsconfig.json and .prettierrc cover most cases as far as I can tell. Is there one compelling use case for eslint?

Thread Thread
 
robertcoopercode profile image
Robert Cooper

There are many eslint rules that aren’t covered by tsconfig options.