Skip to content

Commit

Permalink
fix: upgrade eslint and fix lint and type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Aug 15, 2024
1 parent f88106f commit d255c49
Show file tree
Hide file tree
Showing 71 changed files with 773 additions and 1,322 deletions.
7 changes: 0 additions & 7 deletions .eslintignore

This file was deleted.

26 changes: 0 additions & 26 deletions .eslintrc.cjs

This file was deleted.

5 changes: 3 additions & 2 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ const getSubDirectories = (dir: string): string[] =>
fs
.readdirSync(dir)
.filter((item) => fs.statSync(path.join(dir, item)).isDirectory())
const packages = getSubDirectories(path.resolve(__dirname, 'packages'))

const PACKAGES = getSubDirectories(path.resolve(__dirname, 'packages'))

export default {
extends: ['@commitlint/config-conventional'],
rules: {
'scope-enum': [2, 'always', [...packages, 'e2e']],
'scope-enum': [2, 'always', [...PACKAGES, 'e2e']],
'footer-max-line-length': [0],
},
} satisfies UserConfig
7 changes: 2 additions & 5 deletions e2e/docs/.vuepress/plugins/foo/fooPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { getDirname, path } from 'vuepress/utils'

const __dirname = getDirname(import.meta.url)
const DIRNAME = getDirname(import.meta.url)

export const fooPlugin = {
name: 'test-plugin',
clientConfigFile: path.resolve(
__dirname,
'./nonDefaultExportClientConfig.js',
),
clientConfigFile: path.resolve(DIRNAME, './nonDefaultExportClientConfig.js'),
}
4 changes: 3 additions & 1 deletion e2e/docs/.vuepress/theme/client/layouts/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ const siteData = useSiteData()
</div>
</template>

<style lang="scss" scoped></style>
<style lang="scss" scoped>
// ...
</style>
34 changes: 16 additions & 18 deletions e2e/docs/.vuepress/theme/node/e2eTheme.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import type { Page, Theme } from 'vuepress/core'
import type { Theme } from 'vuepress/core'
import { getDirname, path } from 'vuepress/utils'

const __dirname = getDirname(import.meta.url)
const DIRNAME = getDirname(import.meta.url)

export const e2eTheme = (): Theme => {
return {
name: '@vuepress/theme-e2e',
export const e2eTheme = (): Theme => ({
name: '@vuepress/theme-e2e',

alias: {
// ...
},
alias: {
// ...
},

define: {
// ...
},
define: {
// ...
},

clientConfigFile: path.resolve(__dirname, '../client/config.ts'),
clientConfigFile: path.resolve(DIRNAME, '../client/config.ts'),

extendsPage: (page: Page) => {
// ...
},
extendsPage: () => {
// ...
},

plugins: [],
}
}
plugins: [],
})
4 changes: 2 additions & 2 deletions e2e/modules/conditional-exports/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
declare const str: string
export default str
declare const STR: string
export default STR
8 changes: 4 additions & 4 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defineConfig, devices } from '@playwright/test'
import { BASE, BUNDLER, isCI, isDev } from './utils/env'

const commandPart1 = isDev ? 'docs:dev' : 'docs:build'
const commandPart2 = BUNDLER === 'vite' ? '' : `-${BUNDLER}`
const commandPart3 = isDev ? '' : ' && pnpm docs:serve'
const COMMAND_PART1 = isDev ? 'docs:dev' : 'docs:build'
const COMMAND_PART2 = BUNDLER === 'vite' ? '' : `-${BUNDLER}`
const COMMAND_PART3 = isDev ? '' : ' && pnpm docs:serve'

export default defineConfig({
testDir: 'tests',
Expand All @@ -22,7 +22,7 @@ export default defineConfig({
trace: 'on-first-retry',
},
webServer: {
command: `pnpm docs:clean && pnpm ${commandPart1}${commandPart2}${commandPart3}`,
command: `pnpm docs:clean && pnpm ${COMMAND_PART1}${COMMAND_PART2}${COMMAND_PART3}`,
url: 'http://127.0.0.1:9080',
reuseExistingServer: !isCI,
},
Expand Down
11 changes: 7 additions & 4 deletions e2e/tests/router/resolve-route-query-hash.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from '@playwright/test'

const testCases = [
const TEST_CASES = [
{
path: '/?query=1',
notFound: false,
Expand Down Expand Up @@ -28,8 +28,11 @@ test('should resolve routes when including both the query and hash', async ({

for (const [index, li] of listItemsLocator.entries()) {
const textContent = await li.textContent()
const resolvedRoute = JSON.parse(/: (\{.*\})\s*$/.exec(textContent!)![1])
expect(resolvedRoute.path).toEqual(testCases[index].path)
expect(resolvedRoute.notFound).toEqual(testCases[index].notFound)
const resolvedRoute = JSON.parse(
/: (\{.*\})\s*$/.exec(textContent!)![1],
) as { path: string; notFound: boolean }

expect(resolvedRoute.path).toEqual(TEST_CASES[index].path)
expect(resolvedRoute.notFound).toEqual(TEST_CASES[index].notFound)
}
})
13 changes: 5 additions & 8 deletions e2e/utils/source.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { fs, getDirname, path } from 'vuepress/utils'

const __dirname = getDirname(import.meta.url)
const DIRNAME = getDirname(import.meta.url)

const resolveSourceMarkdownPath = (...args: string[]): string =>
path.resolve(__dirname, '../docs', ...args)
path.resolve(DIRNAME, '../docs', ...args)

export const readSourceMarkdown = async (filePath: string): Promise<string> => {
return fs.readFile(resolveSourceMarkdownPath(filePath), 'utf-8')
}
export const readSourceMarkdown = async (filePath: string): Promise<string> =>
fs.readFile(resolveSourceMarkdownPath(filePath), 'utf-8')

export const writeSourceMarkdown = async (
filePath: string,
content: string,
): Promise<void> => {
return fs.writeFile(resolveSourceMarkdownPath(filePath), content)
}
): Promise<void> => fs.writeFile(resolveSourceMarkdownPath(filePath), content)
41 changes: 41 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { vuepress } from 'eslint-config-vuepress'

const ROOT = path.resolve(fileURLToPath(import.meta.url), '..')
const E2E_DIR = path.resolve(ROOT, 'e2e')
const PACKAGES_DIRS = fs
.readdirSync(path.resolve(ROOT, 'packages'))
.map((item) => `./packages/${item}`)

export default vuepress(
{
imports: {
packageDir: [ROOT, E2E_DIR, ...PACKAGES_DIRS],
},
typescript: {
overrides: {
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'no-underscore-dangle': [
'warn',
{ allow: ['_context', '_registeredComponents'] },
],
},
},
vue: {
overrides: {
'vue/multi-word-component-names': 'off',
'no-useless-assignment': 'off', // TODO: false positive in vue sfc
},
},
},
// {
// files: ['**/tests/**/*.ts', 'e2e/**/*.ts', 'tsup.config.ts'],
// rules: {
// '@typescript-eslint/explicit-function-return-type': 'off',
// 'vue/one-component-per-file': 'off',
// },
// },
)
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"check-types": "vue-tsc --noEmit",
"clean": "pnpm --parallel --stream clean",
"format": "prettier --write .",
"lint": "eslint --ext .cjs,.js,.ts,.vue . && prettier --check .",
"lint:fix": "eslint --fix --ext .cjs,.js,.ts,.vue . && prettier --write .",
"lint": "eslint . && prettier --check .",
"lint:fix": "eslint --fix . && prettier --write .",
"prepare": "husky",
"release": "pnpm release:check && pnpm release:version && pnpm release:publish",
"release:changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
Expand Down Expand Up @@ -39,16 +39,15 @@
"@vitest/coverage-istanbul": "^2.0.5",
"bumpp": "^9.5.1",
"conventional-changelog-cli": "^5.0.0",
"eslint": "^8.57.0",
"eslint-config-vuepress": "^4.10.1",
"eslint-config-vuepress-typescript": "^4.10.1",
"eslint": "^9.9.0",
"eslint-config-vuepress": "^5.1.0",
"husky": "^9.1.4",
"lint-staged": "^15.2.9",
"prettier": "^3.3.3",
"prettier-config-vuepress": "^4.4.0",
"prettier-config-vuepress": "^5.0.0",
"rimraf": "^6.0.1",
"sort-package-json": "^2.10.0",
"tsconfig-vuepress": "^4.5.0",
"tsconfig-vuepress": "^5.0.0",
"tsup": "^8.2.4",
"typescript": "^5.5.4",
"vite": "~5.4.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/bundler-vite/src/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export const build = async (
let serverOutput!: RollupOutput
await withSpinner('Compiling with vite')(async () => {
// create vite config
const clientConfig = await resolveViteConfig({
const clientConfig = resolveViteConfig({
app,
options,
isBuild: true,
isServer: false,
})
const serverConfig = await resolveViteConfig({
const serverConfig = resolveViteConfig({
app,
options,
isBuild: true,
Expand Down
6 changes: 4 additions & 2 deletions packages/bundler-vite/src/build/renderPage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { App, Page } from '@vuepress/core'
import type { VuepressSSRContext } from '@vuepress/shared'
import { fs, renderHead } from '@vuepress/utils'
import type { OutputAsset, OutputChunk, RollupOutput } from 'rollup'
import { ssrContextKey } from 'vue'
import type { App as VueApp } from 'vue'
import { ssrContextKey } from 'vue'
import type { SSRContext } from 'vue/server-renderer'
import type { Router } from 'vue-router'
import { renderPagePrefetchLinks } from './renderPagePrefetchLinks.js'
Expand Down Expand Up @@ -37,8 +38,9 @@ export const renderPage = async ({
await vueRouter.isReady()

// create vue ssr context with default values
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete, no-underscore-dangle
delete vueApp._context.provides[ssrContextKey]
const ssrContext: SSRContext = {
const ssrContext: VuepressSSRContext = {
lang: 'en',
head: [],
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-vite/src/build/renderPagePrefetchLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const renderPagePrefetchLinks = ({
pageChunkFiles: string[]
}): string => {
// shouldPrefetch option
const shouldPrefetch = app.options.shouldPrefetch
const { shouldPrefetch } = app.options

// do not render prefetch links
if (shouldPrefetch === false) {
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-vite/src/build/renderPagePreloadLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const renderPagePreloadLinks = ({
pageChunkFiles: string[]
}): string => {
// shouldPreload option
const shouldPreload = app.options.shouldPreload
const { shouldPreload } = app.options

// do not render preload links
if (shouldPreload === false) {
Expand Down
6 changes: 3 additions & 3 deletions packages/bundler-vite/src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const dev = async (
// plugin hook: extendsBundlerOptions
await app.pluginApi.hooks.extendsBundlerOptions.process(options, app)

const viteConfig = await resolveViteConfig({
const viteConfig = resolveViteConfig({
app,
options,
isBuild: false,
Expand All @@ -24,8 +24,8 @@ export const dev = async (
const server = await createServer(viteConfig)
await server.listen()

const viteVersion = fs.readJsonSync(
require.resolve('vite/package.json'),
const viteVersion = (
fs.readJsonSync(require.resolve('vite/package.json')) as { version: string }
).version
server.config.logger.info(
colors.cyan(`\n vite v${viteVersion}`) +
Expand Down
14 changes: 7 additions & 7 deletions packages/bundler-vite/src/plugins/vuepressMainPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import 'vuepress/client-app'
try {
const postcssConfigResult = await postcssrc()
postcssPlugins = postcssConfigResult.plugins
} catch (error) {
} catch {
postcssPlugins = [autoprefixer]
}

Expand Down Expand Up @@ -164,11 +164,11 @@ const resolveAlias = async ({
// plugin hook: alias
const aliasResult = await app.pluginApi.hooks.alias.process(app, isServer)

aliasResult.forEach((aliasObject) =>
aliasResult.forEach((aliasObject) => {
Object.entries(aliasObject).forEach(([key, value]) => {
alias[key] = value
}),
)
})
})

return [
...Object.keys(alias).map((item) => ({
Expand Down Expand Up @@ -222,11 +222,11 @@ const resolveDefine = async ({
// plugin hook: define
const defineResult = await app.pluginApi.hooks.define.process(app, isServer)

defineResult.forEach((defineObject) =>
defineResult.forEach((defineObject) => {
Object.entries(defineObject).forEach(([key, value]) => {
define[key] = JSON.stringify(value)
}),
)
})
})

return define
}
Loading

0 comments on commit d255c49

Please sign in to comment.