Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 6, 2024
1 parent 6774ec5 commit 12431a7
Show file tree
Hide file tree
Showing 31 changed files with 175 additions and 171 deletions.
6 changes: 3 additions & 3 deletions bench/compare.bench.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-disable import/first */
process.env.NODE_ENV = 'production'

import { fileURLToPath } from 'node:url'
import fs from 'node:fs/promises'
import { basename } from 'node:path'
import { bench, describe } from 'vitest'
import fg from 'fast-glob'
import { fileURLToPath } from 'node:url'
import { twoslasher as twoslasherOld } from '@typescript/twoslash'
import fg from 'fast-glob'
import { createTwoslasher } from 'twoslash'
import { bench, describe } from 'vitest'

const codes = await fg([
'examples/*.ts',
Expand Down
8 changes: 4 additions & 4 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { DefaultTheme } from 'vitepress'
import { defineConfig } from 'vitepress'
import { bundledThemes } from 'shiki'
import antfu from '@antfu/eslint-config'
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
import { bundledThemes } from 'shiki'
import { createTwoslasher as createTwoslasherESLint } from 'twoslash-eslint'
import antfu from '@antfu/eslint-config'
import { defineConfig } from 'vitepress'
import type { DefaultTheme } from 'vitepress'
import { version } from '../../package.json'
import vite from './vite.config'

Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// https://vitepress.dev/guide/custom-theme
import Theme from 'vitepress/theme'
import TwoslashFloatingVue from '@shikijs/vitepress-twoslash/client'
import Theme from 'vitepress/theme'
import type { EnhanceAppContext } from 'vitepress'

import '@shikijs/vitepress-twoslash/style.css'
Expand Down
10 changes: 5 additions & 5 deletions docs/.vitepress/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { fileURLToPath } from 'node:url'
import { resolve } from 'node:path'
import fs from 'node:fs/promises'
import { defineConfig } from 'vite'
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import JITI from 'jiti'
import { format } from 'pretty-format'
import UnoCSS from 'unocss/vite'
import Components from 'unplugin-vue-components/vite'
import { format } from 'pretty-format'
import JITI from 'jiti'
import { defineConfig } from 'vite'

export default defineConfig({
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/highlight.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ To get the beautiful result you see on this website, you can use [Shiki](https:/
It provides [`@shikijs/twoslash`](https://shiki.style/packages/twoslash) that integrates the type information into your code snippets.

```ts twoslash
import { codeToHtml } from 'shiki'
import { transformerTwoslash } from '@shikijs/twoslash' // [!code hl]
import { codeToHtml } from 'shiki'

const html = await codeToHtml(`console.log()`, {
lang: 'ts',
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"sass": "^1.78.0",
"unocss": "^0.62.3",
"vitepress": "^1.3.4",
"vue": "^3.5.2"
"vue": "^3.5.3"
}
}
4 changes: 2 additions & 2 deletions docs/packages/cdn.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ Fetching files from CDN is asynchronous, and there is no way to make the whole p
For example, in [Shiki](https://shiki.style/), the `codeToHtml` function is synchronous as well as the [`@shikijs/twoslash` transformer](https://shiki.style/packages/twoslash).

```ts
import { createTwoslashFromCDN } from 'twoslash-cdn'
import { createHighlighter } from 'shiki'
import { transformerTwoslash } from '@shikijs/twoslash'
import { createHighlighter } from 'shiki'
import { createTwoslashFromCDN } from 'twoslash-cdn'

const highlighter = await createHighlighter({})

Expand Down
2 changes: 1 addition & 1 deletion docs/packages/eslint.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ If you are using [`@shikijs/twoslash`](https://shiki.style/packages/twoslash) an

```ts twoslash
// @noErrors
import Shiki from '@shikijs/markdown-it'
import { transformerTwoslash } from '@shikijs/twoslash'
import { createTwoslasher as createTwoslasherESLint } from 'twoslash-eslint'
import Shiki from '@shikijs/markdown-it'

const shikiPlugin = await Shiki({
theme: 'vitesse-light',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"prepare": "simple-git-hooks"
},
"devDependencies": {
"@antfu/eslint-config": "^3.2.1",
"@antfu/eslint-config": "^3.3.2",
"@iconify-json/ri": "^1.2.0",
"@iconify-json/svg-spinners": "^1.2.0",
"@shikijs/markdown-it": "^1.16.2",
Expand Down Expand Up @@ -54,7 +54,7 @@
"vite": "^5.4.3",
"vite-tsconfig-paths": "^5.0.1",
"vitest": "^2.0.5",
"vue": "^3.5.2"
"vue": "^3.5.3"
},
"resolutions": {
"@types/node": "^22.5.4",
Expand Down
5 changes: 3 additions & 2 deletions packages/twoslash-cdn/playground/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import '@shikijs/twoslash/style-rich.css'
import { createTransformerFactory, rendererRich } from '@shikijs/twoslash/core'
import { codeToHtml } from 'shiki'
import { createTwoslashFromCDN } from 'twoslash-cdn'
import { createStorage } from 'unstorage'
import indexedDbDriver from 'unstorage/drivers/indexedb'
import { createTwoslashFromCDN } from 'twoslash-cdn'

import '@shikijs/twoslash/style-rich.css'

const storage = createStorage({
driver: indexedDbDriver({ base: 'twoslash-cdn:' }),
Expand Down
6 changes: 3 additions & 3 deletions packages/twoslash-cdn/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { TwoslashExecuteOptions, TwoslashFunction, TwoslashOptions, TwoslashReturn } from 'twoslash'
import { setupTypeAcquisition } from '@typescript/ata'
import { createDefaultMapFromCDN } from '@typescript/vfs'
import { createTwoslasher } from 'twoslash'
import ts from 'typescript'
import { createDefaultMapFromCDN } from '@typescript/vfs'
import { setupTypeAcquisition } from '@typescript/ata'
import type { TwoslashExecuteOptions, TwoslashFunction, TwoslashOptions, TwoslashReturn } from 'twoslash'

/**
* A subset of `unstorage`'s interface to maximize the compatibility
Expand Down
2 changes: 1 addition & 1 deletion packages/twoslash-eslint/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createPositionConverter, resolveNodePositions } from 'twoslash-protocol'
import { Linter } from 'eslint'
import { createPositionConverter, resolveNodePositions } from 'twoslash-protocol'
import type { NodeErrorWithoutPosition, TwoslashGenericFunction, TwoslashGenericResult } from 'twoslash-protocol'

export interface CreateTwoslashESLintOptions {
Expand Down
4 changes: 2 additions & 2 deletions packages/twoslash-eslint/test/fixtures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import { extname } from 'node:path'
import process from 'node:process'
import { expect, it } from 'vitest'
import type { TwoslashGenericResult } from 'twoslash-protocol'
import antfu from '@antfu/eslint-config'
import { expect, it } from 'vitest'
import type { Linter } from 'eslint'
import type { TwoslashGenericResult } from 'twoslash-protocol'
import { createTwoslasher } from '../src/index'

// To add a test, create a file in the fixtures folder and it will will run through
Expand Down
28 changes: 14 additions & 14 deletions packages/twoslash-vue/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
import type { Language, VueCompilerOptions } from '@vue/language-core'
import { FileMap, createLanguage, createVueLanguagePlugin, defaultMapperFactory, resolveVueCompilerOptions, setupGlobalTypes } from '@vue/language-core'
import type { CompilerOptions } from 'typescript'
import ts from 'typescript'
import type {
CompilerOptionDeclaration,
CreateTwoslashOptions,
HandbookOptions,
ParsedFlagNotation,
Range,
TwoslashExecuteOptions,
TwoslashInstance,
TwoslashReturnMeta,
} from 'twoslash'
import { createLanguage, createVueLanguagePlugin, defaultMapperFactory, FileMap, resolveVueCompilerOptions, setupGlobalTypes } from '@vue/language-core'
import {
createTwoslasher as createTwoslasherBase,
defaultCompilerOptions,
Expand All @@ -25,6 +12,19 @@ import {
removeCodeRanges,
resolveNodePositions,
} from 'twoslash-protocol'
import ts from 'typescript'
import type { Language, VueCompilerOptions } from '@vue/language-core'
import type {
CompilerOptionDeclaration,
CreateTwoslashOptions,
HandbookOptions,
ParsedFlagNotation,
Range,
TwoslashExecuteOptions,
TwoslashInstance,
TwoslashReturnMeta,
} from 'twoslash'
import type { CompilerOptions } from 'typescript'

export interface VueSpecificOptions {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, it } from 'vitest'
import { codeToHtml } from 'shiki'
import { createTransformerFactory, rendererRich } from '@shikijs/twoslash/core'
import { codeToHtml } from 'shiki'
import { expect, it } from 'vitest'
import { createTwoslasher } from '../src'

const code = await import('./fixtures/example.vue?raw').then(m => m.default)
Expand Down
2 changes: 1 addition & 1 deletion packages/twoslash/scripts/flag-keys.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs/promises'
import ts from 'typescript'
import type { CompilerOptionDeclaration } from '../src/types/options'
import { defaultHandbookOptions } from '../src/defaults'
import type { CompilerOptionDeclaration } from '../src/types/options'

async function generateFlagKeys() {
const tsOptionDeclarations = (ts as any).optionDeclarations as CompilerOptionDeclaration[]
Expand Down
11 changes: 7 additions & 4 deletions packages/twoslash/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import type { CompilerOptions, CompletionEntry, CompletionTriggerKind, DiagnosticCategory, JsxEmit } from 'typescript'
import { createFSBackedSystem, createSystem, createVirtualTypeScriptEnvironment } from '@typescript/vfs'
import type { ErrorLevel, NodeError, NodeWithoutPosition, Position, Range } from 'twoslash-protocol'
import { createPositionConverter, isInRange, isInRanges, removeCodeRanges, resolveNodePositions } from 'twoslash-protocol'

import type { ErrorLevel, NodeError, NodeWithoutPosition, Position, Range } from 'twoslash-protocol'
import type { CompilerOptions, CompletionEntry, CompletionTriggerKind, DiagnosticCategory, JsxEmit } from 'typescript'

import { defaultCompilerOptions, defaultHandbookOptions } from './defaults'
import { TwoslashError } from './error'
import { findCutNotations, findFlagNotations, findQueryMarkers, getExtension, getIdentifierTextSpans, getObjectHash, removeTsExtension, splitFiles, typesToExtension } from './utils'
import { validateCodeForErrors } from './validation'
import { defaultCompilerOptions, defaultHandbookOptions } from './defaults'

import type { CompilerOptionDeclaration, CreateTwoslashOptions, TwoslashExecuteOptions, TwoslashInstance, TwoslashOptions, TwoslashReturn, TwoslashReturnMeta, VirtualFile } from './types'
import { findCutNotations, findFlagNotations, findQueryMarkers, getExtension, getIdentifierTextSpans, getObjectHash, removeTsExtension, splitFiles, typesToExtension } from './utils'

export * from './public'

Expand Down
4 changes: 2 additions & 2 deletions packages/twoslash/src/fallback.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { removeCodeRanges } from 'twoslash-protocol'
import { flagKeys } from './flag-keys'
import { reAnnonateMarkers, reConfigBoolean, reConfigValue } from './regexp'
import type { TwoslashReturnMeta } from './types'
import { findCutNotations } from './utils'
import { flagKeys } from './flag-keys'
import type { TwoslashReturnMeta } from './types'

/**
* A fallback function to strip out twoslash annotations from a string and does nothing else.
Expand Down
4 changes: 2 additions & 2 deletions packages/twoslash/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import ts from 'typescript'
import type { TwoslashOptions } from './core'
import { createTwoslasher as _createTwoslasher, twoslasher as _twoslasher } from './core'
import { convertLegacyOptions, convertLegacyReturn } from './legacy'
import type { TwoslashOptions } from './core'
import type { TwoslashOptionsLegacy, TwoslashReturnLegacy } from './legacy'

export * from './public'
export * from './legacy'
export * from './public'

// eslint-disable-next-line node/prefer-global/process
const cwd = /* @__PURE__ */ typeof process !== 'undefined' && typeof process.cwd === 'function' ? process.cwd() : ''
Expand Down
2 changes: 1 addition & 1 deletion packages/twoslash/src/legacy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CompilerOptions } from 'typescript'
import type { ErrorLevel } from 'twoslash-protocol'
import type { CompilerOptions } from 'typescript'
import type { HandbookOptions, TwoslashExecuteOptions, TwoslashReturn } from './types'

export interface TwoslashOptionsLegacy extends TwoslashExecuteOptions {
Expand Down
10 changes: 5 additions & 5 deletions packages/twoslash/src/public.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// Public Utilities

export * from './defaults'
export * from './error'
export {
removeTwoslashNotations,
} from './fallback'

export * from './types'
export * from './defaults'

export {
findCutNotations,
Expand All @@ -11,10 +15,6 @@ export {
getObjectHash,
} from './utils'

export {
removeTwoslashNotations,
} from './fallback'

export {
validateCodeForErrors,
} from './validation'
2 changes: 1 addition & 1 deletion packages/twoslash/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './handbook-options'
export * from './instance'
export * from './options'
export * from './returns'
export * from './handbook-options'
export * from 'twoslash-protocol/types'
2 changes: 1 addition & 1 deletion packages/twoslash/src/types/instance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { VirtualTypeScriptEnvironment } from '@typescript/vfs'
import type { TwoslashReturn } from './returns'
import type { TwoslashExecuteOptions } from './options'
import type { TwoslashReturn } from './returns'

export type TwoslashFunction = (code: string, extension?: string, options?: TwoslashExecuteOptions) => TwoslashReturn

Expand Down
2 changes: 1 addition & 1 deletion packages/twoslash/src/types/options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { VirtualTypeScriptEnvironment } from '@typescript/vfs'
import type { CompilerOptions, CustomTransformers } from 'typescript'
import type { NodeWithoutPosition } from 'twoslash-protocol'
import type { CompilerOptions, CustomTransformers } from 'typescript'
import type { HandbookOptions } from './handbook-options'
import type { TwoslashReturnMeta } from './returns'

Expand Down
2 changes: 1 addition & 1 deletion packages/twoslash/src/types/returns.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CompilerOptions } from 'typescript'
import type { NodeCompletion, NodeError, NodeHighlight, NodeHover, NodeQuery, NodeTag, Range, TwoslashGenericResult } from 'twoslash-protocol'
import type { CompilerOptions } from 'typescript'
import type { HandbookOptions } from './handbook-options'

export interface TwoslashReturn extends TwoslashGenericResult {
Expand Down
8 changes: 4 additions & 4 deletions packages/twoslash/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { SourceFile } from 'typescript'
import { objectHash } from 'ohash'
import type { Range, createPositionConverter } from 'twoslash-protocol'
import { TwoslashError } from './error'
import type { CompilerOptionDeclaration, ParsedFlagNotation, TwoslashReturnMeta, VirtualFile } from './types'
import type { createPositionConverter, Range } from 'twoslash-protocol'
import type { SourceFile } from 'typescript'
import { defaultHandbookOptions } from './defaults'
import { TwoslashError } from './error'
import { reAnnonateMarkers, reConfigBoolean, reConfigValue, reCutAfter, reCutBefore, reCutEnd, reCutStart, reFilenamesMakers } from './regexp'
import type { CompilerOptionDeclaration, ParsedFlagNotation, TwoslashReturnMeta, VirtualFile } from './types'

export function getObjectHash(obj: any): string {
return objectHash(obj)
Expand Down
2 changes: 1 addition & 1 deletion packages/twoslash/test/custom_transformers.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Node, SourceFile, TransformationContext, TransformerFactory } from 'typescript'
import { isSourceFile, isStringLiteral, visitEachChild, visitNode } from 'typescript'
import { expect, it } from 'vitest'
import type { Node, SourceFile, TransformationContext, TransformerFactory } from 'typescript'
import { twoslasher } from '../src/index'

it('applies custom transformers', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/twoslash/test/fixtures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { extname } from 'node:path'
import process from 'node:process'
import { expect, it } from 'vitest'
import type { TwoslashReturn } from '../src/types'
import { createTwoslasher, removeTwoslashNotations } from '../src/index'
import type { TwoslashReturn } from '../src/types'

// To add a test, create a file in the fixtures folder and it will will run through
// as though it was the codeblock.
Expand Down
4 changes: 2 additions & 2 deletions packages/twoslash/test/new.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect, it } from 'vitest'
import ts from 'typescript'
import { expect, it } from 'vitest'
import { twoslasher } from '../src'
import { splitFiles } from '../src/utils'
import type { TwoslashReturn } from '../src/types'
import { twoslasher } from '../src'

export type TS = typeof import('typescript')

Expand Down
Loading

0 comments on commit 12431a7

Please sign in to comment.