perf: 优化部分正则校验规则

This commit is contained in:
pengzhanbo 2024-05-19 14:06:47 +08:00
parent bc38fad18c
commit 5af709a762
9 changed files with 14 additions and 9 deletions

View File

@ -18,6 +18,7 @@
"stylelint.packageManager": "pnpm",
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off" },
{ "rule": "format/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
@ -27,11 +28,11 @@
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
],
"editor.formatOnSave": false,
"prettier.enable": false,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
// "source.fixAll.stylelint": "explicit"
},
"editor.formatOnPaste": true,
"eslint.validate": [

View File

@ -28,7 +28,7 @@ permalink: /guide/write/
由于文件夹名称将作为分类名称,且不在主题配置中进行排序配置,对于有排序需要的场景,使用以下规则进行命名
``` ts
const dir = /\d+\.[^]+/
const dir = /\d+\.[\s\S]+/
// 即 数字 + . + 分类名称
// 如: 1.前端
```

View File

@ -1,6 +1,10 @@
import config from '@pengzhanbo/eslint-config-vue'
export default config({
// todo: 正则校验
// 当前项目中的 正则 海冰不能完全通过 规则,存在 53 个问题
// 但处理起来比较麻烦,因此将会作为一项比较长期的工作来完成。
regexp: false,
ignores: [
'lib',
'docs/notes/theme/snippet/code-block.snippet.md',

View File

@ -22,7 +22,7 @@ if (import.meta.hot) {
}
`
const headingRe = /<h(\d*).*?>.*?<\/h\1>/gi
const headingRe = /<h(\d)[^>]*>.*?<\/h\1>/gi
function getTimestamp(time: Date): number {
return new Date(time).getTime()

View File

@ -14,7 +14,7 @@ export function caniusePlugin({
}: CanIUsePluginOptions): Plugin {
mode = isMode(mode) ? mode : modeMap[0]
const type = 'caniuse'
const validateReg = new RegExp(`^${type}\\s+(.*)$`)
const validateReg = new RegExp(`^${type}(?:$|\s)`)
const pluginObj: PluginObject = {
name: '@vuepress-plume/plugin-caniuse',
clientConfigFile: path.resolve(__dirname, '../client/clientConfig.js'),

View File

@ -5,7 +5,7 @@ import type { CopyCodeOptions } from '../shared/index.js'
declare const __COPY_CODE_OPTIONS__: CopyCodeOptions
const options = __COPY_CODE_OPTIONS__
const RE_LANGUAGE = /language-([\w]+)/
const RE_LANGUAGE = /language-(\w+)/
const RE_START_CODE = /^ *(\$|>)/gm
const shells = ['shellscript', 'shell', 'bash', 'sh', 'zsh']
const ignoredNodes = ['.diff.remove', '.vp-copy-ignore']

View File

@ -34,7 +34,7 @@ function highlight() {
})
if (container) {
container.innerHTML = output
.replace(/^<pre[^]+?>/, '')
.replace(/^<pre[^>]*>/, '')
.replace(/<\/pre>$/, '')
.replace(/(<span class="line">)(<\/span>)/g, '$1<wbr>$2')
}

View File

@ -4,7 +4,7 @@ import { sleep } from '../utils/sleep.js'
import { rustExecute } from './rustRepl.js'
const ignoredNodes = ['.diff.remove', '.vp-copy-ignore']
const RE_LANGUAGE = /language-([\w]+)/
const RE_LANGUAGE = /language-(\w+)/
const api = {
go: 'https://api.pengzhanbo.cn/repl/golang/run',
kotlin: 'https://api.pengzhanbo.cn/repl/kotlin/run',

View File

@ -3,7 +3,7 @@ export function checkIsMobile(ua: string): boolean {
}
export function checkIsSafari(ua: string): boolean {
return /version\/([\w.]+) .*(mobile ?safari|safari)/i.test(ua)
return /version\/[\w.]+ .*(?:mobile ?safari|safari)/i.test(ua)
}
export function checkIsiPad(ua: string): boolean {