Skip to content

Commit edf6a68

Browse files
author
Cyril CHAPON
committed
docs(linting-formatting): Document code linting and formatting
1 parent f966702 commit edf6a68

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

content/first-steps.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,49 @@ $ npm run start:dev
112112
```
113113

114114
This command will watch your files, automatically recompiling and reloading the server.
115+
116+
#### Linting / formatting
117+
118+
[Nest CLI](/cli/overview) provides best effort to scaffold a reliable development workflow at scale. Thus, a generated Nest project comes with both a code **formatter** and **linter** preinstalled (respectively [eslint](https://eslint.org/) and [prettier](https://prettier.io/)).
119+
120+
> info **Hint** Not sure about the role of formatters VS linters ? Learn the difference [here](https://prettier.io/docs/en/comparison.html).
121+
122+
##### VSCode usage
123+
To ensure maximum stability and extensibility, we use official [`eslint`](https://www.npmjs.com/package/eslint) and [`prettier`](https://www.npmjs.com/package/prettier) cli packages. This setup allows neat IDE integration with official tooling.
124+
125+
For example with *VSCode*, a Nest project is compatible with [`vscode-eslint`](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and [`prettier-vscode`](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) by design !
126+
127+
> warning **Warning** You might be tempted to try [~~`vs-code-prettier-eslint`~~](https://marketplace.visualstudio.com/items?itemName=rvest.vs-code-prettier-eslint). This extension is meant to play with [~~`prettier-eslint`~~](https://github.com/prettier/prettier-eslint) package witch is **not** used inside a Nest project by default.
128+
129+
##### Scripted usage
130+
For headless environments where an IDE is not relevant (*Continuous Integration*, *Git hooks*, ...), a Nest project comes with ready-to-use `npm` (or `yarn`) scripts.
131+
132+
```bash
133+
# Lint and autofix with eslint
134+
npm run lint
135+
# Format with prettier
136+
npm run format
137+
138+
# OR
139+
140+
# Lint and autofix with eslint
141+
yarn lint
142+
# Format with prettier
143+
yarn format
144+
```
145+
146+
##### Plugins and config
147+
148+
A Nest cli scaffolded project uses
149+
- [`eslint-plugin-prettier`](https://github.com/prettier/eslint-plugin-prettier) to remove conflicting rules from `eslint` for use with `prettier`.
150+
- [`@typescript-eslint/plugin`](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin) to enable Typescript linting
151+
152+
> info **Hint** You can learn more about the behavior of `eslint-plugin-prettier` in its [documentation](https://github.com/prettier/eslint-plugin-prettier#recommended-configuration) and discover the actual configuration inside generated [`.eslintrc.js`](https://github.com/nestjs/typescript-starter/blob/master/.eslintrc.js) file
153+
154+
##### Code style
155+
156+
With this stack setup, by default we ensure the resulting code follows :
157+
- Typescript eslint [recommended rules](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended.ts)
158+
- Improved with some [rules in `.eslintrc.js` file](https://github.com/nestjs/typescript-starter/blob/master/.eslintrc.js)
159+
- Prettier [default options](https://prettier.io/docs/en/options.html)
160+
- Improved with some [options in `.prettierrc` file](https://github.com/nestjs/typescript-starter/blob/master/.prettierrc)

0 commit comments

Comments
 (0)