Skip to content

Commit 9ca6996

Browse files
authored
Merge pull request #763 from NoiseFan/ci/lint_fix
ci(lint): Add code formatting tools
1 parent aa0b8d9 commit 9ca6996

File tree

8 files changed

+319
-162
lines changed

8 files changed

+319
-162
lines changed

.github/workflows/autofix.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: autofix.ci
2+
3+
on:
4+
pull_request:
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
autofix:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 10
12+
13+
steps:
14+
- uses: actions/checkout@v5
15+
16+
- name: Use Node.js lts/*
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: lts/*
20+
21+
- name: Setup
22+
run: npm i -g @antfu/ni
23+
24+
- name: Install
25+
run: nci
26+
27+
- name: Lint
28+
run: nr lint --fix
29+
30+
- uses: autofix-ci/action@635ffb0c9798bd160680f18fd73371e355b85f27

advanced/runner.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface VitestRunner {
3131
* 这是在实际运行测试函数之前被调用的。
3232
* 此时已经有了带有 "state" 和 "startTime" 属性的 "result" 对象。
3333
*/
34-
onBeforeTryTask?: (test: Test, options: { retry: number; repeats: number }) => unknown
34+
onBeforeTryTask?: (test: Test, options: { retry: number, repeats: number }) => unknown
3535
/**
3636
* 这是在结果和状态都被设置之后被调用的。
3737
*/
@@ -40,12 +40,12 @@ export interface VitestRunner {
4040
* 这是在运行测试函数后立即被调用的。此时还没有新的状态。
4141
* 如果测试函数抛出异常,将不会调用此方法。
4242
*/
43-
onAfterTryTask?: (test: Test, options: { retry: number; repeats: number }) => unknown
43+
onAfterTryTask?: (test: Test, options: { retry: number, repeats: number }) => unknown
4444
/**
4545
* 在重试结果确定后调用。与 `onAfterTryTask` 不同,此时测试已进入新的状态,
4646
* 并且所有的 `after` 钩子此时也已被执行。
4747
*/
48-
onAfterRetryTask?: (test: Test, options: { retry: number; repeats: number }) => unknown
48+
onAfterRetryTask?: (test: Test, options: { retry: number, repeats: number }) => unknown
4949

5050
/**
5151
* 这是在运行单个测试套件之前被调用的,此时还没有测试结果。

api/expect-typeof.md

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const user = {
7575
name: 'John',
7676
address: { city: 'New York', zip: '10001' }
7777
}
78-
expectTypeOf(user).toMatchObjectType<{ name: string; address: { city: string } }>()
78+
expectTypeOf(user).toMatchObjectType<{ name: string, address: { city: string } }>()
7979
```
8080

8181
::: warning
@@ -91,12 +91,9 @@ This matcher only works with plain object types. It will fail for union types an
9191
```ts
9292
import { expectTypeOf } from 'vitest'
9393

94-
type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }
94+
type ResponsiveProp<T> = T | T[] | { xs?: T, sm?: T, md?: T }
9595

96-
interface CSSProperties {
97-
margin?: string
98-
padding?: string
99-
}
96+
interface CSSProperties { margin?: string, padding?: string }
10097

10198
function getResponsiveProp<T>(_props: T): ResponsiveProp<T> {
10299
return {}
@@ -106,11 +103,7 @@ const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }
106103

107104
expectTypeOf(getResponsiveProp(cssProperties))
108105
.extract<{ xs?: any }>() // extracts the last type from a union
109-
.toEqualTypeOf<{
110-
xs?: CSSProperties
111-
sm?: CSSProperties
112-
md?: CSSProperties
113-
}>()
106+
.toEqualTypeOf<{ xs?: CSSProperties, sm?: CSSProperties, md?: CSSProperties }>()
114107

115108
expectTypeOf(getResponsiveProp(cssProperties))
116109
.extract<unknown[]>() // extracts an array from a union
@@ -130,21 +123,20 @@ expectTypeOf(getResponsiveProp(cssProperties))
130123
```ts
131124
import { expectTypeOf } from 'vitest'
132125

133-
type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }
126+
type ResponsiveProp<T> = T | T[] | { xs?: T, sm?: T, md?: T }
134127

135-
interface CSSProperties { margin?: string; padding?: string }
128+
interface CSSProperties { margin?: string, padding?: string }
136129

137-
function getResponsiveProp<T>(\_props: T): ResponsiveProp<T> {
138-
return {}
130+
function getResponsiveProp<T>(_props: T): ResponsiveProp<T> {
131+
return {}
139132
}
140133

141134
const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }
142135

143136
expectTypeOf(getResponsiveProp(cssProperties))
144-
.exclude<unknown[]>()
145-
.exclude<{ xs?: unknown }>() // or just .exclude<unknown[] | { xs?: unknown }>()
146-
.toEqualTypeOf<CSSProperties>()
147-
137+
.exclude<unknown[]>()
138+
.exclude<{ xs?: unknown }>() // or just .exclude<unknown[] | { xs?: unknown }>()
139+
.toEqualTypeOf<CSSProperties>()
148140
```
149141

150142
::: warning

api/expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ test('expect.soft test', () => {
105105

106106
```ts
107107
interface ExpectPoll extends ExpectStatic {
108-
(actual: () => T, options?: { interval?: number; timeout?: number; message?: string }): Promise<Assertions<T>>
108+
(actual: () => T, options?: { interval?: number, timeout?: number, message?: string }): Promise<Assertions<T>>
109109
}
110110
```
111111

api/vi.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,13 @@ test('importing the next module imports mocked one', async () => {
225225
### vi.mocked
226226

227227
```ts
228-
function mocked<T>(object: T, deep?: boolean): MaybeMockedDeep<T>
229228
function mocked<T>(
230229
object: T,
231-
options?: { partial?: boolean; deep?: boolean }
230+
deep?: boolean
231+
): MaybeMockedDeep<T>
232+
function mocked<T>(
233+
object: T,
234+
options?: { partial?: boolean, deep?: boolean }
232235
): MaybePartiallyMockedDeep<T>
233236
```
234237

eslint.config.js

Lines changed: 40 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,42 @@
11
import antfu, { GLOB_SRC } from '@antfu/eslint-config'
22

3-
export default antfu(
4-
{
5-
vue: true,
6-
// Disable tests rules because we need to test with various setup
7-
test: false,
8-
// This replaces the old `.gitignore`
9-
ignores: [
10-
'**/coverage',
11-
'**/*.snap',
12-
'**/bench.json',
13-
'**/fixtures',
14-
'**/assets/**',
15-
'**/*.d.ts',
16-
'**/*.timestamp-*',
17-
'test/core/src/self',
18-
'test/core/test/mocking/already-hoisted.test.ts',
19-
'test/cache/cache/.vitest-base/results.json',
20-
'test/core/src/wasm/wasm-bindgen-no-cyclic',
21-
'test/workspaces/results.json',
22-
'test/workspaces-browser/results.json',
23-
'test/reporters/fixtures/with-syntax-error.test.js',
24-
'test/network-imports/public/[email protected]',
25-
'test/coverage-test/src/transpiled.js',
26-
'test/coverage-test/src/original.ts',
27-
'test/cli/deps/error/*',
28-
'examples/**/mockServiceWorker.js',
29-
'examples/sveltekit/.svelte-kit',
30-
'packages/browser/**/esm-client-injector.js',
31-
// contains technically invalid code to display pretty diff
32-
'docs/guide/snapshot.md',
33-
// uses invalid js example
34-
'docs/advanced/api/import-example.md',
35-
'docs/guide/examples/*.md',
36-
],
37-
},
38-
{
39-
rules: {
40-
// prefer global Buffer to not initialize the whole module
41-
'node/prefer-global/buffer': 'off',
42-
'node/prefer-global/process': 'off',
43-
'no-empty-pattern': 'off',
44-
'antfu/indent-binary-ops': 'off',
45-
'unused-imports/no-unused-imports': 'error',
46-
'style/member-delimiter-style': [
47-
'error',
48-
{
49-
multiline: { delimiter: 'none' },
50-
singleline: { delimiter: 'semi' },
51-
},
52-
],
53-
// let TypeScript handle this
54-
'no-undef': 'off',
55-
'ts/no-invalid-this': 'off',
56-
'eslint-comments/no-unlimited-disable': 'off',
57-
'curly': ['error', 'all'],
58-
59-
// TODO: migrate and turn it back on
60-
'ts/ban-types': 'off',
61-
'ts/no-unsafe-function-type': 'off',
62-
63-
'no-restricted-imports': [
64-
'error',
65-
{
66-
paths: ['path'],
67-
},
68-
],
69-
70-
'import/no-named-as-default': 'off',
71-
},
72-
},
73-
{
74-
files: [`packages/*/*.{js,mjs,d.ts}`],
75-
rules: {
76-
'antfu/no-import-dist': 'off',
77-
},
78-
},
79-
{
80-
files: [`packages/${GLOB_SRC}`],
81-
rules: {
82-
'no-restricted-imports': [
83-
'error',
84-
{
85-
paths: ['vitest', 'path', 'vitest/node'],
86-
},
87-
],
88-
},
89-
},
90-
{
91-
// these files define vitest as peer dependency
92-
files: [`packages/{coverage-*,ui,browser,web-worker,browser-*}/${GLOB_SRC}`],
93-
rules: {
94-
'no-restricted-imports': [
95-
'error',
96-
{
97-
paths: ['path'],
98-
},
99-
],
100-
},
101-
},
102-
{
103-
files: [
104-
`docs/${GLOB_SRC}`,
105-
`**/*.md`,
106-
`**/*.md/${GLOB_SRC}`,
107-
],
108-
rules: {
109-
'perfectionist/sort-imports': 'off',
110-
'style/max-statements-per-line': 'off',
111-
'import/newline-after-import': 'off',
112-
'import/first': 'off',
113-
'unused-imports/no-unused-imports': 'off',
114-
'ts/method-signature-style': 'off',
115-
'no-self-compare': 'off',
116-
'import/no-mutable-exports': 'off',
117-
},
118-
},
119-
{
120-
files: [
121-
`docs/${GLOB_SRC}`,
122-
`packages/web-worker/${GLOB_SRC}`,
123-
`test/core/${GLOB_SRC}`,
124-
],
125-
rules: {
126-
'no-restricted-globals': 'off',
127-
},
128-
},
129-
{
130-
files: [
131-
`test/${GLOB_SRC}`,
132-
],
133-
rules: {
134-
'antfu/no-top-level-await': 'off',
135-
'unicorn/consistent-function-scoping': 'off',
136-
},
137-
},
138-
)
3+
export default antfu({
4+
stylistic: true,
5+
typescript: true,
6+
vue: true,
7+
jsonc: false,
8+
yaml: false,
9+
ignores: [
10+
'dist',
11+
'node_modules',
12+
'*.svelte',
13+
'*.snap',
14+
'*.d.ts',
15+
'coverage',
16+
'!.vitepress',
17+
// contains technically invalid code to display pretty diff
18+
'guide/snapshot.md',
19+
// uses invalid js example
20+
'advanced/api/import-example.md',
21+
'guide/examples/*.md',
22+
],
23+
rules: {
24+
'no-restricted-globals': 'off',
25+
'no-empty-pattern': 'off',
26+
},
27+
}, {
28+
files: [
29+
`**/*.md`,
30+
`**/*.md/${GLOB_SRC}`,
31+
],
32+
rules: {
33+
'perfectionist/sort-imports': 'off',
34+
'style/max-statements-per-line': 'off',
35+
'import/newline-after-import': 'off',
36+
'import/first': 'off',
37+
'unused-imports/no-unused-imports': 'off',
38+
'ts/method-signature-style': 'off',
39+
'no-self-compare': 'off',
40+
'import/no-mutable-exports': 'off',
41+
},
42+
})

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"prefetch": "tsx .vitepress/scripts/fetch-avatars.ts",
1515
"lint": "eslint .",
1616
"lint:fix": "eslint . --fix",
17-
"generate-pwa-icons": "pwa-assets-generator"
17+
"generate-pwa-icons": "pwa-assets-generator",
18+
"prepare": "simple-git-hooks"
1819
},
1920
"dependencies": {
2021
"@vueuse/core": "latest",
@@ -41,8 +42,10 @@
4142
"esno": "^4.8.0",
4243
"fs-extra": "^11.3.0",
4344
"https-localhost": "^4.7.1",
45+
"lint-staged": "^16.2.6",
4446
"ofetch": "^1.4.1",
4547
"pathe": "^2.0.3",
48+
"simple-git-hooks": "^2.13.1",
4649
"tinyglobby": "latest",
4750
"tsx": "^4.19.3",
4851
"typescript": "^5.8.2",
@@ -55,5 +58,11 @@
5558
"vitepress-plugin-tabs": "^0.7.3",
5659
"vitest": "^4.0.6",
5760
"workbox-window": "^7.3.0"
61+
},
62+
"simple-git-hooks": {
63+
"pre-commit": "pnpm lint-staged"
64+
},
65+
"lint-staged": {
66+
"*": "eslint --fix"
5867
}
5968
}

0 commit comments

Comments
 (0)