Skip to content

Commit

Permalink
refactor: migrate to eslint.config.ts and format code
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Aug 18, 2024
1 parent 6ff4424 commit 85af10b
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 77 deletions.
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"[markdown]": {
"files.trimTrailingWhitespace": false
},
"typescript.tsdk": "node_modules/typescript/lib",
"eslint.options": {
"flags": ["unstable_ts_config"]
},
"eslint.validate": [
"javascript",
"javascriptreact",
Expand Down Expand Up @@ -41,5 +43,6 @@
"vuepress",
"vueuse",
"zoomable"
]
],
"typescript.tsdk": "node_modules/typescript/lib"
}
10 changes: 1 addition & 9 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import * as fs from 'node:fs'
import * as path from 'node:path'
import type { UserConfig } from '@commitlint/types'

const getSubDirectories = (dir: string): string[] =>
fs
.readdirSync(dir)
.filter((item) => fs.statSync(path.join(dir, item)).isDirectory())

const PACKAGES = getSubDirectories(path.resolve(__dirname, 'packages'))
import { PACKAGES } from './scripts/constants.js'

export default {
extends: ['@commitlint/config-conventional'],
Expand Down
7 changes: 5 additions & 2 deletions e2e/docs/.vuepress/plugins/foo/fooPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
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: 2 additions & 2 deletions e2e/docs/.vuepress/theme/node/e2eTheme.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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 => ({
name: '@vuepress/theme-e2e',
Expand All @@ -14,7 +14,7 @@ export const e2eTheme = (): Theme => ({
// ...
},

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

extendsPage: () => {
// ...
Expand Down
4 changes: 2 additions & 2 deletions e2e/utils/source.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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> =>
fs.readFile(resolveSourceMarkdownPath(filePath), 'utf-8')
Expand Down
41 changes: 0 additions & 41 deletions eslint.config.js

This file was deleted.

43 changes: 43 additions & 0 deletions eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import path from 'node:path'
import { vuepress } from 'eslint-config-vuepress'
import { PACKAGES, ROOT } from './scripts/constants.js'

export default vuepress(
{
imports: {
packageDir: [
ROOT,
path.resolve(ROOT, 'e2e'),
...PACKAGES.map((item) => path.resolve(ROOT, `packages/${item}`)),
],
},
javascript: {
overrides: {
'no-underscore-dangle': [
'warn',
{
allow: [
'__dirname',
'_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',
},
},
)
7 changes: 4 additions & 3 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 . && prettier --check .",
"lint:fix": "eslint --fix . && prettier --write .",
"lint": "eslint --flag unstable_ts_config . && prettier --check .",
"lint:fix": "eslint --flag unstable_ts_config --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 All @@ -24,7 +24,7 @@
"lint-staged": {
"*.!(cjs|js|ts|vue)": "prettier --write --ignore-unknown",
"*.(cjs|js|ts|vue)": [
"eslint --fix",
"eslint --flag unstable_ts_config --fix",
"prettier --write"
],
"package.json": "sort-package-json"
Expand All @@ -42,6 +42,7 @@
"eslint": "^9.9.0",
"eslint-config-vuepress": "^5.1.4",
"husky": "^9.1.4",
"jiti": "^1.21.6",
"lint-staged": "^15.2.9",
"prettier": "^3.3.3",
"prettier-config-vuepress": "^5.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/types/internal/clientConfigs.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ClientConfig } from '../clientConfig.js'

declare module '@internal/clientConfigs' {
// eslint-disable-next-line @typescript-eslint/naming-convention
export const clientConfigs: ClientConfig[]
}
4 changes: 2 additions & 2 deletions packages/shared/tests/routes/resolveLocalePath.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, it } from 'vitest'
import type { LocaleConfig } from '../../src/index.js'
import { resolveLocalePath } from '../../src/index.js'

const locales: LocaleConfig = {
const LOCALES: LocaleConfig = {
'/': {
lang: 'en-US',
},
Expand All @@ -29,6 +29,6 @@ const TEST_CASES: [string, string][] = [

TEST_CASES.forEach(([routePath, expected]) => {
it(routePath, () => {
expect(resolveLocalePath(locales, routePath)).toEqual(expected)
expect(resolveLocalePath(LOCALES, routePath)).toEqual(expected)
})
})
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions scripts/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

export const ROOT = path.resolve(fileURLToPath(import.meta.url), '../..')
export const PACKAGES = fs.readdirSync(path.resolve(ROOT, 'packages'))
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "./tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"declaration": false,
"jsx": "preserve",
"paths": {
"@internal/*": ["./packages/client/src/types/internal/*.d.ts"],
Expand All @@ -14,8 +15,8 @@
"**/.vuepress/**/*",
"e2e/**/*",
"packages/**/*",
"commitlint.config.ts",
"vitest.config.ts"
"scripts/**/*",
"*.config.ts"
],
"exclude": ["node_modules", ".temp", "lib", "dist"]
}
13 changes: 1 addition & 12 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vitest/config'

const getSubDirectories = (dir: string): string[] =>
fs
.readdirSync(dir)
.filter((item) => fs.statSync(path.join(dir, item)).isDirectory())

const ROOT = path.dirname(fileURLToPath(import.meta.url))
const PACKAGES = getSubDirectories(path.resolve(ROOT, 'packages')).filter(
(item) => item !== 'vuepress',
)
import { PACKAGES, ROOT } from './scripts/constants.js'

export default defineConfig({
resolve: {
Expand Down

0 comments on commit 85af10b

Please sign in to comment.