Skip to content

Commit

Permalink
docs: update twoslash
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Feb 13, 2024
1 parent 50b7dc1 commit 502d18a
Show file tree
Hide file tree
Showing 12 changed files with 567 additions and 493 deletions.
50 changes: 29 additions & 21 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import stylisticTs from '@stylistic/eslint-plugin-ts'
import stylisticJsx from '@stylistic/eslint-plugin-jsx'
import stylisticPlus from '@stylistic/eslint-plugin-plus'
import * as parserTs from '@typescript-eslint/parser'
import { createTwoslasher } from 'twoslash-eslint'
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
import { packages } from '../../packages/metadata/src'
import { transformerESLint } from './shiki-eslint'
import vite from './vite.config'

const mainPackages = packages.filter(p => p.rules.length)
Expand Down Expand Up @@ -166,27 +167,34 @@ export default defineConfig({
})
},
codeTransformers: [
transformerRenderWhitespace({ position: 'boundary' }),
transformerESLint({
eslintCodePreprocess: (code) => {
// Remove trailing newline and presentational `⏎` characters
return code.replace(/⏎(?=\n)/gu, '').replace(/⏎$/gu, '\n')
},
eslintConfig: [
{
files: ['**'],
plugins: {
'@stylistic': stylistic as ESLint.Plugin,
'@stylistic/js': stylisticJs as ESLint.Plugin,
'@stylistic/jsx': stylisticJsx as ESLint.Plugin,
'@stylistic/ts': stylisticTs as ESLint.Plugin,
'@stylistic/plus': stylisticPlus as ESLint.Plugin,
},
languageOptions: {
parser: parserTs as Linter.ParserModule,
},
transformerRenderWhitespace({
position: 'boundary',
}),
transformerTwoslash({
errorRendering: 'hover',
explicitTrigger: /\beslint-check\b/,
twoslasher: createTwoslasher({
eslintCodePreprocess: (code) => {
// Remove trailing newline and presentational `⏎` characters
return code.replace(/⏎(?=\n)/gu, '').replace(/⏎$/gu, '\n')
},
],
eslintConfig: [
{
files: ['**'],
plugins: {
'@stylistic': stylistic as ESLint.Plugin,
'@stylistic/js': stylisticJs as ESLint.Plugin,
'@stylistic/jsx': stylisticJsx as ESLint.Plugin,
'@stylistic/ts': stylisticTs as ESLint.Plugin,
'@stylistic/plus': stylisticPlus as ESLint.Plugin,
},
languageOptions: {
parser: parserTs as Linter.ParserModule,
},
},
],
}),

}),
],
},
Expand Down
87 changes: 0 additions & 87 deletions docs/.vitepress/shiki-eslint.ts

This file was deleted.

10 changes: 5 additions & 5 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
"fuse.js": "^7.0.0"
},
"devDependencies": {
"@shikijs/transformers": "^1.0.0-beta.6",
"@shikijs/transformers": "^1.1.2",
"@types/hast": "^3.0.4",
"@types/markdown-it-container": "^2.0.9",
"@unocss/reset": "^0.58.5",
"@vueuse/core": "^10.7.2",
"gray-matter": "^4.0.3",
"markdown-it-container": "^4.0.0",
"shiki": "^1.0.0-beta.6",
"twoslash": "^0.1.1",
"shiki": "^1.1.2",
"twoslash": "^0.2.2",
"unocss": "^0.58.5",
"unplugin-vue-components": "^0.26.0",
"vitepress": "^1.0.0-rc.41",
"vue": "^3.4.15"
"vitepress": "^1.0.0-rc.42",
"vue": "^3.4.19"
}
}
39 changes: 23 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"version": "1.6.1",
"private": true,
"packageManager": "pnpm@8.15.1",
"packageManager": "pnpm@8.15.2",
"license": "MIT",
"scripts": {
"build": "pnpm -r run build",
Expand All @@ -27,12 +27,12 @@
"@antfu/eslint-define-config": "1.23.0-2",
"@antfu/ni": "^0.21.12",
"@antfu/utils": "^0.7.7",
"@iconify-json/carbon": "^1.1.28",
"@iconify-json/carbon": "^1.1.30",
"@iconify-json/ri": "^1.1.19",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@shikijs/twoslash": "1.0.0-beta.6",
"@shikijs/vitepress-twoslash": "^1.0.0-beta.6",
"@shikijs/twoslash": "^1.1.2",
"@shikijs/vitepress-twoslash": "^1.1.2",
"@stylistic/eslint-plugin": "workspace:*",
"@stylistic/eslint-plugin-js": "workspace:*",
"@stylistic/eslint-plugin-migrate": "workspace:*",
Expand All @@ -43,10 +43,10 @@
"@types/estree": "^1.0.5",
"@types/fs-extra": "^11.0.4",
"@types/json-schema": "^7.0.15",
"@types/node": "^20.11.16",
"@types/semver": "^7.5.6",
"@typescript-eslint/parser": "^6.20.0",
"@typescript-eslint/utils": "^6.20.0",
"@types/node": "^20.11.17",
"@types/semver": "^7.5.7",
"@typescript-eslint/parser": "^6.21.0",
"@typescript-eslint/utils": "^6.21.0",
"@vitest/coverage-v8": "^1.2.2",
"bumpp": "^9.3.0",
"change-case": "^5.4.2",
Expand All @@ -60,24 +60,31 @@
"json-schema": "^0.4.0",
"json-schema-to-typescript": "^13.1.2",
"lint-staged": "^15.2.2",
"pnpm": "^8.15.1",
"pnpm": "^8.15.2",
"rimraf": "^5.0.5",
"rollup": "^4.9.6",
"rollup": "^4.10.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.1",
"semver": "^7.5.4",
"semver": "^7.6.0",
"shiki": "^1.1.2",
"simple-git-hooks": "^2.9.0",
"taze": "^0.13.2",
"taze": "^0.13.3",
"twoslash-eslint": "^0.2.2",
"typescript": "^5.3.3",
"unbuild": "^2.0.0",
"vite": "^5.0.12",
"vite": "^5.1.1",
"vitest": "^1.2.2",
"vue": "^3.4.15",
"vue": "^3.4.19",
"vue-tsc": "^1.8.27"
},
"pnpm": {
"patchedDependencies": {
"twoslash-eslint@0.2.2": "patches/twoslash-eslint@0.2.2.patch"
}
},
"resolutions": {
"rollup": "^4.9.6",
"vite": "^5.0.12"
"rollup": "^4.10.0",
"vite": "^5.1.1"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,6 @@
},
"devDependencies": {
"@eslint-community/eslint-utils": "^4.4.0",
"@typescript-eslint/parser": "^6.20.0"
"@typescript-eslint/parser": "^6.21.0"
}
}
6 changes: 3 additions & 3 deletions packages/eslint-plugin-jsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"dependencies": {
"@stylistic/eslint-plugin-js": "workspace:^",
"estraverse": "^5.3.0",
"picomatch": "^3.0.1"
"picomatch": "^4.0.1"
},
"devDependencies": {
"@babel/eslint-parser": "^7.23.10",
Expand All @@ -74,10 +74,10 @@
"@babel/plugin-syntax-function-bind": "^7.23.3",
"@babel/preset-react": "^7.23.3",
"@types/picomatch": "^2.3.3",
"@typescript-eslint/parser": "^6.20.0",
"@typescript-eslint/parser": "^6.21.0",
"babel-eslint": "^10.1.0",
"eslint": "^8.56.0",
"semver": "^7.5.4",
"semver": "^7.6.0",
"typescript-eslint-parser": "^22.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin-migrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
},
"dependencies": {
"@eslint-stylistic/metadata": "workspace:*",
"@typescript-eslint/utils": "^6.20.0"
"@typescript-eslint/utils": "^6.21.0"
}
}
4 changes: 2 additions & 2 deletions packages/eslint-plugin-plus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"eslint": "*"
},
"dependencies": {
"@typescript-eslint/utils": "^6.20.0"
"@typescript-eslint/utils": "^6.21.0"
},
"devDependencies": {
"@typescript-eslint/rule-tester": "^6.20.0"
"@typescript-eslint/rule-tester": "^6.21.0"
}
}
4 changes: 2 additions & 2 deletions packages/eslint-plugin-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
},
"dependencies": {
"@stylistic/eslint-plugin-js": "workspace:*",
"@typescript-eslint/utils": "^6.20.0"
"@typescript-eslint/utils": "^6.21.0"
},
"devDependencies": {
"@typescript-eslint/rule-tester": "^6.20.0"
"@typescript-eslint/rule-tester": "^6.21.0"
}
}
54 changes: 54 additions & 0 deletions patches/twoslash-eslint@0.2.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
diff --git a/dist/index.cjs b/dist/index.cjs
index aaa23e195bf86509df0cb04afd4a5ab55ecd63cc..c81fdbce4b1d2264651a1755c6f23b4abd235ac3 100644
--- a/dist/index.cjs
+++ b/dist/index.cjs
@@ -72,7 +72,7 @@ ${current.text}`;
} else {
merged = raws;
}
- const nodes = twoslashProtocol.resolveNodePositions(merged, code);
+ const nodes = twoslashProtocol.resolveNodePositions(merged, code).filter((i) => i.line < pc.lines.length);
const results = {
code,
nodes
diff --git a/dist/index.mjs b/dist/index.mjs
index 246dc40ac5e28a94cf308465887c852c1a192f30..ee01156c271b11ae3ba494c451fd88089051cf4a 100644
--- a/dist/index.mjs
+++ b/dist/index.mjs
@@ -70,7 +70,7 @@ ${current.text}`;
} else {
merged = raws;
}
- const nodes = resolveNodePositions(merged, code);
+ const nodes = resolveNodePositions(merged, code).filter((i) => i.line < pc.lines.length);
const results = {
code,
nodes
diff --git a/package.json b/package.json
index d66f4fe7bc6ab67d09da3930e9fe2108b2cbfa8f..1105553757b22cfe87b5e395d9a0ba954368809d 100644
--- a/package.json
+++ b/package.json
@@ -40,6 +40,12 @@
"files": [
"dist"
],
+ "scripts": {
+ "build": "unbuild",
+ "dev": "unbuild --stub",
+ "prepublishOnly": "nr build",
+ "start": "esno src/index.ts"
+ },
"peerDependencies": {
"eslint": ">=8.50.0"
},
@@ -48,10 +54,5 @@
},
"devDependencies": {
"@types/eslint": "^8.56.2"
- },
- "scripts": {
- "build": "unbuild",
- "dev": "unbuild --stub",
- "start": "esno src/index.ts"
}
}
Loading

0 comments on commit 502d18a

Please sign in to comment.