Skip to content

Commit 77c32d4

Browse files
committed
chore: lint
1 parent 0edaf99 commit 77c32d4

42 files changed

Lines changed: 167 additions & 92 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/devtools-ui-kit/src/components/NDarkToggle.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function toggle(event?: MouseEvent) {
4949
document.documentElement.animate(
5050
{
5151
clipPath: isDark.value
52-
? [...clipPath].reverse()
52+
? clipPath.toReversed()
5353
: clipPath,
5454
},
5555
{

packages/devtools-ui-kit/src/unocss.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717

1818
// @unocss-include
1919

20+
const N_PREFIX_RE = /^n-(.*)$/
21+
2022
export function unocssPreset(): Preset {
2123
return {
2224
name: '@nuxt/devtools-ui-kit',
@@ -28,15 +30,15 @@ export function unocssPreset(): Preset {
2830
},
2931
}),
3032
rules: [
31-
[/^n-(.*)$/, ([, body]: string[], { theme }: RuleContext<Theme>) => {
33+
[N_PREFIX_RE, ([, body]: string[], { theme }: RuleContext<Theme>) => {
3234
const color = parseColor(body!, theme)
3335
if (color?.cssColor?.type === 'rgb' && color.cssColor.components) {
3436
return {
3537
'--nui-c-context': `${color.cssColor.components.join(',')}`,
3638
}
3739
}
3840
}],
39-
[/^n-(.*)$/, fonts[1]![1] as any],
41+
[N_PREFIX_RE, fonts[1]![1] as any],
4042
['n-dashed', { 'border-style': 'dashed' }],
4143
['n-solid', {
4244
'background-color': 'rgba(var(--nui-c-context), 1) !important',

packages/devtools/client/components/AssetDropZone.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const props = defineProps({
1818
},
1919
})
2020
21+
const FILE_EXT_RE = /\.\w+$/
22+
2123
const visible = useVModel(props, 'modelValue')
2224
const lastTarget = ref()
2325
@@ -41,7 +43,7 @@ function onDrop(e: DragEvent) {
4143
}
4244
4345
function setFiles(data: FileList | null) {
44-
const inputFiles = Array.from(data || [])
46+
const inputFiles = [...data || []]
4547
if (inputFiles.length) {
4648
const newFiles: File[] = []
4749
const existingFileNames: string[] = files.value.map(file => file.name)
@@ -120,7 +122,7 @@ function blobIt(file: File) {
120122
121123
function changeName(file: File, newName: string) {
122124
const [name, ext] = file.name.split('.')
123-
const baseName = newName.replace(/\.\w+$/, '')
125+
const baseName = newName.replace(FILE_EXT_RE, '')
124126
const newFileName = `${baseName}.${ext}`
125127
if (baseName.length === 0) {
126128
// TODO: with proper dialog

packages/devtools/client/components/CodeDiff.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const props = defineProps<{
99
to: string
1010
lang: BuiltinLanguage | 'text'
1111
}>()
12+
const SHIKI_CLASS_RE = /class="shiki/
13+
const LINE_CLASS_RE = /class="line"/g
1214
1315
function calculateDiff(from: string, to: string) {
1416
const diffs = diffLines(from.trim(), to.trim())
@@ -46,8 +48,8 @@ const diff = computed(() => calculateDiff(props.from, props.to))
4648
function transformRendered(code: string) {
4749
let count = 0
4850
return code
49-
.replace(/class="shiki/, 'class="shiki diff')
50-
.replace(/class="line"/g, (_) => {
51+
.replace(SHIKI_CLASS_RE, 'class="shiki diff')
52+
.replace(LINE_CLASS_RE, (_) => {
5153
count++
5254
if (diff.value.added.includes(count - 1))
5355
return 'class="line line-added"'

packages/devtools/client/components/ComponentsGraph.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const entries = computed(() => {
5757
})
5858
}
5959
addToSet(selectedFilter.value)
60-
return Array.from(set)
60+
return [...set]
6161
}
6262
return relations
6363
})
@@ -206,14 +206,18 @@ function onCloseDrawer() {
206206
selected.value = undefined
207207
}
208208
209+
const COMPONENTS_PATH_RE = /.*\/components\//
210+
const VUE_EXT_RE = /\.vue$/
211+
const INDEX_SUFFIX_RE = /\/index$/
212+
209213
function getComponentName(path: string) {
210214
const component = props.components.find(i => i.filePath === path)
211215
if (component)
212216
return component.pascalName
213217
return path
214-
.replace(/.*\/components\//, '')
215-
.replace(/\.vue$/, '')
216-
.replace(/\/index$/, '')
218+
.replace(COMPONENTS_PATH_RE, '')
219+
.replace(VUE_EXT_RE, '')
220+
.replace(INDEX_SUFFIX_RE, '')
217221
.split('/')
218222
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
219223
.join('')

packages/devtools/client/components/DebugModuleMutationRecords.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ const props = defineProps<{
66
moduleMutationRecords: ServerDebugModuleMutationRecord[]
77
}>()
88
9+
const WINDOWS_DRIVE_RE = /^[a-z]:[\\/]/i
10+
911
function isPath(path: string) {
10-
return path.startsWith('/') || path.match(/^[a-z]:[\\/]/i)
12+
return path.startsWith('/') || path.match(WINDOWS_DRIVE_RE)
1113
}
1214
1315
// const search = ref('')

packages/devtools/client/components/FileIcon.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { computed } from 'vue'
33
44
const props = defineProps<{ id?: string }>()
55
6-
const ext = computed(() => props.id?.split(/\./g).pop() || '')
6+
const DOT_RE = /\./g
7+
8+
const ext = computed(() => props.id?.split(DOT_RE).pop() || '')
79
const icon = computed(() => {
810
switch (ext.value) {
911
case 'vue':

packages/devtools/client/components/HooksTable.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const startTimes = computed(() => props.hooks.map(i => i.start).sort((a, b) => a
2323
2424
const sorted = computed(() => {
2525
const sortFn = sortFunctions[sortby.value]
26-
const sorted = [...props.hooks].sort(sortFn)
26+
const sorted = props.hooks.toSorted(sortFn)
2727
if (direction.value === 'desc')
2828
sorted.reverse()
2929
return sorted

packages/devtools/client/components/OpenGraphMissingTabs.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const props = defineProps<{
1111
tags: NormalizedHeadTag[]
1212
matchedRouteFilepath?: string
1313
}>()
14+
const JSON_KEY_RE = /"([^"]+)":/g
15+
const DOUBLE_QUOTE_RE = /"/g
1416
1517
const missingTags = computed(() => {
1618
return ogTags.filter(define => !props.tags?.some(tag => tag.name === define.name))
@@ -31,16 +33,16 @@ const codeSnippet = computed(() => {
3133
3234
if (Object.keys(mergedSeoMetaOptions).length) {
3335
const body = JSON.stringify(mergedSeoMetaOptions, null, 2)
34-
.replace(/"([^"]+)":/g, '$1:')
35-
.replace(/"/g, '\'')
36+
.replace(JSON_KEY_RE, '$1:')
37+
.replace(DOUBLE_QUOTE_RE, '\'')
3638
3739
lines.push(`useSeoMeta(${body})`)
3840
}
3941
4042
if (Object.keys(mergedHeadOptions).length) {
4143
const body = JSON.stringify(mergedHeadOptions, null, 2)
42-
.replace(/"([^"]+)":/g, '$1:')
43-
.replace(/"/g, '\'')
44+
.replace(JSON_KEY_RE, '$1:')
45+
.replace(DOUBLE_QUOTE_RE, '\'')
4446
4547
lines.push(`useHead(${body})`)
4648
}

packages/devtools/client/components/RoutePathItem.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@ import { computed, ref } from 'vue'
55
const props = defineProps<{
66
route: RouteInfo
77
}>()
8-
98
const emit = defineEmits<{
109
(e: 'navigate', path: string): void
1110
}>()
11+
const EXPRESS_PARAM_RE = /(:\w+[?*]?(?:\(\))?)/
12+
const TRAILING_PARENS_RE = /\(\)$/
13+
const MULTI_SLASH_RE = /\/+/g
1214
1315
const partsInput = ref<string[]>([])
1416
const parts = computed(() => {
1517
const _ = parseExpressRoute(props.route.path)
1618
// eslint-disable-next-line vue/no-side-effects-in-computed-properties
17-
partsInput.value = Array.from({ length: _.length }, () => '')
19+
partsInput.value = Array.from<string>({ length: _.length }).fill('')
1820
return _
1921
})
2022
2123
function parseExpressRoute(route: string) {
2224
return route
23-
.split(/(:\w+[?*]?(?:\(\))?)/)
25+
.split(EXPRESS_PARAM_RE)
2426
.filter(Boolean)
2527
.map(i => i[0] === ':'
26-
? i.replace(/\(\)$/, '?')
28+
? i.replace(TRAILING_PARENS_RE, '?')
2729
: i)
2830
}
2931
@@ -34,7 +36,7 @@ const path = computed(() => parts.value
3436
: i,
3537
)
3638
.join('')
37-
.replace(/\/+/g, '/'))
39+
.replace(MULTI_SLASH_RE, '/'))
3840
const hasWildcard = computed(() => props.route.path.includes(':'))
3941
4042
function navigate() {

0 commit comments

Comments
 (0)