Skip to content

Commit 02794d1

Browse files
committed
add configuration on how to setup eslint for typescript along with vscode plugins
1 parent 8601c4d commit 02794d1

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

setup/README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
## 타입스크립트 프로젝트 환경 구성
2+
3+
1. 프로젝트 폴더 생성
4+
2. `npm init -y``package.json` 파일 생성
5+
3. 아래 명령어로 타입스크립트 및 문법 검사, 코드 정리 도구 라이브러리 추가
6+
7+
```sh
8+
npm i -D typescript @babel/core @babel/preset-env @babel/preset-typescript @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint prettier eslint-plugin-prettier
9+
```
10+
11+
4. 프로젝트 폴더 바로 아래에 ESLint 설정 파일 추가
12+
13+
```js
14+
// .eslintrc.js
15+
module.exports = {
16+
root: true,
17+
env: {
18+
browser: true,
19+
node: true,
20+
},
21+
extends: [
22+
'eslint:recommended',
23+
'plugin:@typescript-eslint/eslint-recommended',
24+
'plugin:@typescript-eslint/recommended',
25+
],
26+
plugins: ['prettier', '@typescript-eslint'],
27+
rules: {
28+
'prettier/prettier': [
29+
'error',
30+
{
31+
singleQuote: true,
32+
semi: true,
33+
useTabs: false,
34+
tabWidth: 2,
35+
printWidth: 80,
36+
bracketSpacing: true,
37+
arrowParens: 'avoid',
38+
},
39+
],
40+
},
41+
parserOptions: {
42+
parser: '@typescript-eslint/parser',
43+
},
44+
};
45+
```
46+
47+
5. ESLint 이그노어 파일 추가
48+
49+
```
50+
// .eslintignore
51+
node_modules
52+
```
53+
54+
## VSCode ESLint 플러그인 관련 설정
55+
56+
1. VSCode의 [ESLint 플러그인](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) 설치
57+
2. VSCode에서 `ctrl` + `shift` + `p` / `cmd` + `shift` + `p` 키를 이용하여 명령어 실행 창 표시
58+
3. 명령어 실행 창에 `open settings (json)` 입력 후 선택
59+
60+
![find-user-settings-on-command-palette](./command-palette.png)
61+
62+
4. VSCode 사용자 정의 파일인 `settings.json` 파일의 내용에 아래와 같이 ESLint 플러그인 관련 설정 추가.
63+
64+
```js
65+
{
66+
// ... <-- 기존 내용을 꼭 유지한 상태에서 아래 내용을 추가하고 이 주석은 제거할 것
67+
"editor.codeActionsOnSave": {
68+
"source.fixAll.eslint": true
69+
},
70+
"eslint.alwaysShowStatus": true,
71+
"eslint.workingDirectories": [
72+
{"mode": "auto"}
73+
],
74+
"eslint.validate": [
75+
"javascript",
76+
"typescript"
77+
],
78+
}
79+
```
80+
81+
5. `ctrl` + `,` 또는 `cmd` + `,` 눌러서 VSCode 설정 파일(Settings)에 들어간 후 `format on save` 검색. 아래와 같이 체크가 안되어 있는지 확인.
82+
83+
![format-on-save-off](./format-on-save-off.png)

setup/command-palette.png

37.3 KB
Loading

setup/format-on-save-off.png

83 KB
Loading

0 commit comments

Comments
 (0)