Skip to content

Commit

Permalink
style: normalize tsx syntax style and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhc committed Jul 11, 2023
1 parent 2f8426e commit d9e3451
Show file tree
Hide file tree
Showing 313 changed files with 1,435 additions and 1,314 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ cache
*.pcss
*.scss
*.svg

common/icons/vue
common/icons/types
10 changes: 6 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
const { defineConfig } = require('eslint-define-config')

module.exports = defineConfig({
extends: ['@vexip-ui/eslint-config'],
root: true,
rules: {
Expand Down Expand Up @@ -34,9 +36,9 @@ module.exports = {
}
},
{
files: ['components/**/*.tsx'],
files: ['**/*.spec.tsx'],
rules: {
'no-sequences': 'off'
'react/jsx-key': 'off'
}
},
{
Expand Down Expand Up @@ -74,4 +76,4 @@ module.exports = {
globals: {
__VERSION__: 'readonly'
}
}
})
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ jobs:
- name: Lint
run: pnpm run lint

- name: Lint scripts
run: pnpm run lint:scripts

- name: Lint style
run: pnpm run lint:style

Expand Down
6 changes: 3 additions & 3 deletions .husky/.lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"*.{js,jsx,ts,tsx}": [
"*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}": [
"prettier --write",
"eslint --fix"
],
"{!(package)*.json,*.code-snippets,.!(browserslist|npm)*rc}": [
"prettier --write--parser json"
"prettier --write --parser json"
],
"package.json": [
"prettier --write"
],
"*.{css,scss,pcss,html}": [
"*.{css,scss,html}": [
"prettier --write",
"stylelint --fix"
],
Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ cache
*.sh

CHANGELOG.md

common/icons/vue
common/icons/types
2 changes: 2 additions & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ node_modules
*.svg
*.gif
*.md

common/icons/vue
41 changes: 22 additions & 19 deletions common/icons/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { resolve, basename } from 'node:path'
import { basename, resolve } from 'node:path'
import { readFile, writeFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'

import fs from 'fs-extra'
import { execa } from 'execa'
import { red, cyan, green } from 'kolorist'
import { cyan, green, red } from 'kolorist'
import glob from 'fast-glob'
import { format } from 'prettier'

Expand Down Expand Up @@ -95,33 +96,35 @@ async function generateVueIcons(dir: string, out: string, suffix: string) {
let exports = ''
let types = ''

await Promise.all(svgFiles.map(async svgFile => {
const fileName = basename(svgFile, '.svg')
const svg = (await readFile(svgFile, 'utf-8'))
.replace(/<!--[\s\S]*-->/, '')
.replace(/xmlns=".*?"/, 'style="transform: scale(0.85)"')
await Promise.all(
svgFiles.map(async svgFile => {
const fileName = basename(svgFile, '.svg')
const svg = (await readFile(svgFile, 'utf-8'))
.replace(/<!--[\s\S]*-->/, '')
.replace(/xmlns=".*?"/, 'style="transform: scale(0.85)"')

let name = toCapitalCase(fileName)
name = name.replace(/^(\d)/, 'I$1').replace(/-(\d)/g, '$1')
name += suffix
let name = toCapitalCase(fileName)
name = name.replace(/^(\d)/, 'I$1').replace(/-(\d)/g, '$1')
name += suffix

const vue = `
const vue = `
<template>${svg}</template>
<script lang="ts">
import { defineComponent, markRaw } from 'vue'
export default defineComponent(markRaw({ name: '${name}' }))
</script>
`

await writeFile(
resolve(outDir, `${fileName}.vue`),
format(vue, { parser: 'vue', semi: false, singleQuote: true }),
'utf-8'
)
await writeFile(
resolve(outDir, `${fileName}.vue`),
format(vue, { parser: 'vue', semi: false, singleQuote: true }),
'utf-8'
)

exports += `export { default as ${name} } from '.${out ? `/${out}` : ''}/${fileName}.vue'\n`
types += `export const ${name}: SvgIcon\n`
}))
exports += `export { default as ${name} } from '.${out ? `/${out}` : ''}/${fileName}.vue'\n`
types += `export const ${name}: SvgIcon\n`
})
)

console.log(cyan(`generated icon vue components for: ${dir}`))

Expand Down
1 change: 1 addition & 0 deletions common/icons/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { resolve } from 'node:path'
import { readFileSync } from 'node:fs'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

Expand Down
1 change: 1 addition & 0 deletions common/icons/vite.full.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { resolve } from 'node:path'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

Expand Down
14 changes: 4 additions & 10 deletions common/plugins/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'

import { execa } from 'execa'
import { red } from 'kolorist'

Expand All @@ -8,16 +9,9 @@ const rootDir = resolve(fileURLToPath(import.meta.url), '../..')
const bin = (name: string) => resolve(rootDir, 'node_modules/.bin/' + name)

async function main() {
await execa(
bin('tsup-node'),
[
'src/index.ts',
'--dts',
'--format',
'cjs,esm'
],
{ stdio: 'inherit' }
)
await execa(bin('tsup-node'), ['src/index.ts', '--dts', '--format', 'cjs,esm'], {
stdio: 'inherit'
})
}

main().catch(error => {
Expand Down
18 changes: 9 additions & 9 deletions components/breadcrumb/tests/breadcrumb.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ describe('Breadcrumb', () => {
it('items', () => {
const wrapper = mount(() => (
<Breadcrumb>
<BreadcrumbItem>item1</BreadcrumbItem>
<BreadcrumbItem>item2</BreadcrumbItem>
<BreadcrumbItem>{'item1'}</BreadcrumbItem>
<BreadcrumbItem>{'item2'}</BreadcrumbItem>
</Breadcrumb>
))

Expand All @@ -27,8 +27,8 @@ describe('Breadcrumb', () => {
it('separator', () => {
const wrapper = mount(() => (
<Breadcrumb separator={'-'}>
<BreadcrumbItem>item1</BreadcrumbItem>
<BreadcrumbItem>item2</BreadcrumbItem>
<BreadcrumbItem>{'item1'}</BreadcrumbItem>
<BreadcrumbItem>{'item2'}</BreadcrumbItem>
</Breadcrumb>
))

Expand All @@ -39,8 +39,8 @@ describe('Breadcrumb', () => {
const wrapper = mount(() => (
<Breadcrumb>
{{
default: () => <BreadcrumbItem>item</BreadcrumbItem>,
separator: () => <span class={'sep'}>666</span>
default: () => <BreadcrumbItem>{'item'}</BreadcrumbItem>,
separator: () => <span class={'sep'}>{'666'}</span>
}}
</Breadcrumb>
))
Expand All @@ -57,7 +57,7 @@ describe('Breadcrumb', () => {
onSelect
},
slots: {
default: () => <BreadcrumbItem label={'item'}>item</BreadcrumbItem>
default: () => <BreadcrumbItem label={'item'}>{'item'}</BreadcrumbItem>
}
})

Expand All @@ -73,7 +73,7 @@ describe('Breadcrumb', () => {
onSelect
},
slots: {
default: () => <BreadcrumbItem label={'item'}>item</BreadcrumbItem>
default: () => <BreadcrumbItem label={'item'}>{'item'}</BreadcrumbItem>
}
})

Expand All @@ -89,7 +89,7 @@ describe('Breadcrumb', () => {
onSeparatorClick
},
slots: {
default: () => <BreadcrumbItem label={'item'}>item</BreadcrumbItem>
default: () => <BreadcrumbItem label={'item'}>{'item'}</BreadcrumbItem>
}
})

Expand Down
4 changes: 2 additions & 2 deletions components/breadcrumb/tests/ssr.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ describe('SSR for Breadcrumb', () => {
await renderToString(
createSSRApp(() => (
<Breadcrumb>
<BreadcrumbItem>item1</BreadcrumbItem>
<BreadcrumbItem>item2</BreadcrumbItem>
<BreadcrumbItem>{'item1'}</BreadcrumbItem>
<BreadcrumbItem>{'item2'}</BreadcrumbItem>
</Breadcrumb>
))
)
Expand Down
22 changes: 11 additions & 11 deletions components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ export default defineComponent({
slots.loading()
)
: (
<Icon
{...icons.value.loading}
effect={props.loadingEffect || icons.value.loading.effect}
icon={props.loadingIcon || icons.value.loading.icon}
></Icon>
<Icon
{...icons.value.loading}
effect={props.loadingEffect || icons.value.loading.effect}
icon={props.loadingIcon || icons.value.loading.icon}
></Icon>
)}
</div>
)
Expand All @@ -255,9 +255,9 @@ export default defineComponent({
renderLoadingIcon()
)
: (
<div class={nh.be('icon')}>
{slots.icon ? slots.icon() : props.icon ? <Icon icon={props.icon}></Icon> : null}
</div>
<div class={nh.be('icon')}>
{slots.icon ? slots.icon() : props.icon ? <Icon icon={props.icon}></Icon> : null}
</div>
)
}

Expand All @@ -268,9 +268,9 @@ export default defineComponent({
renderLoadingIcon()
)
: (
<div class={nh.be('icon')}>
{slots.icon ? slots.icon() : <Icon icon={props.icon}></Icon>}
</div>
<div class={nh.be('icon')}>
{slots.icon ? slots.icon() : <Icon icon={props.icon}></Icon>}
</div>
)
}

Expand Down
6 changes: 5 additions & 1 deletion components/checkbox/tests/checkbox.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ describe('Checkbox', () => {
const onChange = vi.fn()
const wrapper = mount(() => (
<CheckboxGroup disabled onChange={onChange}>
<Checkbox></Checkbox>,<Checkbox disabled></Checkbox>,<Checkbox disabled={false}></Checkbox>
<Checkbox></Checkbox>
{','}
<Checkbox disabled></Checkbox>
{','}
<Checkbox disabled={false}></Checkbox>
</CheckboxGroup>
))

Expand Down
12 changes: 6 additions & 6 deletions components/contextmenu/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ function renderGroupItem(item: ContextmenuConfig, nh: NameHelper) {
item.renderer()
)
: (
<span class={nh.be('label')} style={{ color: item.color }}>
{item.label || item.key}
</span>
<span class={nh.be('label')} style={{ color: item.color }}>
{item.label || item.key}
</span>
)}
{renderItemShortcut(item, nh)}
<div class={[nh.be('icon'), nh.be('arrow')]}>
Expand Down Expand Up @@ -111,9 +111,9 @@ export function renderItem({ config, nh }: { config: ContextmenuConfig, nh: Name
config.renderer()
)
: (
<span class={nh.be('label')} style={{ color: config.color }}>
{config.label || config.key}
</span>
<span class={nh.be('label')} style={{ color: config.color }}>
{config.label || config.key}
</span>
)}
{renderItemShortcut(config, nh)}
</DropdownItem>
Expand Down
8 changes: 7 additions & 1 deletion components/grid/symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import type { InjectionKey } from 'vue'

export type LayoutProp = number | string | (number | string)[]

export type GridJustify = 'start' | 'end' | 'center' | 'space-around' | 'space-between' | 'space-evenly'
export type GridJustify =
| 'start'
| 'end'
| 'center'
| 'space-around'
| 'space-between'
| 'space-evenly'
export type GridAlign = 'top' | 'middle' | 'bottom' | 'stretch'

export interface CellFlex {
Expand Down
2 changes: 1 addition & 1 deletion components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ export default defineComponent({
renderSlot(slots, 'password', { plain: showPassword.value })
)
: (
<Icon {...passwordIcon.value}></Icon>
<Icon {...passwordIcon.value}></Icon>
)}
</div>
)
Expand Down
Loading

0 comments on commit d9e3451

Please sign in to comment.