Skip to content

Commit

Permalink
chore: always require curly braces (#5885)
Browse files Browse the repository at this point in the history
Co-authored-by: Ari Perkkiö <ari.perkkio@gmail.com>
  • Loading branch information
sheremet-va and AriPerkkio committed Jun 16, 2024
1 parent 66e648f commit 471cf97
Show file tree
Hide file tree
Showing 386 changed files with 13,939 additions and 6,956 deletions.
12 changes: 8 additions & 4 deletions docs/.vitepress/contributors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@ export const contributors = (contributorNames).reduce<Contributor[]>((acc, name)

function createLinks(tm: CoreTeam): CoreTeam {
tm.links = [{ icon: 'github', link: `https://github.com/${tm.github}` }]
if (tm.mastodon)
if (tm.mastodon) {
tm.links.push({ icon: 'mastodon', link: tm.mastodon })
}

if (tm.discord)
if (tm.discord) {
tm.links.push({ icon: 'discord', link: tm.discord })
}

if (tm.youtube)
if (tm.youtube) {
tm.links.push({ icon: 'youtube', link: `https://www.youtube.com/@${tm.youtube}` })
}

if (tm.twitter)
if (tm.twitter) {
tm.links.push({ icon: 'x', link: `https://twitter.com/${tm.twitter}` })
}

return tm
}
Expand Down
12 changes: 8 additions & 4 deletions docs/.vitepress/scripts/cli-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ function resolveOptions(options: CLIOptions<any>, parentName?: string) {
}

function resolveCommand(name: string, config: CLIOption<any> | null): any {
if (!config)
if (!config) {
return null
}

let title = '`'
if (config.shorthand)
if (config.shorthand) {
title += `-${config.shorthand}, `
}
title += `--${config.alias || name}`
if ('argument' in config)
if ('argument' in config) {
title += ` ${config.argument}`
}
title += '`'
if ('subcommands' in config && config.subcommands)
if ('subcommands' in config && config.subcommands) {
return resolveOptions(config.subcommands, name)
}

return {
title,
Expand Down
9 changes: 6 additions & 3 deletions docs/.vitepress/scripts/fetch-avatars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const dirAvatars = resolve(docsDir, 'public/user-avatars/')
const dirSponsors = resolve(docsDir, 'public/sponsors/')

async function download(url: string, fileName: string) {
if (existsSync(fileName))
if (existsSync(fileName)) {
return
}
// eslint-disable-next-line no-console
console.log('downloading', fileName)
try {
Expand All @@ -20,15 +21,17 @@ async function download(url: string, fileName: string) {
}

async function fetchAvatars() {
if (!existsSync(dirAvatars))
if (!existsSync(dirAvatars)) {
await fsp.mkdir(dirAvatars, { recursive: true })
}

await Promise.all([...teamEmeritiMembers, ...teamMembers].map(c => c.github).map(name => download(`https://github.com/${name}.png?size=100`, join(dirAvatars, `${name}.png`))))
}

async function fetchSponsors() {
if (!existsSync(dirSponsors))
if (!existsSync(dirSponsors)) {
await fsp.mkdir(dirSponsors, { recursive: true })
}
await Promise.all([
download('https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg', join(dirSponsors, 'antfu.svg')),
download('https://cdn.jsdelivr.net/gh/patak-dev/static/sponsors.svg', join(dirSponsors, 'patak-dev.svg')),
Expand Down
3 changes: 2 additions & 1 deletion docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import HomePage from '../components/HomePage.vue'
import Version from '../components/Version.vue'
import '@shikijs/vitepress-twoslash/style.css'

if (inBrowser)
if (inBrowser) {
import('./pwa')
}

export default {
...Theme,
Expand Down
3 changes: 2 additions & 1 deletion docs/api/expect-typeof.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,9 @@ This matcher extracts assert value (e.g., `assert v is number`), so you can perf
import { expectTypeOf } from 'vitest'

function assertNumber(v: any): asserts v is number {
if (typeof v !== 'number')
if (typeof v !== 'number') {
throw new TypeError('Nope !')
}
}

expectTypeOf(assertNumber).asserts.toBeNumber()
Expand Down
29 changes: 18 additions & 11 deletions docs/api/expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ Opposite of `toBeDefined`, `toBeUndefined` asserts that the value _is_ equal to
import { expect, test } from 'vitest'

function getApplesFromStock(stock: string) {
if (stock === 'Bill')
if (stock === 'Bill') {
return 13
}
}

test('mary doesn\'t have a stock', () => {
Expand All @@ -214,8 +215,9 @@ import { Stocks } from './stocks.js'

const stocks = new Stocks()
stocks.sync('Bill')
if (stocks.getInfo('Bill'))
if (stocks.getInfo('Bill')) {
stocks.sell('apples', 'Bill')
}
```

So if you want to test that `stocks.getInfo` will be truthy, you could write:
Expand Down Expand Up @@ -247,8 +249,9 @@ import { Stocks } from './stocks.js'

const stocks = new Stocks()
stocks.sync('Bill')
if (!stocks.stockFailed('Bill'))
if (!stocks.stockFailed('Bill')) {
stocks.sell('apples', 'Bill')
}
```

So if you want to test that `stocks.stockFailed` will be falsy, you could write:
Expand Down Expand Up @@ -660,8 +663,9 @@ For example, if we want to test that `getFruitStock('pineapples')` throws, we co
import { expect, test } from 'vitest'

function getFruitStock(type: string) {
if (type === 'pineapples')
if (type === 'pineapples') {
throw new Error('Pineapples are not in stock')
}

// Do some other stuff
}
Expand Down Expand Up @@ -1203,8 +1207,9 @@ For example, if you have a function that fails when you call it, you may use thi
import { expect, test } from 'vitest'

async function buyApples(id) {
if (!id)
if (!id) {
throw new Error('no id')
}
}

test('buyApples throws an error when no id provided', async () => {
Expand Down Expand Up @@ -1301,8 +1306,9 @@ For example, if we want to test that `build()` throws due to receiving directori
import { expect, test } from 'vitest'

async function build(dir) {
if (dir.includes('no-src'))
if (dir.includes('no-src')) {
throw new Error(`${dir}/src does not exist`)
}
}

const errorDirs = [
Expand Down Expand Up @@ -1594,14 +1600,15 @@ function areAnagramsEqual(a: unknown, b: unknown): boolean | undefined {
const isAAnagramComparator = isAnagramComparator(a)
const isBAnagramComparator = isAnagramComparator(b)

if (isAAnagramComparator && isBAnagramComparator)
if (isAAnagramComparator && isBAnagramComparator) {
return a.equals(b)

else if (isAAnagramComparator === isBAnagramComparator)
}
else if (isAAnagramComparator === isBAnagramComparator) {
return undefined

else
}
else {
return false
}
}

expect.addEqualityTesters([areAnagramsEqual])
Expand Down
5 changes: 3 additions & 2 deletions docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,9 @@ You can also nest describe blocks if you have a hierarchy of tests or benchmarks
import { describe, expect, test } from 'vitest'

function numberToCurrency(value: number | string) {
if (typeof value !== 'number')
throw new Error('Value must be a number')
if (typeof value !== 'number') {
throw new TypeError('Value must be a number')
}

return value.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}
Expand Down
6 changes: 4 additions & 2 deletions docs/api/vi.md
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,9 @@ let i = 0
setTimeout(() => console.log(++i))
const interval = setInterval(() => {
console.log(++i)
if (i === 3)
if (i === 3) {
clearInterval(interval)
}
}, 50)

vi.runAllTimers()
Expand Down Expand Up @@ -818,8 +819,9 @@ test('Server started successfully', async () => {

await vi.waitFor(
() => {
if (!server.isReady)
if (!server.isReady) {
throw new Error('Server not started')
}

console.log('Server started')
},
Expand Down
6 changes: 4 additions & 2 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2131,12 +2131,14 @@ export default defineConfig({
test: {
onStackTrace(error: Error, { file }: ParsedStack): boolean | void {
// If we've encountered a ReferenceError, show the whole stack.
if (error.name === 'ReferenceError')
if (error.name === 'ReferenceError') {
return
}

// Reject all frames from third party libraries.
if (file.includes('node_modules'))
if (file.includes('node_modules')) {
return false
}
},
},
})
Expand Down
6 changes: 4 additions & 2 deletions docs/guide/mocking.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ function purchase() {
const currentHour = new Date().getHours()
const [open, close] = businessHours

if (currentHour > open && currentHour < close)
if (currentHour > open && currentHour < close) {
return { message: 'Success' }
}

return { message: 'Error' }
}
Expand Down Expand Up @@ -194,8 +195,9 @@ export default {
{
name: 'virtual-modules',
resolveId(id) {
if (id === '$app/forms')
if (id === '$app/forms') {
return 'virtual:$app/forms'
}
}
}
]
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default antfu(
'no-undef': 'off',
'ts/no-invalid-this': 'off',
'eslint-comments/no-unlimited-disable': 'off',
'curly': ['error', 'all'],

// TODO: migrate and turn it back on
'ts/ban-types': 'off',
Expand Down
3 changes: 2 additions & 1 deletion examples/sveltekit/src/lib/add.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { dev } from '$app/environment'

export function add(a: number, b: number) {
if (dev)
if (dev) {
console.warn(`Adding ${a} and ${b}`)
}

return a + b
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"lint-staged": "^15.2.5",
"magic-string": "^0.30.10",
"pathe": "^1.1.2",
"prettier": "^2.8.8",
"rimraf": "^5.0.7",
"rollup": "^4.18.0",
"rollup-plugin-dts": "^6.1.1",
Expand Down
33 changes: 26 additions & 7 deletions packages/browser/context.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,24 @@ export interface FsOptions {
flag?: string | number
}

export interface TypePayload { type: string }
export interface PressPayload { press: string }
export interface DownPayload { down: string }
export interface UpPayload { up: string }
export interface TypePayload {
type: string
}
export interface PressPayload {
press: string
}
export interface DownPayload {
down: string
}
export interface UpPayload {
up: string
}

export type SendKeysPayload = TypePayload | PressPayload | DownPayload | UpPayload
export type SendKeysPayload =
| TypePayload
| PressPayload
| DownPayload
| UpPayload

export interface ScreenshotOptions {
element?: Element
Expand All @@ -35,8 +47,15 @@ export interface ScreenshotOptions {
}

export interface BrowserCommands {
readFile: (path: string, options?: BufferEncoding | FsOptions) => Promise<string>
writeFile: (path: string, content: string, options?: BufferEncoding | FsOptions & { mode?: number | string }) => Promise<void>
readFile: (
path: string,
options?: BufferEncoding | FsOptions
) => Promise<string>
writeFile: (
path: string,
content: string,
options?: BufferEncoding | (FsOptions & { mode?: number | string })
) => Promise<void>
removeFile: (path: string) => Promise<void>
sendKeys: (payload: SendKeysPayload) => Promise<void>
}
Expand Down
5 changes: 4 additions & 1 deletion packages/browser/providers/playwright.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import type {
declare module 'vitest/node' {
interface BrowserProviderOptions {
launch?: LaunchOptions
context?: Omit<BrowserContextOptions, 'ignoreHTTPSErrors' | 'serviceWorkers'>
context?: Omit<
BrowserContextOptions,
'ignoreHTTPSErrors' | 'serviceWorkers'
>
}

export interface BrowserCommandContext {
Expand Down
Loading

0 comments on commit 471cf97

Please sign in to comment.