Skip to content

Commit 5594460

Browse files
committed
Combine a few articles on setting up your editor
1 parent 964d2fb commit 5594460

File tree

7 files changed

+136
-156
lines changed

7 files changed

+136
-156
lines changed

docusaurus/docs/debugging-in-the-editor.md

Lines changed: 0 additions & 50 deletions
This file was deleted.

docusaurus/docs/formatting-code-automatically.md

Lines changed: 0 additions & 54 deletions
This file was deleted.

docusaurus/docs/lint-output-in-the-editor.md

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
id: setting-up-your-editor
3+
title: Setting up your Editor
4+
sidebar_label: Setting up your Editor
5+
---
6+
7+
## Syntax highlighting
8+
9+
To configure the syntax highlighting in your favorite text editor, head to the [relevant Babel documentation page](https://babeljs.io/docs/editors) and follow the instructions. Some of the most popular editors are covered.
10+
11+
## Displaying Lint Output in the Editor
12+
13+
> Note: this feature is available with `[email protected]` and higher.<br>
14+
> It also only works with npm 3 or higher.
15+
16+
Some editors, including Sublime Text, Atom, and Visual Studio Code, provide plugins for ESLint.
17+
18+
They are not required for linting. You should see the linter output right in your terminal as well as the browser console. However, if you prefer the lint results to appear right in your editor, there are some extra steps you can do.
19+
20+
You would need to install an ESLint plugin for your editor first. Then, add a file called `.eslintrc` to the project root:
21+
22+
```js
23+
{
24+
"extends": "react-app"
25+
}
26+
```
27+
28+
Now your editor should report the linting warnings.
29+
30+
Note that even if you edit your `.eslintrc` file further, these changes will **only affect the editor integration**. They won’t affect the terminal and in-browser lint output. This is because Create React App intentionally provides a minimal set of rules that find common mistakes.
31+
32+
If you want to enforce a coding style for your project, consider using [Prettier](https://github.com/jlongster/prettier) instead of ESLint style rules.
33+
34+
## Debugging in the Editor
35+
36+
**This feature is currently only supported by [Visual Studio Code](https://code.visualstudio.com) and [WebStorm](https://www.jetbrains.com/webstorm/).**
37+
38+
Visual Studio Code and WebStorm support debugging out of the box with Create React App. This enables you as a developer to write and debug your React code without leaving the editor, and most importantly it enables you to have a continuous development workflow, where context switching is minimal, as you don’t have to switch between tools.
39+
40+
### Visual Studio Code
41+
42+
You would need to have the latest version of [VS Code](https://code.visualstudio.com) and VS Code [Chrome Debugger Extension](https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome) installed.
43+
44+
Then add the block below to your `launch.json` file and put it inside the `.vscode` folder in your app’s root directory.
45+
46+
```json
47+
{
48+
"version": "0.2.0",
49+
"configurations": [
50+
{
51+
"name": "Chrome",
52+
"type": "chrome",
53+
"request": "launch",
54+
"url": "http://localhost:3000",
55+
"webRoot": "${workspaceRoot}/src",
56+
"sourceMapPathOverrides": {
57+
"webpack:///src/*": "${webRoot}/*"
58+
}
59+
}
60+
]
61+
}
62+
```
63+
64+
> Note: the URL may be different if you've made adjustments via the [HOST or PORT environment variables](/docs/advanced-configuration).
65+
66+
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.
67+
68+
Having problems with VS Code Debugging? Please see their [troubleshooting guide](https://github.com/Microsoft/vscode-chrome-debug/blob/master/README.md#troubleshooting).
69+
70+
### WebStorm
71+
72+
You would need to have [WebStorm](https://www.jetbrains.com/webstorm/) and [JetBrains IDE Support](https://chrome.google.com/webstore/detail/jetbrains-ide-support/hmhgeddbohgjknpmjagkdomcpobmllji) Chrome extension installed.
73+
74+
In the WebStorm menu `Run` select `Edit Configurations...`. Then click `+` and select `JavaScript Debug`. Paste `http://localhost:3000` into the URL field and save the configuration.
75+
76+
> Note: the URL may be different if you've made adjustments via the [HOST or PORT environment variables](/docs/advanced-configuration).
77+
78+
Start your app by running `npm start`, then press `^D` on macOS or `F9` on Windows and Linux or click the green debug icon to start debugging in WebStorm.
79+
80+
The same way you can debug your application in IntelliJ IDEA Ultimate, PhpStorm, PyCharm Pro, and RubyMine.
81+
82+
## Formatting Code Automatically
83+
84+
Prettier is an opinionated code formatter with support for JavaScript, CSS and JSON. 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/).
85+
86+
To format our code whenever we make a commit in git, we need to install the following dependencies:
87+
88+
```sh
89+
npm install --save husky lint-staged prettier
90+
```
91+
92+
Alternatively you may use `yarn`:
93+
94+
```sh
95+
yarn add husky lint-staged prettier
96+
```
97+
98+
- `husky` makes it easy to use githooks as if they are npm scripts.
99+
- `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).
100+
- `prettier` is the JavaScript formatter we will run before commits.
101+
102+
Now we can make sure every file is formatted correctly by adding a few lines to the `package.json` in the project root.
103+
104+
Add the following field to the `package.json` section:
105+
106+
```diff
107+
+ "husky": {
108+
+ "hooks": {
109+
+ "pre-commit": "lint-staged"
110+
+ }
111+
+ }
112+
```
113+
114+
Next we add a 'lint-staged' field to the `package.json`, for example:
115+
116+
```diff
117+
"dependencies": {
118+
// ...
119+
},
120+
+ "lint-staged": {
121+
+ "src/**/*.{js,jsx,json,css}": [
122+
+ "prettier --single-quote --write",
123+
+ "git add"
124+
+ ]
125+
+ },
126+
"scripts": {
127+
```
128+
129+
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.
130+
131+
Next you might want to integrate Prettier in your favorite editor. Read the section on [Editor Integration](https://prettier.io/docs/en/editors.html) on the Prettier GitHub page.

docusaurus/docs/syntax-highlighting-in-the-editor.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docusaurus/website/i18n/en.json

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@
5555
"code-splitting": {
5656
"title": "Code Splitting"
5757
},
58-
"debugging-in-the-editor": {
59-
"title": "Debugging in the Editor"
60-
},
6158
"debugging-tests": {
6259
"title": "Debugging Tests",
6360
"sidebar_label": "Debugging tests"
@@ -79,10 +76,6 @@
7976
"folder-structure": {
8077
"title": "Folder structure"
8178
},
82-
"formatting-code-automatically": {
83-
"title": "Formatting Code Automatically",
84-
"sidebar_label": "Formatting code"
85-
},
8679
"generating-dynamic-meta-tags-on-the-server": {
8780
"title": "Generating Dynamic `<meta>` Tags on the Server"
8881
},
@@ -102,10 +95,6 @@
10295
"integrating-with-an-api-backend": {
10396
"title": "Integrating with an API Backend"
10497
},
105-
"lint-output-in-the-editor": {
106-
"title": "Displaying Lint Output in the Editor",
107-
"sidebar_label": "In-editor linting"
108-
},
10998
"making-a-progressive-web-app": {
11099
"title": "Making a Progressive Web App"
111100
},
@@ -131,6 +120,10 @@
131120
"title": "Sending feedback",
132121
"sidebar_label": "Feedback"
133122
},
123+
"setting-up-your-editor": {
124+
"title": "Setting up your Editor",
125+
"sidebar_label": "Setting up your Editor"
126+
},
134127
"something-missing": {
135128
"title": "Something missing?",
136129
"sidebar_label": "Something missing?"
@@ -139,10 +132,6 @@
139132
"title": "Supported Browsers and Features",
140133
"sidebar_label": "Browsers and Features"
141134
},
142-
"syntax-highlighting-in-the-editor": {
143-
"title": "Syntax highlighting in the editor",
144-
"sidebar_label": "Syntax highlighting"
145-
},
146135
"troubleshooting": {
147136
"title": "Troubleshooting",
148137
"sidebar_label": "Troubleshooting"

docusaurus/website/sidebars.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
"updating-to-new-releases"
1212
],
1313
"Development": [
14-
"syntax-highlighting-in-the-editor",
15-
"lint-output-in-the-editor",
16-
"debugging-in-the-editor",
17-
"formatting-code-automatically",
14+
"setting-up-your-editor",
1815
"developing-components-in-isolation",
1916
"analyzing-the-bundle-size",
2017
"using-https-in-development"

0 commit comments

Comments
 (0)