在 Next 13.0 使用 ESLint 分析工具並套用 Airbnb 程式碼風格

做法

安裝 eslint 依賴套件。

1
2
3
4
npm i eslint \
eslint-config-next \
eslint-config-airbnb \
-D

修改 .eslintrc.js 檔,並添加相關規則。

1
2
3
4
5
6
7
8
9
10
11
12
module.exports = {
extends: [
'next/core-web-vitals',
'airbnb',
],
globals: {
React: 'readonly',
},
rules: {
'react/jsx-filename-extension': ['error', { extensions: ['.js', '.jsx', '.ts', '.tsx'] }],
},
};

執行檢查。

1
npm run lint