Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 28, 2024
1 parent 52ea154 commit 75cc1e4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default defineConfig({
{
name: 'twoslash:remove-escape',
postprocess(code) {
return code.replace(/\[\\\!code/g, '[!code')
return code.replace(/\[\\!code/g, '[!code')
},
},
],
Expand Down
7 changes: 4 additions & 3 deletions docs/.vitepress/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export default defineConfig({
transform(code, id) {
if (!id.endsWith('.md'))
return
return code.replace(/(`{3,4})(\w+) twoslash([^\n]*?)\n([\s\S]+?)\n\1/g, (_, quotes, lang, options, code) => {
return code.replace(/(`{3,4})(\w+) twoslash([^\n]*)\n([\s\S]+?)\n\1/g, (_, quotes, lang, options, code) => {
// Only run on codeblocks which have a twoslash annotation
if (!code.match(/\/\/ @|\^[?\|^]|---cut/))
if (!code.match(/\/\/ @|\^[?|^]|---cut/))
return _

let preferInput = false
Expand Down Expand Up @@ -69,7 +69,8 @@ export default defineConfig({
return
return await replaceAsync(
code,
/(`{3,4})(\w+)([^\n]*?)\beval\b([^\n]*?)\n([\s\S]+?)\n\1/g,
// eslint-disable-next-line regexp/no-super-linear-backtracking
/(`{3,4})(\w+)([^\n]*?)\beval\b([^\n]*)\n([\s\S]+?)\n\1/g,
async (_, quotes, lang, optionsPre, optionsPost, code) => {
// eslint-disable-next-line no-console
console.log('markdown eval', { lang, code })
Expand Down
2 changes: 1 addition & 1 deletion packages/twoslash/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export function createTwoslasher(createOptions: CreateTwoslashOptions = {}): Two
)
}

let prefix = code.slice(0, target).match(/[$_\w]+$/)?.[0] || ''
let prefix = code.slice(0, target).match(/[$\w]+$/)?.[0] || ''
prefix = prefix.split('.').pop()!

let completions: CompletionEntry[] = []
Expand Down
16 changes: 8 additions & 8 deletions packages/twoslash/src/regexp.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const reConfigBoolean = /^\/\/\s?@(\w+)$/mg
export const reConfigValue = /^\/\/\s?@(\w+):\s?(.+)$/mg
export const reAnnonateMarkers = /^\s*\/\/\s*\^(\?|\||\^+)( .*)?$/mg
export const reConfigBoolean = /^\/\/\s?@(\w+)$/gm
export const reConfigValue = /^\/\/\s?@(\w+):\s?(.+)$/gm
export const reAnnonateMarkers = /^\s*\/\/\s*\^(\?|\||\^+)( .*)?$/gm

export const reCutBefore = /^[\t\v\f ]*\/\/\s?---cut(-before)?---\r?\n/mg
export const reCutAfter = /^[\t\v\f ]*\/\/\s?---cut-after---$/mg
export const reCutStart = /^[\t\v\f ]*\/\/\s?---cut-start---$/mg
export const reCutEnd = /^[\t\v\f ]*\/\/\s?---cut-end---\r?\n/mg
export const reFilenamesMakers = /^[\t\v\f ]*\/\/\s?@filename: (.+)$/mg
export const reCutBefore = /^[\t\v\f ]*\/\/\s?---cut(-before)?---\r?\n/gm
export const reCutAfter = /^[\t\v\f ]*\/\/\s?---cut-after---$/gm
export const reCutStart = /^[\t\v\f ]*\/\/\s?---cut-start---$/gm
export const reCutEnd = /^[\t\v\f ]*\/\/\s?---cut-end---\r?\n/gm
export const reFilenamesMakers = /^[\t\v\f ]*\/\/\s?@filename: (.+)$/gm

0 comments on commit 75cc1e4

Please sign in to comment.