You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 26, 2019. It is now read-only.
-[Changing the Page `<title>`](#changing-the-page-title)
21
22
-[Installing a Dependency](#installing-a-dependency)
22
23
-[Importing a Component](#importing-a-component)
@@ -264,6 +265,59 @@ Then add the block below to your `launch.json` file and put it inside the `.vsco
264
265
265
266
Start your app by running `npm start`, and start debugging in VS Code by pressing `F5` or by clicking the green debug icon. You can now write code, set breakpoints, make changes to the code, and debug your newly modified code—all from your editor.
266
267
268
+
## Formatting Code Automatically
269
+
270
+
Prettier is an opinionated JavaScript formatter. With Prettier you can format the code you write automatically to ensure a code style within your project. See the [Prettier's GitHub page](https://github.com/prettier/prettier) for more information, and look at this [page to see it in action](https://prettier.github.io/prettier/).
271
+
272
+
To format our code whenever we make a commit in git, we need to install the following dependencies:
273
+
274
+
```
275
+
npm install --save-dev husky lint-staged prettier
276
+
```
277
+
278
+
or if you use Yarn:
279
+
280
+
```
281
+
yarn add --dev husky lint-staged prettier
282
+
```
283
+
284
+
*`husky` makes it easy to use githooks as if they are npm scripts.
285
+
*`lint-staged` allows us to run scripts on staged files in git. See this [blog post about lint-staged to learn more about it](https://medium.com/@okonetchnikov/make-linting-great-again-f3890e1ad6b8).
286
+
*`prettier` is the JavaScript formatter we will run before commits.
287
+
288
+
Now we can make sure every file is formatted correctly by adding a few lines to the `package.json` in the project root.
289
+
290
+
Add the following line to `scripts` section:
291
+
292
+
```js
293
+
{
294
+
// ...
295
+
"scripts": {
296
+
// ...
297
+
"precommit":"lint-staged"
298
+
},
299
+
// ...
300
+
}
301
+
```
302
+
303
+
Next we add a 'lint-staged' field to the `package.json`, for example:
304
+
305
+
```js
306
+
{
307
+
// ...
308
+
"lint-staged": {
309
+
"src/**/*.{js,jsx}": [
310
+
"prettier --single-quote --write",
311
+
"git add"
312
+
]
313
+
}
314
+
}
315
+
```
316
+
317
+
Now, whenever you make a commit, Prettier will format the changed files automatically. You can also run `./node_modules/.bin/prettier --single-quote --write "src/**/*.{js,jsx}"` to format your entire project for the first time.
318
+
319
+
Next you might want to integrate Prettier in your favorite editor. Read the section on [Editor Integration](https://github.com/prettier/prettier#editor-integration) on the Prettier GitHub page.
320
+
267
321
## Changing the Page `<title>`
268
322
269
323
You can find the source HTML file in the `public` folder of the generated project. You may edit the `<title>` tag in it to change the title from “React App” to anything else.
0 commit comments