From 6b87a377e695c219c69ab9d6c81ff9ba65cb4dac Mon Sep 17 00:00:00 2001 From: ambar Date: Sat, 27 Apr 2024 09:46:50 +0800 Subject: [PATCH] style: lint:fix --- biome.json | 9 ++++++++- example/values.ts | 2 +- package.json | 12 +++--------- scripts/build-extension.mjs | 4 ++-- scripts/build-preview.mjs | 8 ++++---- scripts/copy.mjs | 4 ++-- src/extension.ts | 14 +++++++------- src/extension/__tests__/bundle.spec.ts | 2 +- src/extension/bundle.ts | 12 ++++++------ src/extension/getWebviewContent.ts | 2 +- src/preview.tsx | 22 +++++++++++----------- src/preview/Inspector.tsx | 3 ++- src/preview/console.tsx | 3 ++- src/preview/darkMode.tsx | 3 ++- src/preview/webview-ui-toolkit.d.ts | 4 ++-- src/sandbox/__tests__/nodeVM.spec.ts | 12 +++++++----- src/sandbox/nodeVM.ts | 2 +- src/sandbox/transform.ts | 6 +++--- 18 files changed, 65 insertions(+), 59 deletions(-) diff --git a/biome.json b/biome.json index c8143f9..aa678da 100644 --- a/biome.json +++ b/biome.json @@ -1,3 +1,10 @@ { - "extends": ["@recommended/biome-config"] + "$schema": "https://biomejs.dev/schemas/1.7.1/schema.json", + "extends": ["@recommended/biome-config"], + "javascript": { + "formatter": { + "trailingComma": "es5", + "arrowParentheses": "always" + } + } } diff --git a/example/values.ts b/example/values.ts index ba1cf17..d8c4f62 100644 --- a/example/values.ts +++ b/example/values.ts @@ -1,5 +1,5 @@ // Circular -let obj: Record = {a: 1, obj: null} +const obj: Record = {a: 1, obj: null} obj.obj = obj obj diff --git a/package.json b/package.json index fd536eb..495becf 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,7 @@ "engines": { "vscode": "^1.61.0" }, - "categories": [ - "Programming Languages" - ], + "categories": ["Programming Languages"], "activationEvents": [ "onLanguage:javascript", "onLanguage:javascriptreact", @@ -145,12 +143,8 @@ }, "jest": { "preset": "es-jest", - "transformIgnorePatterns": [ - "/node_modules/(?!(node-fetch-cache)/)" - ], - "collectCoverageFrom": [ - "src/**/*" - ] + "transformIgnorePatterns": ["/node_modules/(?!(node-fetch-cache)/)"], + "collectCoverageFrom": ["src/**/*"] }, "dependencies": { "esbuild": "^0.20.2" diff --git a/scripts/build-extension.mjs b/scripts/build-extension.mjs index dcc9d99..f68b551 100644 --- a/scripts/build-extension.mjs +++ b/scripts/build-extension.mjs @@ -1,8 +1,8 @@ -/* eslint-disable no-console */ -import minimist from 'minimist' import {execSync} from 'child_process' import {builtinModules} from 'module' import * as esbuild from 'esbuild' +/* eslint-disable no-console */ +import minimist from 'minimist' import watchLogPlugin from './watchLogPlugin.mjs' const args = minimist(process.argv.slice(2), { diff --git a/scripts/build-preview.mjs b/scripts/build-preview.mjs index 3dddaf2..f7fa39f 100644 --- a/scripts/build-preview.mjs +++ b/scripts/build-preview.mjs @@ -1,9 +1,9 @@ -/* eslint-disable no-console */ -import minimist from 'minimist' +import {execSync} from 'child_process' import NodeModulesPolyfills from '@esbuild-plugins/node-modules-polyfill' -import {fetchBuilder, FileSystemCache} from 'node-fetch-cache' import * as esbuild from 'esbuild' -import {execSync} from 'child_process' +/* eslint-disable no-console */ +import minimist from 'minimist' +import {FileSystemCache, fetchBuilder} from 'node-fetch-cache' import httpPlugin from './httpPlugin.mjs' import watchLogPlugin from './watchLogPlugin.mjs' diff --git a/scripts/copy.mjs b/scripts/copy.mjs index 7b34192..18604de 100644 --- a/scripts/copy.mjs +++ b/scripts/copy.mjs @@ -1,6 +1,6 @@ -import fg from 'fast-glob' -import path from 'path' import {promises as fs} from 'fs' +import path from 'path' +import fg from 'fast-glob' const config = [ // { diff --git a/src/extension.ts b/src/extension.ts index ddc0691..9f1654e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,16 +2,16 @@ import path from 'path' import * as prettyFormat from 'pretty-format' import * as vscode from 'vscode' -import type {Runtime, AnyFunction, BuildPlatform} from './types' +import type {Worker} from 'worker_threads' import bundle from './extension/bundle' -import {install} from './extension/install' import getWebviewContent from './extension/getWebviewContent' -import transform from './sandbox/transform' +import {install} from './extension/install' import * as nodeVM from './sandbox/nodeVM' +import transform from './sandbox/transform' import type {ExpContext} from './sandbox/types' -import timeMark from './utils/timeMark' +import type {AnyFunction, BuildPlatform, Runtime} from './types' import {of} from './utils/promise' -import type {Worker} from 'worker_threads' +import timeMark from './utils/timeMark' const NAME = 'Live Code' const output = vscode.window.createOutputChannel(NAME) @@ -331,13 +331,13 @@ async function processDocumentPanel( function debounce>(fn: T, wait: number) { let timer: number | undefined - return function () { + return (() => { if (timer) { clearTimeout(timer) } // eslint-disable-next-line prefer-rest-params timer = setTimeout(fn.apply.bind(fn, void 0, arguments), wait) - } as T + }) as T } function setPanelTitleAndIcon( diff --git a/src/extension/__tests__/bundle.spec.ts b/src/extension/__tests__/bundle.spec.ts index 8d3784e..d845ab1 100644 --- a/src/extension/__tests__/bundle.spec.ts +++ b/src/extension/__tests__/bundle.spec.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ -import bundle, {BundleOpts} from '../bundle' +import bundle, {type BundleOpts} from '../bundle' describe('browser', () => { const opts: BundleOpts = { diff --git a/src/extension/bundle.ts b/src/extension/bundle.ts index 3d80b18..0220897 100644 --- a/src/extension/bundle.ts +++ b/src/extension/bundle.ts @@ -1,7 +1,7 @@ import path from 'path' import type * as Esbuild from 'esbuild' -import {fetchBuilder, MemoryCache} from 'node-fetch-cache' import {nodeExternalsPlugin} from 'esbuild-node-externals' +import {MemoryCache, fetchBuilder} from 'node-fetch-cache' // @ts-expect-error ESM import httpPlugin from '../../scripts/httpPlugin.mjs' @@ -107,11 +107,11 @@ export default async function bundle( nodeExternalsPlugin(), ] : isWeb - ? [ - // - externalGlobalPlugin({react: 'React', 'react-dom': 'ReactDOM'}), - ] - : [], + ? [ + // + externalGlobalPlugin({react: 'React', 'react-dom': 'ReactDOM'}), + ] + : [], }) const outputs = result.outputFiles const js = outputs.find((x) => x.path.endsWith('.js'))?.text diff --git a/src/extension/getWebviewContent.ts b/src/extension/getWebviewContent.ts index 10fbd4f..b414ef0 100644 --- a/src/extension/getWebviewContent.ts +++ b/src/extension/getWebviewContent.ts @@ -1,4 +1,4 @@ -import {AppConfig} from '../types' +import type {AppConfig} from '../types' export default function getWebviewContent(appConfig: AppConfig) { return ` diff --git a/src/preview.tsx b/src/preview.tsx index 2db6597..746f599 100644 --- a/src/preview.tsx +++ b/src/preview.tsx @@ -1,21 +1,21 @@ /** @jsx jsx */ import {jsx} from '@emotion/react' +import isPromise from 'is-promise' +import * as prettyFormat from 'pretty-format' import React, {useState, useMemo, useEffect, useCallback} from 'react' import {render} from 'react-dom' -import * as prettyFormat from 'pretty-format' -import isPromise from 'is-promise' -// import {VSCodeProgressRing} from '@vscode/webview-ui-toolkit/react' -import type {EvaluationResult, ExpContext} from './sandbox/types' -import {runInNewContext, CallbackParams} from './sandbox/browserVM' -import injectImportMap from './sandbox/injectImportMap' -import injectCSS from './sandbox/injectCSS' -import {IsDarkModeProvider, useIsDarkMode} from './preview/darkMode' import ErrorBoundary from './preview/ErrorBoundary' import Inspector from './preview/Inspector' -import {StyledConsole, Hook, Unhook, Message} from './preview/console' -import {AppConfig, AnyFunction, Runtime} from './types' -import timeMark from './utils/timeMark' +import {Hook, type Message, StyledConsole, Unhook} from './preview/console' +import {IsDarkModeProvider, useIsDarkMode} from './preview/darkMode' +import {type CallbackParams, runInNewContext} from './sandbox/browserVM' +import injectCSS from './sandbox/injectCSS' +import injectImportMap from './sandbox/injectImportMap' +// import {VSCodeProgressRing} from '@vscode/webview-ui-toolkit/react' +import type {EvaluationResult, ExpContext} from './sandbox/types' +import type {AnyFunction, AppConfig, Runtime} from './types' import {of} from './utils/promise' +import timeMark from './utils/timeMark' // https://code.visualstudio.com/api/extension-guides/webview#persistence const vscode = acquireVsCodeApi() diff --git a/src/preview/Inspector.tsx b/src/preview/Inspector.tsx index e62963e..cfa8d7f 100644 --- a/src/preview/Inspector.tsx +++ b/src/preview/Inspector.tsx @@ -1,4 +1,5 @@ -import React, {useState, useEffect} from 'react' +import type React from 'react' +import {useEffect, useState} from 'react' import * as ri from 'react-inspector' import {useIsDarkMode} from './darkMode' diff --git a/src/preview/console.tsx b/src/preview/console.tsx index 53d0440..b4bb9a7 100644 --- a/src/preview/console.tsx +++ b/src/preview/console.tsx @@ -1,7 +1,8 @@ /** @jsx jsx */ import {jsx} from '@emotion/react' -import React, {useMemo} from 'react' import {Console, Decode} from 'console-feed' +import type React from 'react' +import {useMemo} from 'react' import {baseInspectorStyles} from './Inspector' import {useIsDarkMode} from './darkMode' diff --git a/src/preview/darkMode.tsx b/src/preview/darkMode.tsx index a3b1b63..a34106e 100644 --- a/src/preview/darkMode.tsx +++ b/src/preview/darkMode.tsx @@ -1,4 +1,5 @@ -import React, {useState, useEffect, createContext, useContext} from 'react' +import type React from 'react' +import {createContext, useContext, useEffect, useState} from 'react' // https://github.com/microsoft/vscode/issues/7589#issuecomment-226129243 const getIsDarkMode = () => document.body.classList.contains('vscode-dark') diff --git a/src/preview/webview-ui-toolkit.d.ts b/src/preview/webview-ui-toolkit.d.ts index a213d63..a6dfe79 100644 --- a/src/preview/webview-ui-toolkit.d.ts +++ b/src/preview/webview-ui-toolkit.d.ts @@ -1,9 +1,9 @@ -import React from 'react' +import type React from 'react' // https://github.com/microsoft/vscode-webview-ui-toolkit type VSCodeElement< T = HTMLElement, - P = React.HTMLAttributes + P = React.HTMLAttributes, > = React.DetailedHTMLProps, T> declare global { diff --git a/src/sandbox/__tests__/nodeVM.spec.ts b/src/sandbox/__tests__/nodeVM.spec.ts index ffdc0b6..f5eac08 100644 --- a/src/sandbox/__tests__/nodeVM.spec.ts +++ b/src/sandbox/__tests__/nodeVM.spec.ts @@ -1,4 +1,4 @@ -import {Message} from 'console-feed/lib/definitions/Console' +import type {Message} from 'console-feed/lib/definitions/Console' import {create} from '../../utils/promise' import * as nodeVM from '../nodeVM' import transform from '../transform' @@ -8,8 +8,9 @@ const opts = { } test('empty', async () => { - expect(await nodeVM.runInNewContext(transform(``), opts)) - .toMatchInlineSnapshot(` + expect( + await nodeVM.runInNewContext(transform(``), opts) + ).toMatchInlineSnapshot(` { "logs": [], "result": [], @@ -18,8 +19,9 @@ test('empty', async () => { }) test('expression', async () => { - expect(await nodeVM.runInNewContext(transform(`0`), opts)) - .toMatchInlineSnapshot(` + expect( + await nodeVM.runInNewContext(transform(`0`), opts) + ).toMatchInlineSnapshot(` { "logs": [], "result": [ diff --git a/src/sandbox/nodeVM.ts b/src/sandbox/nodeVM.ts index d4dbec5..32249b6 100644 --- a/src/sandbox/nodeVM.ts +++ b/src/sandbox/nodeVM.ts @@ -1,6 +1,6 @@ import path from 'path' -import type {ExpContext} from './types' import {Worker} from 'worker_threads' +import type {ExpContext} from './types' const workerPath = path.resolve(__dirname, 'nodeWorker.js') diff --git a/src/sandbox/transform.ts b/src/sandbox/transform.ts index a3938ba..cbad644 100644 --- a/src/sandbox/transform.ts +++ b/src/sandbox/transform.ts @@ -1,7 +1,7 @@ -import * as recast from 'recast' -import {types} from 'recast' -import getBabelOptions, {Overrides} from 'recast/parsers/_babel_options' import {parse as babelParse} from '@babel/parser' +import * as recast from 'recast' +import type {types} from 'recast' +import getBabelOptions, {type Overrides} from 'recast/parsers/_babel_options' function parse(source: string, options?: Overrides) { const babelOptions = getBabelOptions(options)