Search code examples
eslinttslintprettier

Tslint/eslint vs prettier


Tslint (probably as well as eslint) has a --fix param, that fixes style errors. Is there any reason I should also consider using prettier, other than "prettier has more style rules"?


Solution

  • There are a few good reasons why you'd use Prettier over TSLint:

    • Prettier is much faster than TSLint at formatting because it doesn't need to run as many rules or use type information.
    • Prettier is much more opinionated in its output. That means you get a much more strictly enforced style guide for you. TSLint's whitespace rule and related are intentionally not feature-complete with Prettier (reference).
    • Prettier reformats code more strictly than TSLint. You have to do a lot less of your own formatting work (and if others are working on your project, everybody's code will look much more similar).

    Here's a common approach if you're still interested:

    • In your tslint.json, use tslint-config-prettier to disable any formatting rules that conflict with Prettier
    • Per Prettier's docs, use husky and pretty-quick to auto-run Prettier on all Git commits