Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: upgrade eslint and fix lint and type errors #1600

Merged
merged 12 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ import NotFound from './layouts/NotFound.vue'
import './styles/index.scss'

export default defineClientConfig({
enhance({ app, router }) {
enhance() {
// ...
},

setup() {
// ...
},

/* eslint-disable @typescript-eslint/no-unsafe-assignment -- vue sfc type info is not available in eslint scope */
layouts: {
CssModulesLayout,
CustomLayout,
Layout,
NotFound,
},
/* eslint-enable @typescript-eslint/no-unsafe-assignment */

rootComponents: [RootComponentFromTheme],
})
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)

Copy link
Member

@Mister-Hope Mister-Hope Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, I think the original one is fine, and I have seen other repos doing this.

Are there some rules that disallow this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's all fine. Just don't want to add complicated @typescript-eslint/naming-convention override 😮‍💨

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mister-Hope Reverted. It should have been supported in [email protected]

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
20 changes: 10 additions & 10 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { defineConfig, devices } from '@playwright/test'
import { BASE, BUNDLER, isCI, isDev } from './utils/env'
import { BASE, BUNDLER, IS_CI, IS_DEV } from './utils/env'

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

export default defineConfig({
testDir: 'tests',
forbidOnly: isCI,
reporter: isCI ? 'github' : 'line',
retries: isCI ? 2 : 0,
workers: isDev ? 1 : undefined,
forbidOnly: IS_CI,
reporter: IS_CI ? 'github' : 'line',
retries: IS_CI ? 2 : 0,
workers: IS_DEV ? 1 : undefined,
projects: [
{
name: 'chromium',
Expand All @@ -22,8 +22,8 @@ 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,
reuseExistingServer: !IS_CI,
},
})
4 changes: 2 additions & 2 deletions e2e/tests/hmr.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from '@playwright/test'
import { isDev } from '../utils/env'
import { IS_DEV } from '../utils/env'
import { readSourceMarkdown, writeSourceMarkdown } from '../utils/source'

const hmrUpdateTitle = async (): Promise<void> => {
Expand Down Expand Up @@ -33,7 +33,7 @@
)
}

if (isDev) {
if (IS_DEV) {
test.beforeEach(async () => {
await hmrRestore()
})
Expand All @@ -58,7 +58,7 @@

await page.goto('hmr/title.html')

await expect(page).toHaveTitle(/HMR Title/)

Check failure on line 61 in e2e/tests/hmr.spec.ts

View workflow job for this annotation

GitHub Actions / e2e (ubuntu-latest, 22, webpack)

[chromium] › hmr.spec.ts:56:3 › should update title correctly

1) [chromium] › hmr.spec.ts:56:3 › should update title correctly ───────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveTitle(expected) Locator: locator(':root') Expected pattern: /HMR Title/ Received string: "VuePress E2E" Call log: - expect.toHaveTitle with timeout 5000ms - waiting for locator(':root') - locator resolved to <html lang="en-US">…</html> - unexpected value "VuePress E2E" - locator resolved to <html lang="en-US">…</html> - unexpected value "VuePress E2E" - locator resolved to <html lang="en-US">…</html> - unexpected value "VuePress E2E" - locator resolved to <html lang="en-US">…</html> - unexpected value "VuePress E2E" - locator resolved to <html lang="en-US">…</html> - unexpected value "VuePress E2E" - locator resolved to <html lang="en-US">…</html> - unexpected value "VuePress E2E" - locator resolved to <html lang="en-US">…</html> - unexpected value "VuePress E2E" - locator resolved to <html lang="en-US">…</html> - unexpected value "VuePress E2E" - locator resolved to <html lang="en-US">…</html> - unexpected value "VuePress E2E" 59 | await page.goto('hmr/title.html') 60 | > 61 | await expect(page).toHaveTitle(/HMR Title/) | ^ 62 | await expect(titleLocator).toHaveText('HMR Title') 63 | await hmrUpdateTitle() 64 | await expect(page).toHaveTitle(/Updated Title/) at /home/runner/work/core/core/e2e/tests/hmr.spec.ts:61:24
await expect(titleLocator).toHaveText('HMR Title')
await hmrUpdateTitle()
await expect(page).toHaveTitle(/Updated Title/)
Expand All @@ -74,7 +74,7 @@
)

await page.goto('hmr/title.html')
await expect(page).toHaveTitle(/HMR Title/)

Check failure on line 77 in e2e/tests/hmr.spec.ts

View workflow job for this annotation

GitHub Actions / e2e (macos-latest, 22, vite)

[chromium] › hmr.spec.ts:68:3 › should update title and frontmatter correctly after navigation

1) [chromium] › hmr.spec.ts:68:3 › should update title and frontmatter correctly after navigation Error: Timed out 5000ms waiting for expect(locator).toHaveTitle(expected) Locator: locator(':root') Expected pattern: /HMR Title/ Received string: "Updated Title | VuePress E2E" Call log: - expect.toHaveTitle with timeout 5000ms - waiting for locator(':root') - locator resolved to <html lang="en">…</html> - unexpected value "" - locator resolved to <html lang="en">…</html> - unexpected value "" - locator resolved to <html lang="en-US">…</html> - unexpected value "Updated Title | VuePress E2E" - locator resolved to <html lang="en-US">…</html> - unexpected value "Updated Title | VuePress E2E" - locator resolved to <html lang="en-US">…</html> - unexpected value "Updated Title | VuePress E2E" - locator resolved to <html lang="en-US">…</html> - unexpected value "Updated Title | VuePress E2E" - locator resolved to <html lang="en-US">…</html> - unexpected value "Updated Title | VuePress E2E" - locator resolved to <html lang="en-US">…</html> - unexpected value "Updated Title | VuePress E2E" - locator resolved to <html lang="en-US">…</html> - unexpected value "Updated Title | VuePress E2E" 75 | 76 | await page.goto('hmr/title.html') > 77 | await expect(page).toHaveTitle(/HMR Title/) | ^ 78 | await expect(titleLocator).toHaveText('HMR Title') 79 | 80 | // update title page at /Users/runner/work/core/core/e2e/tests/hmr.spec.ts:77:24
await expect(titleLocator).toHaveText('HMR Title')

// update title page
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/imports/conditional-exports.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
test('should load different files correctly', async ({ page }) => {
await page.goto('imports/conditional-exports.html')

await expect(page.locator('.e2e-theme-content p')).toHaveText('browser-mjs')

Check failure on line 7 in e2e/tests/imports/conditional-exports.spec.ts

View workflow job for this annotation

GitHub Actions / e2e (macos-latest, 18, vite)

[chromium] › imports/conditional-exports.spec.ts:4:1 › should load different files correctly

1) [chromium] › imports/conditional-exports.spec.ts:4:1 › should load different files correctly ── Error: Timed out 5000ms waiting for expect(locator).toHaveText(expected) Locator: locator('.e2e-theme-content p') Expected string: "browser-mjs" Received: <element(s) not found> Call log: - expect.toHaveText with timeout 5000ms - waiting for locator('.e2e-theme-content p') 5 | await page.goto('imports/conditional-exports.html') 6 | > 7 | await expect(page.locator('.e2e-theme-content p')).toHaveText('browser-mjs') | ^ 8 | 9 | if (COMMAND === 'build') { 10 | expect( at /Users/runner/work/core/core/e2e/tests/imports/conditional-exports.spec.ts:7:54

if (COMMAND === 'build') {
expect(
await page.evaluate(() =>
fetch('./conditional-exports.html').then((res) => res.text()),
await page.evaluate(async () =>
fetch('./conditional-exports.html').then(async (res) => res.text()),
),
).toContain('<p>node-mjs</p>')
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/router/navigate-by-link.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test.beforeEach(async ({ page }) => {
test.describe('markdown links', () => {
test('should navigate to home correctly', async ({ page }) => {
await page.locator('#markdown-links + ul > li > a').nth(0).click()
await expect(page).toHaveURL(`${BASE}`)
await expect(page).toHaveURL(BASE)
await expect(page.locator('#home-h2')).toHaveText('Home H2')
})

Expand Down Expand Up @@ -46,7 +46,7 @@ test.describe('markdown links', () => {
test.describe('html links', () => {
test('should navigate to home correctly', async ({ page }) => {
await page.locator('#html-links + p > a').nth(0).click()
await expect(page).toHaveURL(`${BASE}`)
await expect(page).toHaveURL(BASE)
await expect(page.locator('#home-h2')).toHaveText('Home H2')
})

Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/router/navigate-by-router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test.beforeEach(async ({ page }) => {

test('should navigate to home correctly', async ({ page }) => {
await page.locator('#home').click()
await expect(page).toHaveURL(`${BASE}`)
await expect(page).toHaveURL(BASE)
await expect(page.locator('#home-h2')).toHaveText('Home H2')
})

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)
}
})
12 changes: 9 additions & 3 deletions e2e/tests/router/resolve-route.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 = [
{
selector: '#index',
expected: {
Expand Down Expand Up @@ -54,13 +54,19 @@ const testCases = [
test('should resolve routes correctly', async ({ page }) => {
await page.goto('router/resolve-route.html')

for (const { selector, expected } of testCases) {
for (const { selector, expected } of TEST_CASES) {
const listItemsLocator = await page
.locator(`.e2e-theme-content ${selector} + ul > li`)
.all()
for (const li of listItemsLocator) {
const textContent = await li.textContent()
const resolvedRoute = JSON.parse(/: (\{.*\})\s*$/.exec(textContent!)![1])
const resolvedRoute = JSON.parse(
/: (\{.*\})\s*$/.exec(textContent!)![1],
) as {
path: string
meta: Record<string, unknown>
notFound: boolean
}
expect(resolvedRoute.path).toEqual(expected.path)
expect(resolvedRoute.meta).toStrictEqual(expected.meta)
expect(resolvedRoute.notFound).toEqual(expected.notFound)
Expand Down
6 changes: 3 additions & 3 deletions e2e/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export const BASE = process.env.E2E_BASE ?? '/'
export const BUNDLER = process.env.E2E_BUNDLER ?? 'vite'
export const COMMAND = process.env.E2E_COMMAND ?? 'dev'

export const isDev = COMMAND === 'dev'
export const isProd = COMMAND === 'build'
export const isCI = !!process.env.CI
export const IS_DEV = COMMAND === 'dev'
export const IS_PROD = COMMAND === 'build'
export const IS_CI = !!process.env.CI
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', '_pageChunk', '_registeredComponents'] },
],
},
},
vue: {
overrides: {
'no-useless-assignment': 'off', // TODO: false positive in vue sfc
},
},
},
{
files: ['**/tests/**'],
rules: {
'import/no-unresolved': 'off',
'no-console': 'off',
'prefer-template': '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.2",
"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
Loading
Loading