Linting et Style de Code
You are reading the documentation for version 2 of FoalTS. Instructions for upgrading to this version are available here. The old documentation can be found here.
A linter is a tool that analizes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs. In particular, it helps teams to keep the code consistent between their members.
For example, with ESLint, the rule @typescript-eslint/quotes: single
enforces the use of single quotes throughout the code.
#
ESLint & TypeScriptFoalTS offers a pre-configuration for the linter ESLint. It is the most commonly used in the JavaScript ecosystem and can work with TypeScript through the @typescript-eslint/parser
and @typescript-eslint/eslint-plugin
packages.
You can run the linting with this command:
And if the linting issues can be automatically fixed, you can also fix them with this command:
#
Configuration with VSCodeInstructions to configure VSCode with ESLint and TypeScript can be found here.
#
Adding New RulesThe rules are specified in the .eslintrc
configuration file located at the root of the project.
The list of available JavaScript rules can be found on the ESLint website. Some of them are compatible with TypeScript. Others are not and you will need to find equivalents here.
#
Migrating from TSLintTSLint is a TypeScript linter that was previously used by FoalTS but has since been deprecated. This is why new versions of the framework use ESLint.
In order to migrate from TSLint to ESLint, you can refer to this page. It lists all TSLint rules along side rules from the ESLint ecosystem that are identical or similar.