From 4be8252dedb448c49f5e594f3d0a42cd4a550344 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Tue, 20 Aug 2024 12:39:32 +0800 Subject: [PATCH] style: fix eslint error (#332) --- .../EditorHeader/StyleDropdown.vue | 2 +- .../CodemirrorEditor/EditorHeader/index.vue | 8 +- .../DropdownMenuCheckboxItem.vue | 6 +- .../ui/dropdown-menu/DropdownMenuContent.vue | 2 +- .../ui/dropdown-menu/DropdownMenuItem.vue | 2 +- .../ui/dropdown-menu/DropdownMenuLabel.vue | 2 +- .../dropdown-menu/DropdownMenuRadioItem.vue | 4 +- .../dropdown-menu/DropdownMenuSeparator.vue | 2 +- .../ui/dropdown-menu/DropdownMenuShortcut.vue | 2 +- .../dropdown-menu/DropdownMenuSubContent.vue | 2 +- .../dropdown-menu/DropdownMenuSubTrigger.vue | 2 +- .../ui/hover-card/HoverCardContent.vue | 2 +- src/utils/index.js | 27 +++--- src/utils/wx-renderer.js | 10 +-- tailwind.config.js | 88 +++++++++---------- 15 files changed, 79 insertions(+), 82 deletions(-) diff --git a/src/components/CodemirrorEditor/EditorHeader/StyleDropdown.vue b/src/components/CodemirrorEditor/EditorHeader/StyleDropdown.vue index c6d818a..4a8e855 100644 --- a/src/components/CodemirrorEditor/EditorHeader/StyleDropdown.vue +++ b/src/components/CodemirrorEditor/EditorHeader/StyleDropdown.vue @@ -18,7 +18,7 @@ import { HoverCardTrigger, } from '@/components/ui/hover-card' -import { codeBlockThemeOptions, colorOptions, fontFamilyOptions, fontSizeOptions, githubConfig, legendOptions, themeOptions } from '@/config' +import { codeBlockThemeOptions, colorOptions, fontFamilyOptions, fontSizeOptions, legendOptions, themeOptions } from '@/config' import { useStore } from '@/stores' const store = useStore() diff --git a/src/components/CodemirrorEditor/EditorHeader/index.vue b/src/components/CodemirrorEditor/EditorHeader/index.vue index 8c6ecf4..47f28bb 100644 --- a/src/components/CodemirrorEditor/EditorHeader/index.vue +++ b/src/components/CodemirrorEditor/EditorHeader/index.vue @@ -1,5 +1,5 @@ diff --git a/src/components/ui/dropdown-menu/DropdownMenuSubContent.vue b/src/components/ui/dropdown-menu/DropdownMenuSubContent.vue index 446f9fb..829bcfe 100644 --- a/src/components/ui/dropdown-menu/DropdownMenuSubContent.vue +++ b/src/components/ui/dropdown-menu/DropdownMenuSubContent.vue @@ -8,7 +8,7 @@ import { } from 'radix-vue' import { cn } from '@/lib/utils' -const props = defineProps() +const props = defineProps() const emits = defineEmits() const delegatedProps = computed(() => { diff --git a/src/components/ui/dropdown-menu/DropdownMenuSubTrigger.vue b/src/components/ui/dropdown-menu/DropdownMenuSubTrigger.vue index 3474553..5a9f2c2 100644 --- a/src/components/ui/dropdown-menu/DropdownMenuSubTrigger.vue +++ b/src/components/ui/dropdown-menu/DropdownMenuSubTrigger.vue @@ -8,7 +8,7 @@ import { import { ChevronRight } from 'lucide-vue-next' import { cn } from '@/lib/utils' -const props = defineProps() +const props = defineProps() const delegatedProps = computed(() => { const { class: _, ...delegated } = props diff --git a/src/components/ui/hover-card/HoverCardContent.vue b/src/components/ui/hover-card/HoverCardContent.vue index 8affac4..dd49381 100644 --- a/src/components/ui/hover-card/HoverCardContent.vue +++ b/src/components/ui/hover-card/HoverCardContent.vue @@ -9,7 +9,7 @@ import { import { cn } from '@/lib/utils' const props = withDefaults( - defineProps(), + defineProps(), { sideOffset: 4, }, diff --git a/src/utils/index.js b/src/utils/index.js index ff45d4a..e9ef547 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -3,7 +3,7 @@ import prettier from 'prettier/standalone' import prettierCss from 'prettier/parser-postcss' import prettierMarkdown from 'prettier/parser-markdown' -import { defaultTheme, prefix } from '@/config' +import { prefix } from '@/config' export function addPrefix(str) { return `${prefix}__${str}` @@ -323,10 +323,13 @@ export function exportHTML() { } /** - * 生成列表字符串 - * @param {*} data 对应内容集合 - * @param {*} rows 行 - * @param {*} cols 列 + * 根据数据生成 Markdown 表格 + * + * @param {object} options - 选项 + * @param {object} options.data - 表格数据 + * @param {number} options.rows - 行数 + * @param {number} options.cols - 列数 + * @returns {string} 生成的 Markdown 表格 */ export function createTable({ data, rows, cols }) { let table = `` @@ -354,8 +357,8 @@ export function toBase64(file) { } export function checkImage(file) { - // check filename suffix - const isValidSuffix = /\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(file.name) + // 检查文件名后缀 + const isValidSuffix = /\.(gif|jpe?g|png)$/i.test(file.name) if (!isValidSuffix) { return { ok: false, @@ -363,15 +366,15 @@ export function checkImage(file) { } } - // check file size - const maxSize = 10 - const valid = file.size / 1024 / 1024 <= maxSize - if (!valid) { + // 检查文件大小 + const maxSizeMB = 10 + if (file.size > maxSizeMB * 1024 * 1024) { return { ok: false, - msg: `由于公众号限制,图片大小不能超过 ${maxSize}M`, + msg: `由于公众号限制,图片大小不能超过 ${maxSizeMB}M`, } } + return { ok: true } } diff --git a/src/utils/wx-renderer.js b/src/utils/wx-renderer.js index d983bb0..9a4b39d 100644 --- a/src/utils/wx-renderer.js +++ b/src/utils/wx-renderer.js @@ -24,7 +24,7 @@ class WxRenderer { 'font-size': this.opts.size, }) for (const ele in themeTpl.inline) { - if (themeTpl.inline.hasOwnProperty(ele)) { + if (Object.prototype.hasOwnProperty.call(themeTpl.inline, ele)) { const style = themeTpl.inline[ele] mapping[ele] = merge(themeTpl.BASE, style) } @@ -32,7 +32,7 @@ class WxRenderer { const base_block = merge(base, {}) for (const ele in themeTpl.block) { - if (themeTpl.block.hasOwnProperty(ele)) { + if (Object.prototype.hasOwnProperty.call(themeTpl.block, ele)) { const style = themeTpl.block[ele] mapping[ele] = merge(base_block, style) } @@ -151,12 +151,12 @@ class WxRenderer { `code`, )}>${text}` } - renderer.codespan = (text, lang) => + renderer.codespan = (text, _) => `${text}` renderer.listitem = text => `
  • <%s/>${text}
  • ` - renderer.list = (text, ordered, start) => { + renderer.list = (text, ordered, _) => { text = text.replace(/<\/*p .*?>/g, ``).replace(/<\/*p>/g, ``) const segments = text.split(`<%s/>`) if (!ordered) { @@ -220,7 +220,7 @@ class WxRenderer { `
    ${header}${body}
    ` - renderer.tablecell = (text, flags) => + renderer.tablecell = (text, _) => `${text}` renderer.hr = () => `
    ` return renderer diff --git a/tailwind.config.js b/tailwind.config.js index 2e3505b..edb0872 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -1,87 +1,87 @@ -const animate = require("tailwindcss-animate") +const animate = require(`tailwindcss-animate`) /** @type {import('tailwindcss').Config} */ module.exports = { - darkMode: ["class"], - safelist: ["dark"], - prefix: "", + darkMode: [`class`], + safelist: [`dark`], + prefix: ``, experimental: { optimizeUniversalDefaults: true, }, content: [ - './pages/**/*.{ts,tsx,vue}', - './components/**/*.{ts,tsx,vue}', - './app/**/*.{ts,tsx,vue}', - './src/**/*.{ts,tsx,vue}', - ], + `./pages/**/*.{ts,tsx,vue}`, + `./components/**/*.{ts,tsx,vue}`, + `./app/**/*.{ts,tsx,vue}`, + `./src/**/*.{ts,tsx,vue}`, + ], theme: { extend: { colors: { - border: "hsl(var(--border))", - input: "hsl(var(--input))", - ring: "hsl(var(--ring))", - background: "hsl(var(--background))", - foreground: "hsl(var(--foreground))", + border: `hsl(var(--border))`, + input: `hsl(var(--input))`, + ring: `hsl(var(--ring))`, + background: `hsl(var(--background))`, + foreground: `hsl(var(--foreground))`, primary: { - DEFAULT: "hsl(var(--primary))", - foreground: "hsl(var(--primary-foreground))", + DEFAULT: `hsl(var(--primary))`, + foreground: `hsl(var(--primary-foreground))`, }, secondary: { - DEFAULT: "hsl(var(--secondary))", - foreground: "hsl(var(--secondary-foreground))", + DEFAULT: `hsl(var(--secondary))`, + foreground: `hsl(var(--secondary-foreground))`, }, destructive: { - DEFAULT: "hsl(var(--destructive))", - foreground: "hsl(var(--destructive-foreground))", + DEFAULT: `hsl(var(--destructive))`, + foreground: `hsl(var(--destructive-foreground))`, }, muted: { - DEFAULT: "hsl(var(--muted))", - foreground: "hsl(var(--muted-foreground))", + DEFAULT: `hsl(var(--muted))`, + foreground: `hsl(var(--muted-foreground))`, }, accent: { - DEFAULT: "hsl(var(--accent))", - foreground: "hsl(var(--accent-foreground))", + DEFAULT: `hsl(var(--accent))`, + foreground: `hsl(var(--accent-foreground))`, }, popover: { - DEFAULT: "hsl(var(--popover))", - foreground: "hsl(var(--popover-foreground))", + DEFAULT: `hsl(var(--popover))`, + foreground: `hsl(var(--popover-foreground))`, }, card: { - DEFAULT: "hsl(var(--card))", - foreground: "hsl(var(--card-foreground))", + DEFAULT: `hsl(var(--card))`, + foreground: `hsl(var(--card-foreground))`, }, }, borderRadius: { - xl: "calc(var(--radius) + 4px)", - lg: "var(--radius)", - md: "calc(var(--radius) - 2px)", - sm: "calc(var(--radius) - 4px)", + xl: `calc(var(--radius) + 4px)`, + lg: `var(--radius)`, + md: `calc(var(--radius) - 2px)`, + sm: `calc(var(--radius) - 4px)`, }, keyframes: { - "accordion-down": { + 'accordion-down': { from: { height: 0 }, - to: { height: "var(--radix-accordion-content-height)" }, + to: { height: `var(--radix-accordion-content-height)` }, }, - "accordion-up": { - from: { height: "var(--radix-accordion-content-height)" }, + 'accordion-up': { + from: { height: `var(--radix-accordion-content-height)` }, to: { height: 0 }, }, - "collapsible-down": { + 'collapsible-down': { from: { height: 0 }, - to: { height: 'var(--radix-collapsible-content-height)' }, + to: { height: `var(--radix-collapsible-content-height)` }, }, - "collapsible-up": { - from: { height: 'var(--radix-collapsible-content-height)' }, + 'collapsible-up': { + from: { height: `var(--radix-collapsible-content-height)` }, to: { height: 0 }, }, }, animation: { - "accordion-down": "accordion-down 0.2s ease-out", - "accordion-up": "accordion-up 0.2s ease-out", - "collapsible-down": "collapsible-down 0.2s ease-in-out", - "collapsible-up": "collapsible-up 0.2s ease-in-out", + 'accordion-down': `accordion-down 0.2s ease-out`, + 'accordion-up': `accordion-up 0.2s ease-out`, + 'collapsible-down': `collapsible-down 0.2s ease-in-out`, + 'collapsible-up': `collapsible-up 0.2s ease-in-out`, }, }, },