Skip to main content

Command Palette

Search for a command to run...

ESLint in VSCode

Updated
1 min read
S

I was the main web front-end engineer responsible for developing and maintaining the customer-facing platform for WisdomHall (品學堂) in 2024 Q3 Q4, code reviewed by CTO and a senior engineer. http://learning.wisdomhall.com.tw has total active 257k users, according to their Facebook post: https://www.facebook.com/share/p/1MnjbwZxCV/ My tech stack includes JavaScript, Vue 2, Nuxt 2, git, and Docker.

在 petKnow project ZY 設定了嚴格的 coding style, 我常常會因為多了一兩個 breakline 導致 eslint-plugin-prettier 報出錯誤無法繼續顯示跟工作。我查了一下自動讓 vscode making code to ESLint on save.

quote: https://www.masrinastudio.com/post/eslint-formatting-vscode-guide/

To use ESLint in VSCode, you’ll need to install the ESLint extension from the VSCode Marketplace. Once you’ve installed the extension, you’ll need to configure it to format your code on save.

  1. Open your VSCode settings by clicking on the gear icon in the bottom left corner of the editor, or by pressing Ctrl + ,.

  2. In the search bar at the top, type “editor.codeActionsOnSave”.

  3. Click on “Edit in settings.json”. This will open your VSCode settings.json file.

  4. Add the following lines to your settings.json file:

     "editor.codeActionsOnSave": { "source.fixAll.eslint": true},
     "eslint.alwaysShowStatus": true
    

Save your settings.json file and you’re done! This tells VSCode to run ESLint’s automatic code fixing whenever you save a file. The alwaysShowStatus option will show you the ESLint status for the current file in the status bar.

https://stackoverflow.com/questions/51012185/formatting-typescript-with-prettier-in-vscode
Add codes below to your setting.json file:

"[typescript]": { "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode" }

typescript auto-formatting:
https://stackoverflow.com/questions/55537574/format-tsx-files-on-save-in-vs-code

{
  "typescript.format.enable": false,
  "[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

my .eslintrc.js file
拿掉 "plugin:vue/vue3-essential", 這行, *.vue 裡面的 auto-formatting on save 就失效了。

.eslintrc.js

module.exports = {
  root: true,
  env: {
    node: true,
  },
  extends: [
    "plugin:vue/vue3-essential",
    "eslint:recommended",
    "@vue/eslint-config-typescript",
  ],
  rules: {
    "vue/multi-word-component-names": "off",
  },
};

More from this blog

Vue 3 的雞毛蒜皮各種小特性

在 Nuxt 3 專案中,這是一個被稱為「自動導入 (auto-imports)」的特性 我:為何 showPost 不用引用就可以直接使用? [id].vue: 1 lines selecteduseAsyncData Gemini: stat_minus_1Thinking 在 Nuxt 3 專案中,這是一個被稱為「自動導入 (auto-imports)」的特性。 Nuxt 會自動掃描特定目錄下的檔案,例如 composables/ 和 utils/,並將其中定義的函式、變數等在整個應用程...

Sep 25, 20251 min read

請用 10 歲小孩能懂的方式,解釋 Virtual DOM 觀念

當然可以!以下是一個 10 歲小孩也能懂的方式來解釋 Virtual DOM(虛擬 DOM) 是什麼: 🎨 想像你在畫畫一棵樹 你有一張畫紙(這是網頁上的畫面),你正在畫一棵樹 🌳。 有一天你想把樹的葉子從綠色換成黃色,因為是秋天了 🍂。 做法一: 你把整棵樹擦掉,重新畫一棵新的黃色葉子樹。🧽✏️ 這樣很花時間,而且很累對吧? 做法二(更聰明的做法): 你先在一張透明的描圖紙上畫一樣的樹,看看哪裡需要改,發現「只要把葉子塗黃就好!」然後你只改葉子的顏色,其他部分都不動,畫起來又快又省力...

Sep 22, 20252 min read

ChatGPT 用 10 歲孩童能聽懂的方法,解釋 webpage cookies 的原理跟用途

請用十歲孩童能聽懂的方法,解釋網頁 cookie 的原理跟用途 1. Cookie 是什麼? 想像你去一家餅乾店(網站),老闆給你一張小紙條,寫著你的名字和喜好(例如你喜歡巧克力餅乾)。這張小紙條就是「Cookie」。 但它不是可以吃的餅乾,而是電腦裡的一小段文字紀錄,網站會存到你的瀏覽器裡。 2. 它是怎麼運作的? 你第一次到網站 → 網站寫一張小紙條(Cookie)給你。 你下次再來 → 你把小紙條交給老闆(網站)。 老闆一看,就知道: 你是誰 你喜歡什麼 你上次逛到哪一頁 ...

Sep 17, 20251 min read

sunpochin

56 posts