ESLint Setting

記錄一些自己常用的 ESLint 設定

version:
eslint@8.47.0
eslint-config-next@13.4.13

Extends

next/core-web-vitals

為 init next 的 default 配置

More info: Core Web Vitals

Rules

semi

Require or disallow semicolons instead of ASI (automatic semicolon insertion)

取消每段 statement 末尾的分號

1
2
3
{
"semi": ["error", "never"]
}

member-delimiter-style

Require a specific member delimiter style for interfaces and type literals
取消 interface/type 末尾的分號

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"@typescript-eslint/member-delimiter-style": [
"error",
{
"multiline":
{
"delimiter": "none",
"requireLast": true
},
"singleline":
{
"delimiter": "none",
"requireLast": true
}
}
],
}

quotes

Enforce the consistent use of either backticks, double, or single quotes

使用單引號

1
2
3
{
"quotes": ["error", "single"]
}

object-curly-spacing

Enforce consistent spacing inside braces

大括號內的間距一致,包和物件中的物件和陣列

1
2
3
4
5
6
7
8
9
10
{
"object-curly-spacing": [
"error",
"always",
{
"arraysInObjects": true,
"objectsInObjects": true
}
]
}

block-spacing

Disallow or enforce spaces inside of blocks after opening block and before closing block

大括號後需要空格

1
2
3
{
"block-spacing": ["error", "always"]
}

Plugins

eslint-plugin-simple-import-sort

Easy autofixable import sorting

Add “simple-import-sort” to “plugins”

1
2
3
{
"plugins": ["simple-import-sort"]
}

Then add the rules for sorting imports and exports:

1
2
3
4
5
6
{
"rules": {
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error"
}
}

ESLint Setting
http://example.com/2023/08/13/ESLint-Setting/
Author
John Doe
Posted on
August 13, 2023
Licensed under