style: lint regexp
This commit is contained in:
parent
257d2c9db2
commit
4325c27968
@ -1,10 +1,6 @@
|
||||
import config from '@pengzhanbo/eslint-config-vue'
|
||||
|
||||
export default config({
|
||||
// todo: 正则校验
|
||||
// 当前项目中的 正则 还并不能完全通过 规则,存在 53 个问题
|
||||
// 但处理起来比较麻烦,因此将会作为一项比较长期的工作来完成。
|
||||
regexp: false,
|
||||
ignores: [
|
||||
'lib',
|
||||
'docs/notes/theme/snippet/code-block.snippet.md',
|
||||
|
||||
@ -24,7 +24,7 @@ export const caniusePlugin: PluginWithOptions<CanIUseOptions> = (
|
||||
): void => {
|
||||
createRuleBlock<CanIUseTokenMeta>(md, {
|
||||
type: 'caniuse',
|
||||
syntaxPattern: /^@\[caniuse(?:\s*?(embed|image)?(?:{([0-9,\-]*?)})?)\]\(([^)]*)\)/,
|
||||
syntaxPattern: /^@\[caniuse\s*(embed|image)?(?:\{([0-9,\-]*)\})?\]\(([^)]*)\)/,
|
||||
meta: ([, mode, versions = '', feature]) => ({
|
||||
feature,
|
||||
mode: (mode as CanIUseMode) || defaultMode,
|
||||
@ -53,7 +53,7 @@ export function legacyCaniuse(
|
||||
|
||||
mode = isMode(mode) ? mode : modeMap[0]
|
||||
const type = 'caniuse'
|
||||
const validateReg = new RegExp(`^${type}\\s+(.*)$`)
|
||||
const validateReg = new RegExp(`^${type}`)
|
||||
|
||||
const validate = (info: string): boolean => {
|
||||
return validateReg.test(info.trim())
|
||||
|
||||
@ -12,7 +12,7 @@ import { createRuleBlock } from '../utils/createRuleBlock.js'
|
||||
export const codeSandboxPlugin: PluginWithOptions<never> = (md) => {
|
||||
createRuleBlock<CodeSandboxTokenMeta>(md, {
|
||||
type: 'codesandbox',
|
||||
syntaxPattern: /^@\[codesandbox(?:\s+(embed|button))?(?:\s+([^]*?))?\]\(([^)]*?)\)/,
|
||||
syntaxPattern: /^@\[codesandbox(?:\s+(embed|button))?([^\]]*)\]\(([^)]*)\)/,
|
||||
meta([, type, info = '', source = '']) {
|
||||
const { attrs } = resolveAttrs(info)
|
||||
const [profile, filepath = ''] = source.split('#')
|
||||
|
||||
@ -14,7 +14,7 @@ const CODEPEN_LINK = 'https://codepen.io/'
|
||||
export const codepenPlugin: PluginWithOptions<never> = (md) => {
|
||||
createRuleBlock<CodepenTokenMeta>(md, {
|
||||
type: 'codepen',
|
||||
syntaxPattern: /^@\[codepen(?:\s+([^]*?))?\]\(([^)]*?)\)/,
|
||||
syntaxPattern: /^@\[codepen([^\]]*)\]\(([^)]*)\)/,
|
||||
meta: ([, info = '', source = '']) => {
|
||||
const { attrs } = resolveAttrs(info)
|
||||
const [user, slash] = source.split('/')
|
||||
|
||||
@ -15,7 +15,7 @@ export interface IconCacheItem {
|
||||
|
||||
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 8)
|
||||
const iconDataCache = new Map<string, any>()
|
||||
const URL_CONTENT_RE = /(url\([^]+?\))/
|
||||
const URL_CONTENT_RE = /(url\([\s\S]+?\))/
|
||||
const CSS_PATH = 'internal/md-power/icons.css'
|
||||
|
||||
function resolveOption(opt?: boolean | IconsOptions): Required<IconsOptions> {
|
||||
|
||||
@ -11,7 +11,7 @@ import { createRuleBlock } from '../utils/createRuleBlock.js'
|
||||
export const jsfiddlePlugin: PluginWithOptions<never> = (md) => {
|
||||
createRuleBlock<JSFiddleTokenMeta>(md, {
|
||||
type: 'jsfiddle',
|
||||
syntaxPattern: /^@\[jsfiddle(?:\s+([^]*?))?\]\(([^)]*?)\)/,
|
||||
syntaxPattern: /^@\[jsfiddle([^\]]*)\]\(([^)]*)\)/,
|
||||
meta([, info = '', source]) {
|
||||
const { attrs } = resolveAttrs(info)
|
||||
const [user, id] = source.split('/')
|
||||
|
||||
@ -5,7 +5,7 @@ import type { App } from 'vuepress/core'
|
||||
import { fs, getDirname, path } from 'vuepress/utils'
|
||||
import type { ReplEditorData, ReplOptions } from '../../shared/repl.js'
|
||||
|
||||
const RE_INFO = /^(#editable)?\s*?(.*)$/
|
||||
const RE_INFO = /^(#editable)?(.*)$/
|
||||
|
||||
function createReplContainer(md: markdownIt, lang: string) {
|
||||
const type = `${lang}-repl`
|
||||
|
||||
@ -13,7 +13,8 @@ import { createRuleBlock } from '../utils/createRuleBlock.js'
|
||||
export const pdfPlugin: PluginWithOptions<never> = (md) => {
|
||||
createRuleBlock<PDFTokenMeta>(md, {
|
||||
type: 'pdf',
|
||||
syntaxPattern: /^@\[pdf(?:\s+(\d+))?(?:\s+([^]*?))?\]\(([^)]*?)\)/,
|
||||
// eslint-disable-next-line regexp/no-super-linear-backtracking
|
||||
syntaxPattern: /^@\[pdf(?:\s+(\d+))?([^\]]*)\]\(([^)]*)\)/,
|
||||
meta([, page, info = '', src = '']) {
|
||||
const { attrs } = resolveAttrs(info)
|
||||
return {
|
||||
|
||||
@ -12,7 +12,7 @@ import { createRuleBlock } from '../utils/createRuleBlock.js'
|
||||
export const replitPlugin: PluginWithOptions<never> = (md) => {
|
||||
createRuleBlock<ReplitTokenMeta>(md, {
|
||||
type: 'replit',
|
||||
syntaxPattern: /^@\[replit(?:\s+([^]*?))?\]\(([^)]*?)\)/,
|
||||
syntaxPattern: /^@\[replit([^\]]*)\]\(([^)]*)\)/,
|
||||
meta: ([, info = '', source = '']) => {
|
||||
const { attrs } = resolveAttrs(info)
|
||||
return {
|
||||
|
||||
@ -18,7 +18,8 @@ export const bilibiliPlugin: PluginWithOptions<never> = (md) => {
|
||||
createRuleBlock<BilibiliTokenMeta>(md, {
|
||||
type: 'bilibili',
|
||||
name: 'video_bilibili',
|
||||
syntaxPattern: /^@\[bilibili(?:\s+p(\d+))?(?:\s+([^]*?))?\]\(([^)]*)\)/,
|
||||
// eslint-disable-next-line regexp/no-super-linear-backtracking
|
||||
syntaxPattern: /^@\[bilibili(?:\s+p(\d+))?([^\]]*)\]\(([^)]*)\)/,
|
||||
meta([, page, info = '', source = '']) {
|
||||
const { attrs } = resolveAttrs(info)
|
||||
const ids = source.trim().split(/\s+/)
|
||||
|
||||
@ -15,7 +15,7 @@ export const youtubePlugin: PluginWithOptions<never> = (md) => {
|
||||
createRuleBlock<YoutubeTokenMeta>(md, {
|
||||
type: 'youtube',
|
||||
name: 'video_youtube',
|
||||
syntaxPattern: /^@\[youtube(?:\s+([^]*?))?\]\(([^)]*)\)/,
|
||||
syntaxPattern: /^@\[youtube([^\]]*)\]\(([^)]*)\)/,
|
||||
meta([, info = '', id = '']) {
|
||||
const { attrs } = resolveAttrs(info)
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const RE_ATTR_VALUE = /(?:^|\s+)(?<attr>[\w\d-]+)(?:=\s*(?<quote>['"])(?<value>.+?)\k<quote>)?(?:\s+|$)/
|
||||
const RE_ATTR_VALUE = /(?:^|\s+)(?<attr>[\w-]+)(?:=\s*(?<quote>['"])(?<value>.+?)\k<quote>)?(?:\s+|$)/
|
||||
|
||||
export function resolveAttrs(info: string): {
|
||||
attrs: Record<string, any>
|
||||
|
||||
@ -147,7 +147,9 @@ async function indexFile(page: Page, options: SearchIndexOptions['searchOptions'
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line regexp/no-super-linear-backtracking
|
||||
const headingRegex = /<h(\d*).*?>(<a.*? href="#.*?".*?>.*?<\/a>)<\/h\1>/gi
|
||||
// eslint-disable-next-line regexp/no-super-linear-backtracking
|
||||
const headingContentRegex = /<a.*? href="#(.*?)".*?>(.*?)<\/a>/i
|
||||
|
||||
/**
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { useClipboard, useEventListener } from '@vueuse/core'
|
||||
|
||||
const SHELL_RE = /language-(shellscript|shell|bash|sh|zsh)/
|
||||
const SHELL_RE = /language-(?:shellscript|shell|bash|sh|zsh)/
|
||||
const IGNORE_NODES = ['.vp-copy-ignore', '.diff.remove']
|
||||
|
||||
interface CopyCodeOptions {
|
||||
|
||||
@ -27,7 +27,7 @@ const cache = new LRUCache<string, string>(64)
|
||||
|
||||
const vueRE = /-vue$/
|
||||
const mustacheRE = /\{\{.*?\}\}/g
|
||||
const decorationsRE = /^\/\/ @decorations:(.*?)\n/
|
||||
const decorationsRE = /^\/\/ @decorations:(.*)\n/
|
||||
|
||||
export async function highlight(
|
||||
theme: ThemeOptions,
|
||||
@ -136,7 +136,7 @@ export async function highlight(
|
||||
})
|
||||
|
||||
if (enabledTwoslash && options.twoslash)
|
||||
s = s.replace(/{/g, '{')
|
||||
s = s.replace(/\{/g, '{')
|
||||
|
||||
return `${s}\n`
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
import type { Markdown } from 'vuepress/markdown'
|
||||
|
||||
const HIGHLIGHT_LINES_REGEXP = /{([\d,-]+)}/
|
||||
const HIGHLIGHT_LINES_REGEXP = /\{([\d,-]+)\}/
|
||||
|
||||
export function highlightLinesPlugin(md: Markdown): void {
|
||||
const rawFence = md.renderer.rules.fence!
|
||||
|
||||
@ -56,7 +56,7 @@ export function lineNumberPlugin(md: Markdown, { lineNumbers = true }: LineNumbe
|
||||
|
||||
const finalCode = rawCode
|
||||
.replace(/<\/div>$/, `${lineNumbersWrapperCode}</div>`)
|
||||
.replace(/"(language-[^"]*?)"/, '"$1 line-numbers-mode"')
|
||||
.replace(/"(language-[^"]*)"/, '"$1 line-numbers-mode"')
|
||||
|
||||
return finalCode
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ export function preWrapperPlugin(md: Markdown, { preWrapper = true }: PreWrapper
|
||||
|
||||
if (!preWrapper) {
|
||||
// remove `<code>` attributes
|
||||
result = result.replace(/<code[^]*?>/, '<code>')
|
||||
result = result.replace(/<code[\s\S]*?>/, '<code>')
|
||||
result = `<pre class="${languageClass}"${result.slice('<pre'.length)}`
|
||||
return result
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ function vPre<T extends ElementContent>(el: T): T {
|
||||
|
||||
function renderMarkdown(this: ShikiTransformerContextCommon, md: string): ElementContent[] {
|
||||
const mdast = fromMarkdown(
|
||||
md.replace(/{@link ([^}]*)}/g, '$1'), // replace jsdoc links
|
||||
md.replace(/\{@link ([^}]*)\}/g, '$1'), // replace jsdoc links
|
||||
{ mdastExtensions: [gfmFromMarkdown()] },
|
||||
)
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ export function transformerTwoslash(options: VitePressPluginTwoslashOptions = {}
|
||||
},
|
||||
postprocess(html) {
|
||||
if (this.meta.twoslash)
|
||||
return html.replace(/{/g, '{')
|
||||
return html.replace(/\{/g, '{')
|
||||
|
||||
return html
|
||||
},
|
||||
|
||||
@ -9,6 +9,7 @@ import type { TransformerCompactLineOption } from '@shikijs/transformers'
|
||||
* [{ line: number, classes: string[] }]
|
||||
*/
|
||||
export function attrsToLines(attrs: string): TransformerCompactLineOption[] {
|
||||
// eslint-disable-next-line regexp/optimal-quantifier-concatenation, regexp/no-super-linear-backtracking
|
||||
attrs = attrs.replace(/^(?:\[.*?\])?.*?([\d,-]+).*/, '$1').trim()
|
||||
|
||||
const result: number[] = []
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
const RE_ATTR_VALUE = /(?:^|\s+)(?<attr>[\w\d-]+)(?:=\s*(?<quote>['"])(?<value>.+?)\k<quote>)?(?:\s+|$)/
|
||||
const RE_CODE_BLOCKS = /^[\w\d-]*(\s*:[\w\d-]*)?(\s*\{[\d\w-,\s]+\})?\s*/
|
||||
const RE_ATTR_VALUE = /(?:^|\s+)(?<attr>[\w-]+)(?:=\s*(?<quote>['"])(?<value>.+?)\k<quote>)?(?:\s+|$)/
|
||||
const RE_CODE_BLOCKS = /^[\w\-]*(\s*:[\w\-]*)?(\s*\{[\w\-,\s]+\})?\s*/
|
||||
|
||||
export function resolveAttrs(info: string): {
|
||||
attrs: Record<string, string | boolean>
|
||||
|
||||
@ -26,11 +26,6 @@
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.vp-doc .hint-container code {
|
||||
font-size: var(--vp-custom-block-code-font-size);
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.vp-doc .hint-container th,
|
||||
.vp-doc .hint-container blockquote > p {
|
||||
font-size: var(--vp-custom-block-font-size);
|
||||
@ -46,6 +41,7 @@
|
||||
}
|
||||
|
||||
.vp-doc .hint-container div[class*="language-"] code {
|
||||
font-size: var(--vp-custom-block-code-font-size);
|
||||
font-weight: 400;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
@ -115,7 +115,8 @@ export function extendsPageData(
|
||||
|
||||
let uuid = 10000
|
||||
const cache: Record<string, number> = {}
|
||||
const RE_CATEGORY = /^(\d+)?(?:\.?)([^]+)$/
|
||||
// eslint-disable-next-line regexp/no-super-linear-backtracking, regexp/no-misleading-capturing-group
|
||||
const RE_CATEGORY = /^(\d+)?\.?([\s\S]+)$/
|
||||
let LOCALE_RE: RegExp
|
||||
|
||||
export function autoCategory(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user