Skip to content

Commit

Permalink
chore: fix eslint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez committed May 12, 2024
1 parent c62e6b7 commit 35e79ed
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function onClick() {

<template>
<div class="storybook storybook-button">
<MyButton label="" class="classes" :style="style" @click="onClick">
<MyButton label="" :class="classes" :style="style" @click="onClick">
<slot />
</MyButton>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<!-- eslint-disable vue/multi-word-component-names -->
<script setup lang="ts">
import PiniaLogo from '~/components/PiniaLogo.vue'
const props = defineProps({
defineProps({
msg: {
type: String,
required: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- eslint-disable vue/multi-word-component-names -->
<script setup>
defineProps({
message: String,
Expand Down
1 change: 1 addition & 0 deletions packages/storybook-nuxt/playground/pages/about.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- eslint-disable vue/multi-word-component-names -->
<script setup>
defineProps({
msg: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- eslint-disable vue/multi-word-component-names -->
<template>
<div>test-{{ $route.params.id }}</div>
</template>
1 change: 1 addition & 0 deletions packages/storybook-nuxt/playground/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- eslint-disable vue/multi-word-component-names -->
<script setup>
defineProps({
msg: String,
Expand Down
1 change: 1 addition & 0 deletions packages/storybook-nuxt/playground/pages/parent.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- eslint-disable vue/multi-word-component-names -->
<template>
<div>
Parent
Expand Down
1 change: 1 addition & 0 deletions packages/storybook-nuxt/playground/pages/parent/b.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- eslint-disable vue/multi-word-component-names -->
<template>
<div>Parent/b</div>
</template>
1 change: 1 addition & 0 deletions packages/storybook-nuxt/playground/pages/parent/index.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- eslint-disable vue/multi-word-component-names -->
<template>
<div>Parent/index</div>
</template>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
const reloads = useState('reload', () => 0)
// eslint-disable-next-line max-statements-per-line
onMounted(() => {
reloads.value++
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
const reloads = useState('static', () => 0)
// eslint-disable-next-line max-statements-per-line
onMounted(() => {
reloads.value++
})
Expand Down
1 change: 0 additions & 1 deletion packages/storybook-nuxt/playground/stores/counter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line promise/param-names
const delay = (t: number) => new Promise((r) => setTimeout(r, t))

export const useCounter = defineStore('counter', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Story = StoryObj<typeof meta>

export const Home: Story = {
args: {},
render(args: any) {
render(args) {
return {
components: { MyNuxtPage },
setup() {
Expand Down
2 changes: 1 addition & 1 deletion packages/storybook-nuxt/playground/stories/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface Props {
* in external file .
* @file ./types.ts
* @default "Hello World"
* */
*/

a: string
}
59 changes: 27 additions & 32 deletions packages/storybook-nuxt/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ let nuxt: Nuxt
* @param nuxt
*/
function extendComponents(nuxt: Nuxt) {
nuxt.hook('components:extend', (components: any) => {
const nuxtLink = components.find(({ name }: any) => name === 'NuxtLink')
nuxt.hook('components:extend', (components) => {
const nuxtLink = components.find(({ name }) => name === 'NuxtLink')
nuxtLink.filePath = join(runtimeDir, 'components/nuxt-link')
nuxtLink.shortPath = join(runtimeDir, 'components/nuxt-link')
nuxt.options.build.transpile.push(nuxtLink.filePath)
Expand All @@ -50,6 +50,7 @@ async function extendComposables(nuxt: Nuxt) {
})
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
async function defineNuxtConfig(baseConfig: Record<string, any>) {
const { loadNuxt, buildNuxt, addPlugin, extendPages } = await import(
'@nuxt/kit'
Expand Down Expand Up @@ -83,39 +84,31 @@ async function defineNuxtConfig(baseConfig: Record<string, any>) {
mode: 'client',
})
// Add iframe page
extendPages((pages: any) => {
extendPages((pages) => {
pages.push({
name: 'storybook-iframe',
path: '/iframe.html',
})
})

nuxt.hook(
'vite:extendConfig',
(
config: ViteConfig | PromiseLike<ViteConfig> | Record<string, any>,
{ isClient }: any,
) => {
if (isClient) {
const plugins = baseConfig.plugins

// Find the index of the plugin with name 'vite:vue'
const index = plugins.findIndex(
(plugin: any) => plugin.name === 'vite:vue',
)

// Check if the plugin was found
if (index !== -1) {
// Replace the plugin with the new one using vuePlugin()
plugins[index] = vuePlugin()
} else {
plugins.push(vuePlugin())
}
baseConfig.plugins = plugins
extendedConfig = mergeConfig(config, baseConfig)
nuxt.hook('vite:extendConfig', (config, { isClient }) => {
if (isClient) {
const plugins = baseConfig.plugins

// Find the index of the plugin with name 'vite:vue'
const index = plugins.findIndex((plugin) => plugin.name === 'vite:vue')

// Check if the plugin was found
if (index !== -1) {
// Replace the plugin with the new one using vuePlugin()
plugins[index] = vuePlugin()
} else {
plugins.push(vuePlugin())
}
},
)
baseConfig.plugins = plugins
extendedConfig = mergeConfig(config, baseConfig)
}
})
})

await nuxt.ready()
Expand All @@ -127,13 +120,12 @@ async function defineNuxtConfig(baseConfig: Record<string, any>) {
viteConfig: extendedConfig,
nuxt,
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
throw new Error(e)
}
}
export const core: PresetProperty<'core', StorybookConfig> = async (
config: any,
) => {
export const core: PresetProperty<'core', StorybookConfig> = async (config) => {
return {
...config,
builder: '@storybook/builder-vite',
Expand All @@ -152,9 +144,12 @@ export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (
}

export const viteFinal: StorybookConfig['viteFinal'] = async (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
config: Record<string, any>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
options: any,
) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const getStorybookViteConfig = async (c: Record<string, any>, o: any) => {
// const pkgPath = await getPackageDir('@storybook/vue3-vite')
const presetURL = pathToFileURL(
Expand Down Expand Up @@ -199,7 +194,7 @@ export const viteFinal: StorybookConfig['viteFinal'] = async (
})
}

async function getPackageDir(frameworkPackageName: any) {
async function getPackageDir(frameworkPackageName: string) {
// const packageJsonPath = join(frameworkPackageName, 'package.json')

try {
Expand Down
2 changes: 1 addition & 1 deletion packages/storybook-nuxt/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function nuxtAppEntry() {
return vueAppPromise
}

nuxtAppEntry().then((app: any) => {
nuxtAppEntry().then((app) => {
logger.log('nuxtAppEntry done', app)
app()
.then(() => {
Expand Down
13 changes: 8 additions & 5 deletions packages/storybook-nuxt/src/runtime/components/nuxt-link.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable max-statements-per-line */
import type { ComputedRef, DefineComponent, PropType } from 'vue'
import {
computed,
Expand Down Expand Up @@ -69,7 +68,8 @@ export interface NuxtLinkProps {
// https://caniuse.com/requestidlecallback
export const requestIdleCallback: Window['requestIdleCallback'] = import.meta
.server
? ((() => {}) as any)
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
((() => {}) as any)
: globalThis.requestIdleCallback ||
((cb) => {
const start = Date.now()
Expand All @@ -84,7 +84,8 @@ export const requestIdleCallback: Window['requestIdleCallback'] = import.meta

export const cancelIdleCallback: Window['cancelIdleCallback'] = import.meta
.server
? ((() => {}) as any)
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
((() => {}) as any)
: globalThis.cancelIdleCallback ||
((id) => {
clearTimeout(id)
Expand Down Expand Up @@ -252,7 +253,8 @@ export function defineNuxtLink(options: NuxtLinkOptions) {
const el = import.meta.server ? undefined : ref<HTMLElement | null>(null)
const elRef = import.meta.server
? undefined
: (ref: any) => {
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
(ref: any) => {
el!.value = props.custom ? ref?.$el?.nextElementSibling : ref?.$el
}

Expand Down Expand Up @@ -309,7 +311,7 @@ export function defineNuxtLink(options: NuxtLinkOptions) {

return () => {
if (!isExternal.value) {
const routerLinkProps: Record<string, any> = {
const routerLinkProps: Record<string, unknown> = {
ref: elRef,
to: to.value,
activeClass: props.activeClass || options.activeClass,
Expand Down Expand Up @@ -460,6 +462,7 @@ function isSlowConnection() {
if (import.meta.server) return

// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/connection
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const cn = (navigator as any).connection as {
saveData: boolean
effectiveType: string
Expand Down
4 changes: 3 additions & 1 deletion packages/storybook-nuxt/src/runtime/plugins/storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import plugins from '#build/plugins'

import '#build/css'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const globalWindow = window as any
const logger = console

export default defineNuxtPlugin({
name: 'storybook-nuxt-plugin',
enforce: 'pre', // or 'post'

setup(nuxtApp: any) {
setup(nuxtApp) {
logger.log('🔌 🔌 🔌 [storybook-nuxt-plugin] setup ', { nuxtApp })
const nuxtMainApp = getContext('nuxt-app')
if (nuxtMainApp)
Expand All @@ -28,6 +29,7 @@ export default defineNuxtPlugin({
)

if (nuxtApp.globalName !== 'nuxt') return
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const applyNuxtPlugins = async (vueApp: App, storyContext: any) => {
const nuxt = createNuxtApp({
vueApp,
Expand Down
2 changes: 1 addition & 1 deletion packages/storybook-nuxt/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type StorybookConfigFramework = {
* The interface for Storybook configuration in `main.ts` files.
*/
export type StorybookConfig = {
viteFinal?: Record<string, any>
viteFinal?: Record<string, unknown>
} & StorybookConfigFramework
export interface NuxtOptions {}
export { Meta, StoryFn, StoryObj, Preview, VueRenderer, DecoratorFunction }

0 comments on commit 35e79ed

Please sign in to comment.