# ESLint 和 StyleLint
# ESLint
電腦的全域中安裝
eslint套件npm i eslint -g1初始化 eslint 設定
eslint --init1可以選擇由
JavaScript,YAML或JSON格式作為 eslint 的設定檔,這邊以JavaScript作為範例module.exports = { env: { browser: true, es2021: true, node: true, }, extends: 'eslint:recommended', parserOptions: { ecmaVersion: 12, sourceType: 'module', }, plugins: ['html'], rules: { indent: ['error', 2], 'linebreak-style': ['error', 'windows'], quotes: ['error', 'single'], semi: ['error', 'always'], }, };1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19VSCode 的 Workspace Settings 中新增下方設定
{ "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, "eslint.validate": ["javascript", "html"] }1
2
3
4
5
6
# StyleLint
提醒
如果專案中需使用 SCSS,可以新增 stylelint-config-sass-guidelines (opens new window) 作為管理。
並將 .stylelintrc.json 中的 extends 屬性改為:
{
"extends": "stylelint-config-sass-guidelines"
}
1
2
3
2
3
在 VSCode 的 Workspace Settings 中新增下方設定:
{
"editor.codeActionsOnSave": {
"source.fixAll.stylelint": true
}
}
1
2
3
4
5
2
3
4
5
# Prettier 的並用
安裝 VSCode 的 Prettier 套件
VSCode 的 User Settings 中新增下方設定
只針對
html和markdown檔案在做儲存的時後會自動的排版。{ "prettier.singleQuote": true, "[html]": { "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true }, "[markdown]": { "editor.quickSuggestions": true, "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode" } }1
2
3
4
5
6
7
8
9
10
11
12