Skip to content

Commit 14e4427

Browse files
authored
chore: migrate to eslint (#111)
* chore: migrate to eslint * chore: ignore `vue/one-component-per-file` * chore: fix ts error
1 parent 5fafe8c commit 14e4427

38 files changed

+2246
-744
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
node_modules
3+
examples/vite-ssr
4+
tests/e2e/vite-ssr

.eslintrc.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
node: true,
6+
},
7+
extends: '@antfu/eslint-config',
8+
rules: {
9+
'vue/one-component-per-file': 'off'
10+
},
11+
}

.github/workflows/export-sizes.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
with:
1919
node-version: ${{ matrix.node-version }}
2020
registry-url: https://registry.npmjs.org/
21-
cache: "pnpm"
21+
cache: pnpm
2222
- uses: antfu/export-size-action@v1
2323
with:
2424
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Release
33
on:
44
push:
55
tags:
6-
- "v*"
6+
- 'v*'
77

88
jobs:
99
release:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
test:
11-
if: "!contains(github.event.head_commit.message, 'ci skip')"
11+
if: '!contains(github.event.head_commit.message, ''ci skip'')'
1212

1313
strategy:
1414
matrix:

.prettierrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/nuxt3/app.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<script setup lang="ts">
2-
import { useHead } from "#head"
2+
import { useHead } from '#head'
33
44
useHead({
5-
title: "Title",
6-
titleTemplate: (title) => `${title} | Title Site`,
5+
title: 'Title',
6+
titleTemplate: title => `${title} | Title Site`,
77
})
88
</script>
9+
910
<template>
1011
<div>
1112
<NuxtPage />

examples/nuxt3/components/ModifyTitle.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
const props = defineProps<{
33
title: string
44
}>()
5-
await new Promise((resolve) => setTimeout(resolve, 1000))
5+
await new Promise(resolve => setTimeout(resolve, 1000))
66
77
useHead({
88
title: computed(() => props.title),
99
})
1010
</script>
11+
1112
<template>
1213
<div>final title test</div>
1314
</template>

examples/nuxt3/nuxt.config.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
import { defineNuxtConfig } from "nuxt/config"
2-
import { fileURLToPath } from "url"
3-
import { addPlugin } from "@nuxt/kit"
4-
import { resolve } from "pathe"
1+
import { fileURLToPath } from 'url'
2+
import { defineNuxtConfig } from 'nuxt/config'
3+
import { addPlugin } from '@nuxt/kit'
4+
import { resolve } from 'pathe'
55

6-
const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url))
7-
const rootDir = fileURLToPath(new URL("../../", import.meta.url))
6+
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
7+
const rootDir = fileURLToPath(new URL('../../', import.meta.url))
88

99
// https://v3.nuxtjs.org/api/configuration/nuxt.config
1010
export default defineNuxtConfig({
1111
alias: {
12-
"@vueuse/head": `${rootDir}/src`,
12+
'@vueuse/head': `${rootDir}/src`,
1313
},
1414
app: {
1515
head: {
16-
title: "default title",
16+
title: 'default title',
1717
},
1818
},
1919
workspaceDir: rootDir,
2020
hooks: {
21-
"modules:before": async ({ nuxt }) => {
21+
'modules:before': async ({ nuxt }) => {
2222
const newModules = nuxt.options._modules
2323
// remove the nuxt meta (head) module
2424
for (const k in newModules) {
25-
if (typeof newModules[k] === "function") {
26-
if ((await newModules[k].getMeta()).name === "meta") {
25+
if (typeof newModules[k] === 'function') {
26+
if ((await newModules[k].getMeta()).name === 'meta') {
2727
// we can't use an undefined key so use a duplicate
28-
newModules[k] = "@nuxt/telemetry"
28+
newModules[k] = '@nuxt/telemetry'
2929
}
3030
}
3131
}
3232
nuxt.options._modules = newModules
3333
},
34-
"modules:done"({ nuxt }) {
34+
'modules:done': function ({ nuxt }) {
3535
// Replace #head alias
36-
nuxt.options.alias["#head"] = runtimeDir
36+
nuxt.options.alias['#head'] = runtimeDir
3737

38-
addPlugin({ src: resolve(runtimeDir, "plugin") }, { append: true })
38+
addPlugin({ src: resolve(runtimeDir, 'plugin') }, { append: true })
3939

4040
nuxt.options.build.transpile.push(runtimeDir)
4141
},

examples/nuxt3/pages/index.vue

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
<script lang="ts" setup>
2-
import { useHead } from "#head"
2+
import { useHead } from '#head'
33
44
const page = ref({
5-
title: "Home",
6-
description: "Home page description",
7-
image: "https://nuxtjs.org/meta_400.png",
5+
title: 'Home',
6+
description: 'Home page description',
7+
image: 'https://nuxtjs.org/meta_400.png',
88
})
99
1010
useHead({
1111
title: computed(() => `${page.value.title} | Nuxt`),
1212
meta: [
1313
{
14-
name: "description",
14+
name: 'description',
1515
content: computed(() => page.value.description),
1616
},
1717
{
18-
property: "og:image",
18+
property: 'og:image',
1919
content: computed(() => page.value.image),
2020
},
2121
],
2222
})
2323
</script>
24+
2425
<template>
2526
<div>
2627
<h1>Index</h1>
27-
<nuxt-link to="/second">second page</nuxt-link>
28+
<nuxt-link to="/second">
29+
second page
30+
</nuxt-link>
2831
</div>
2932
</template>

examples/nuxt3/pages/second.vue

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,43 @@
11
<script lang="ts" setup>
2-
await new Promise((resolve) => setTimeout(resolve, 1000))
2+
await new Promise(resolve => setTimeout(resolve, 1000))
33
4-
const title = ref("Intermediately title with 1s delay")
4+
const title = ref('Intermediately title with 1s delay')
55
66
useHead({
77
title,
88
bodyAttrs: {
9-
class: "new-bg",
9+
class: 'new-bg',
1010
},
1111
style: [
1212
// this is an example of the side effects of this rendering strategy
1313
// this style won't be hydrated at all
1414
{
1515
children: `.new-bg { background-color: lemonchiffon; } h2 { color: ${
16-
process.server ? "red" : "lime"
16+
process.server ? 'red' : 'lime'
1717
}; }`,
1818
},
1919
],
2020
})
2121
2222
const changeTitle = () => {
23-
title.value = "Intermediately title updated"
23+
title.value = 'Intermediately title updated'
2424
}
2525
2626
const finalTitle = computed(() => {
27-
return title.value.replace("Intermediately", "Final")
27+
return title.value.replace('Intermediately', 'Final')
2828
})
2929
</script>
30+
3031
<template>
3132
<div>
3233
<h2>second page</h2>
3334
<p>has a 1 second delay on rendering</p>
3435
<ModifyTitle :title="finalTitle" />
35-
<button @click="changeTitle">change title</button>
36-
<nuxt-link to="/">first page</nuxt-link>
36+
<button @click="changeTitle">
37+
change title
38+
</button>
39+
<nuxt-link to="/">
40+
first page
41+
</nuxt-link>
3742
</div>
3843
</template>

examples/nuxt3/runtime/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { HeadObject } from "@vueuse/head"
2-
import { useNuxtApp } from "#app"
1+
import type { HeadObject } from '@vueuse/head'
2+
import { useNuxtApp } from '#app'
33

44
export type MetaObject = HeadObject
55

examples/nuxt3/runtime/plugin.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import { createHead, renderHeadToString } from "@vueuse/head"
1+
import { createHead, renderHeadToString } from '@vueuse/head'
2+
import type { ComputedGetter } from 'vue'
23
import {
34
computed,
5+
getCurrentInstance,
6+
onBeforeUnmount,
47
ref,
58
watchEffect,
6-
onBeforeUnmount,
7-
getCurrentInstance,
8-
ComputedGetter,
9-
} from "vue"
10-
import defu from "defu"
11-
import type { MetaObject } from "."
12-
import { defineNuxtPlugin, useRoute } from "#app"
13-
import { useRouter, watch } from "#imports"
9+
} from 'vue'
10+
import defu from 'defu'
11+
import type { MetaObject } from '.'
12+
import { defineNuxtPlugin } from '#app'
1413

1514
// Note: This is just a copy of Nuxt's internal head plugin with modifications made for this issue
1615

@@ -20,7 +19,7 @@ export default defineNuxtPlugin((nuxtApp) => {
2019
nuxtApp.vueApp.use(head)
2120

2221
const headReady = ref(false)
23-
nuxtApp.hooks.hookOnce("app:mounted", () => {
22+
nuxtApp.hooks.hookOnce('app:mounted', () => {
2423
watchEffect(() => {
2524
head.updateDOM()
2625
})
@@ -31,30 +30,28 @@ export default defineNuxtPlugin((nuxtApp) => {
3130
const meta = ref<MetaObject>(_meta)
3231
const headObj = computed(() => {
3332
const overrides: MetaObject = { meta: [] }
34-
if (meta.value.charset) {
35-
overrides.meta!.push({ key: "charset", charset: meta.value.charset })
36-
}
37-
if (meta.value.viewport) {
38-
overrides.meta!.push({ name: "viewport", content: meta.value.viewport })
39-
}
33+
if (meta.value.charset)
34+
overrides.meta!.push({ key: 'charset', charset: meta.value.charset })
35+
36+
if (meta.value.viewport)
37+
overrides.meta!.push({ name: 'viewport', content: meta.value.viewport })
38+
4039
return defu(overrides, meta.value)
4140
})
4241
head.addHeadObjs(headObj as any)
4342

44-
if (process.server) {
43+
if (process.server)
4544
return
46-
}
4745

48-
if (headReady) {
46+
if (headReady.value) {
4947
watchEffect(() => {
5048
head.updateDOM()
5149
})
5250
}
5351

5452
const vm = getCurrentInstance()
55-
if (!vm) {
53+
if (!vm)
5654
return
57-
}
5855

5956
onBeforeUnmount(() => {
6057
head.removeHeadObjs(headObj as any)

examples/vite-ssr/Contact.vue

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
<script setup>
2-
import { ref } from "vue"
3-
import { Head } from "../../src"
2+
import { ref } from 'vue'
3+
import { Head } from '../../src'
44
55
const count = ref(0)
66
7-
const style = `button {color: red}`
7+
const style = 'button {color: red}'
88
</script>
99

1010
<template>
1111
<Head>
1212
<title>{{ count }}</title>
13-
<html lang="en"></html>
14-
<body class="body"></body>
15-
<meta name="description" content="desc" />
13+
<html lang="en" />
14+
<body class="body" />
15+
<meta name="description" content="desc">
1616
<component is="style">
17-
body { background: lightgreen; } {{ style }}</component
18-
>
17+
body { background: lightgreen; } {{ style }}
18+
</component>
1919
</Head>
2020

21-
<router-link to="/">Back Home</router-link>
21+
<router-link to="/">
22+
Back Home
23+
</router-link>
2224

23-
<hr />
25+
<hr>
2426

25-
<button @click="count++">{{ count }}</button>
27+
<button @click="count++">
28+
{{ count }}
29+
</button>
2630
</template>

0 commit comments

Comments
 (0)