Skip to content

Commit

Permalink
chore: eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
ForkKILLET committed Dec 9, 2023
1 parent 4057d74 commit 9f4f763
Show file tree
Hide file tree
Showing 78 changed files with 1,040 additions and 420 deletions.
31 changes: 31 additions & 0 deletions frontend/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
extends:
- 'plugin:vue/vue3-recommended'
- 'eslint:recommended'
- 'plugin:@typescript-eslint/recommended'
- '@vue/eslint-config-typescript'

ignorePatterns:
- dist/*

parser: 'vue-eslint-parser'

parserOptions:
parser: '@typescript-eslint/parser'

rules:
'semi': [ 'warn', 'never' ]
'no-empty': 'off'
'no-unused-vars': 'off'
'no-constant-condition': [ 'error', { checkLoops: false } ]
'vue/html-indent': [ 'warn', 4 ]
'vue/no-mutating-props': 'off'
'vue/multi-word-component-names': 'off'
'vue/require-v-for-key': 'off'
'vue/no-deprecated-filter': 'off'
'vue/valid-v-model': 'off'
'vue/no-template-shadow': 'off'
'@typescript-eslint/no-unused-vars': [ 'error', { varsIgnorePattern: '^_' } ]
'@typescript-eslint/no-non-null-assertion': 'off'
'@typescript-eslint/no-empty-interface': 'off'
'@typescript-eslint/ban-types': 'off'
'@typescript-eslint/no-explicit-any': 'off'
10 changes: 8 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
"dev": "VITE_BUILD_ENV=\"$(uname -sr)\" VITE_LAST_COMMIT=\"$(git log -1 HEAD --oneline --no-color --no-decorate)\" vite --port 1635",
"check": "vue-tsc --noEmit",
"build": "vue-tsc --noEmit && VITE_BUILD_TIME=\"$(date -R)\" VITE_BUILD_ENV=\"$(uname -sr)\" VITE_LAST_COMMIT=\"$(git log -1 HEAD --oneline --no-color --no-decorate)\" vite build",
"preview": "vite preview",
"compress": "pnpm -F nyadict-frontend-script compress -i ../src/types/index.ts -b @type -o ../src/utils/compress.ts"
"preview": "vite preview",
"compress": "pnpm -F nyadict-frontend-script compress -i ../src/types/index.ts -b @type -o ../src/utils/compress.ts",
"lint": "eslint --ext .ts,.vue ."
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.4.2",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"@fortawesome/vue-fontawesome": "^3.0.3",
"@typescript-eslint/parser": "^5.62.0",
"@vueuse/components": "^10.5.0",
"@vueuse/core": "^10.5.0",
"axios": "^1.5.1",
"d3-force": "^3.0.0",
"d3-interpolate": "^3.0.1",
"dayjs": "^1.11.10",
"eslint-plugin-vue": "^9.19.2",
"json5": "^2.2.3",
"jwt-decode": "^3.1.2",
"mitt": "^3.0.1",
Expand All @@ -34,8 +37,11 @@
"@types/d3-force": "^3.0.6",
"@types/d3-interpolate": "^3.0.2",
"@types/wanakana": "^4.0.4",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@vitejs/plugin-vue": "^4.4.0",
"@vue/eslint-config-typescript": "^12.0.0",
"@vue/runtime-core": "^3.3.4",
"eslint": "^8.51.0",
"typescript": "^5.2.2",
"vite": "^4.4.11",
"vue-tsc": "^1.8.19"
Expand Down
17 changes: 7 additions & 10 deletions frontend/scripts/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type TypeToCompress = {
}

function compress(file: string, base: string): string {
let program = ts.createProgram([ file ], {})
const program = ts.createProgram([ file ], {})
const f = program.getSourceFile(file)

const typeDefs: Record<string, TypeToCompress> = {}
Expand Down Expand Up @@ -105,18 +105,18 @@ function compress(file: string, base: string): string {
log('Generating', typeName)


let compressTypes: string[] = []
const compressTypes: string[] = []
let typeCode = ''
let serCode = ''
let deserCode = ''

const typeDef = typeDefs[typeName]

if (typeDef.kind === ts.SyntaxKind.TypeLiteral) {
let serInputs: string[] = []
let deserInputs: string[] = []
let serOutputs: string[] = []
let deserOutputs: string[] = []
const serInputs: string[] = []
const deserInputs: string[] = []
const serOutputs: string[] = []
const deserOutputs: string[] = []

for (const propName in typeDef.propMap) {
const { newName, question, typeNode } = typeDef.propMap[propName]
Expand Down Expand Up @@ -172,13 +172,12 @@ function compress(file: string, base: string): string {
}

else if (typeDef.kind === ts.SyntaxKind.UnionType) {
let branches: { branchTypeText: string, tagTypeText: string }[] = []
const branches: { branchTypeText: string, tagTypeText: string }[] = []

const tagName = typeDef.tag
let newTagName: string

typeDef.node.forEachChild(branch => {
let branchIndex = 0
if (ts.isTypeReferenceNode(branch)) {
const branchTypeText = branch.getText(f)
const branchTypeDef = typeDefs[branchTypeText]
Expand All @@ -191,8 +190,6 @@ function compress(file: string, base: string): string {
const tagTypeText = tagProp.typeNode.getText(f)
branches.push({ branchTypeText, tagTypeText })
}

branchIndex ++
}
})

Expand Down
7 changes: 5 additions & 2 deletions frontend/src/components/ActionPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ const onSubmit = () => {
<div class="content card">
<div class="panel">
<h2>{{ title }}</h2>
<slot></slot>
<slot />
<div>
<button @click="onSubmit" class="card square inline light">
<button
class="card square inline light"
@click="onSubmit"
>
<fa-icon
:icon="pending ? 'spinner' : 'arrow-right'"
:spin="pending"
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/components/ArchiveEdition.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ defineProps<{

<template>
<span class="archive-edition">
<NyaDate :date="edition.time" format="MM-DD hh:mm" />
<NyaDate
:date="edition.time"
format="MM-DD hh:mm"
/>
@ <span class="archive-device">{{ edition.device }}</span>
<slot></slot>
<slot />
</span>
</template>

Expand Down
63 changes: 45 additions & 18 deletions frontend/src/components/ArchiveInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,57 +39,84 @@ const tailEdition = computed(() => props.info?.editionChain?.at(- 1))
:class="{ barber: active, message: ! info }"
>
<template v-if="isImporting">
<div class="archive-importing-mask-switch" v-if="id">
<fa-icon icon="eye" class="button" />
<div
v-if="id"
class="archive-importing-mask-switch"
>
<fa-icon
icon="eye"
class="button"
/>
</div>
<div
class="archive message importing-mask card"
>
<div>
<span class="id">{{ id ?? '新' }}</span>
<LongPressButton
@long-press="emit('upload-here')"
icon="file-import"
color="var(--color-fg)"
desc="アップロード"
:delay=".5"
@long-press="emit('upload-here')"
/>
</div>
</div>
</template>
<template v-if="info">
<div class="archive-content">
<div class="archive-header">
<span v-if="id !== undefined" class="id">{{ id }}</span>
<span
v-if="id !== undefined"
class="id"
>{{ id }}</span>
<div class="archive-title">
<NyaConfirmInput
v-model="info.title"
:disabled="remote"
/>
</div>
</div>
<div v-if="tailEdition" class="archive-tail">
<fa-icon icon="code-branch" :fixed-width="true" />
<RouterLink :to="{
path: '/sync/tree',
query: {
id,
remote: remote ? '' : undefined
}
}" class="no-animation">
<div
v-if="tailEdition"
class="archive-tail"
>
<fa-icon
icon="code-branch"
:fixed-width="true"
/>
<RouterLink
:to="{
path: '/sync/tree',
query: {
id,
remote: remote ? '' : undefined
}
}"
class="no-animation"
>
<ArchiveEdition :edition="tailEdition" />
</RouterLink>
</div>
<div>
<fa-icon icon="folder" :fixed-width="true" />
<fa-icon
icon="folder"
:fixed-width="true"
/>
<span><span class="number">{{ info.wordCount ?? 'N/A' }}</span> 単語</span>
</div>
<div>
<fa-icon icon="box" :fixed-width="true" />
<fa-icon
icon="box"
:fixed-width="true"
/>
<span><span class="number">{{ (info.size / 1024).toFixed(2) }}</span> KiB</span>
</div>
<div>
<fa-icon icon="code" :fixed-width="true" />
<fa-icon
icon="code"
:fixed-width="true"
/>
<span>
v<span class="number">{{ info.version ?? '?' }}</span>
<span v-if="info?.version && info.version !== ARCHIVE_VERSION">
Expand All @@ -99,14 +126,14 @@ const tailEdition = computed(() => props.info?.editionChain?.at(- 1))
</div>
</div>
<div class="archive-action">
<slot></slot>
<slot />
</div>
</template>
<template v-else-if="noInfoReason">
<span class="no-info-reason">{{ noInfoReasons[noInfoReason] }}</span>
</template>
<div class="archive-labels">
<slot name="labels"></slot>
<slot name="labels" />
</div>
</div>
</template>
Expand Down
48 changes: 34 additions & 14 deletions frontend/src/components/ArchiveList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,35 @@ watch(route, ({ path }) => {
}}</span> アーカイブ

<label for="file">
<fa-icon icon="file-arrow-up" class="button" />
<fa-icon
icon="file-arrow-up"
class="button"
/>
</label>
<input id="file" type="file" accept=".json" @change="onSelectFile" />
<input
id="file"
type="file"
accept=".json"
@change="onSelectFile"
>

<fa-icon @click="create" icon="circle-plus" class="button" />

<fa-icon @click="archiveStore.fetchRemoteArchivesInfo(true)" icon="rotate" class="button" />
<fa-icon
icon="circle-plus"
class="button"
@click="create"
/>

<fa-icon
icon="rotate"
class="button"
@click="archiveStore.fetchRemoteArchivesInfo(true)"
/>
</p>
<div class="archive-list-entries scroll-y">
<div v-if="selectedFile && selectedTitle" class="archive-entry">
<div
v-if="selectedFile && selectedTitle"
class="archive-entry"
>
<ArchiveInfo
id="アップ"
:info="{
Expand All @@ -231,8 +250,9 @@ watch(route, ({ path }) => {
}"
>
<fa-icon
icon="trash"
class="button"
@click="selectedFile = undefined"
icon="trash" class="button"
/>
</ArchiveInfo>

Expand All @@ -248,55 +268,55 @@ watch(route, ({ path }) => {
class="archive-entry"
>
<ArchiveInfo
:active="id === currentId"
:id="id"
:active="id === currentId"
:info="local"
:no-info-reason="'no-local'"
:is-importing="!! selectedFile"
@upload-here="imports(id)"
>
<fa-icon
@click="currentId !== id && (currentId = id)"
class="button"
:icon="currentId === id ? 'flag-checkered' : 'flag'"
:fixed-width="true"
@click="currentId !== id && (currentId = id)"
/>
<fa-icon
@click="(event: MouseEvent) => exports(id, event.shiftKey)"
class="button"
icon="file-arrow-down"
:fixed-width="true"
@click="(event: MouseEvent) => exports(id, event.shiftKey)"
/>
<LongPressButton
@long-press="push(id, state)"
:icon="pushIcon"
color="var(--color-fg)"
desc="プッシュ"
:delay=".5"
@long-press="push(id, state)"
/>
<LongPressButton
@long-press="withdraw(id)"
icon="trash"
color="var(--color-wrong)"
desc="削除"
:delay="1.5"
@long-press="withdraw(id)"
/>
</ArchiveInfo>

<ArchiveInfo
:active="false"
:id="remote?.idPerUser"
:active="false"
:remote="true"
:info="remote"
:no-info-reason="jwtPayload ? 'no-remote' : 'no-account'"
>
<template #default>
<LongPressButton
@long-press="pull(id, state)"
:icon="pullIcon"
color="var(--color-fg)"
desc="プル"
:delay=".5"
@long-press="pull(id, state)"
/>
</template>
<template #labels>
Expand Down
Loading

0 comments on commit 9f4f763

Please sign in to comment.