Skip to content

Commit

Permalink
sync #282
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Jan 31, 2024
1 parent cd69aa8 commit 0dbe77d
Show file tree
Hide file tree
Showing 21 changed files with 230 additions and 972 deletions.
4 changes: 2 additions & 2 deletions packages/checker-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
"tiny-invariant": "^1.3.1"
},
"peerDependencies": {
"eslint": "*",
"eslint": "^8.51.0",
"vite-plugin-checker": ">= 0.7.0"
},
"devDependencies": {
"@types/eslint": "^8.44.0",
"eslint": "^8.11.0",
"eslint": "^8.51.0",
"tsup": "^6.7.0",
"vite-plugin-checker": "workspace:*"
}
Expand Down
17 changes: 16 additions & 1 deletion packages/checker-eslint/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Module from 'node:module'
import chokidar from 'chokidar'
import { ESLint } from 'eslint'
import path from 'path'
Expand All @@ -21,6 +22,7 @@ import { normalizeEslintDiagnostic } from './logger.js'
import type { EslintOptions } from './types.js'
import { options as optionator } from './options.js'

const require = Module.createRequire(import.meta.url)
const __filename = fileURLToPath(import.meta.url)

const manager = new FileDiagnosticManager()
Expand Down Expand Up @@ -64,7 +66,20 @@ const createDiagnostic: CreateDiagnostic<EslintOptions> = () => {
...translatedOptions,
...eslintOptions.dev?.overrideConfig,
}
const eslint = new ESLint(finalEslintOptions)

let eslint: ESLint
if (eslintOptions.useFlatConfig) {
const { FlatESLint, shouldUseFlatConfig } = require('eslint/use-at-your-own-risk')
if (shouldUseFlatConfig?.()) {
eslint = new FlatESLint({
cwd: root,
})
} else {
throw Error('Please upgrade your eslint to latest version to use `useFlatConfig` option.')
}
} else {
eslint = new ESLint(finalEslintOptions)
}

const dispatchDiagnostics = () => {
const diagnostics = filterLogLevel(manager.getDiagnostics(), logLevel)
Expand Down
4 changes: 4 additions & 0 deletions packages/checker-eslint/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export type EslintOptions =
* default config for dev mode when options.eslint.dev.eslint is nullable.
*/
lintCommand: string
/**
* @default false
*/
useFlatConfig?: boolean
dev?: Partial<{
/** You can override the options of translated from lintCommand. */
overrideConfig: ESLint.Options
Expand Down
2 changes: 1 addition & 1 deletion playground/config-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/react-dom": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"eslint": "^8.11.0",
"eslint": "^8.51.0",
"typescript": "^5.0.4",
"vite": "^5.0.12",
"vite-plugin-checker": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion playground/config-enableBuild-false/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/react-dom": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"eslint": "^8.11.0",
"eslint": "^8.51.0",
"typescript": "^5.0.4",
"vite": "^5.0.12",
"vite-plugin-checker": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion playground/config-initialIsOpen-error-clean/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/react-dom": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"eslint": "^8.11.0",
"eslint": "^8.51.0",
"typescript": "^5.0.4",
"vite": "^5.0.12",
"@vite-plugin-checker/eslint": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/react-dom": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"eslint": "^8.11.0",
"eslint": "^8.51.0",
"typescript": "^5.0.4",
"vite": "^5.0.12",
"vite-plugin-checker": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion playground/config-initialIsOpen-error/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/react-dom": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"eslint": "^8.11.0",
"eslint": "^8.51.0",
"typescript": "^5.0.4",
"vite": "^5.0.12",
"@vite-plugin-checker/eslint": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion playground/config-initialIsOpen-false/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/react-dom": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"eslint": "^8.11.0",
"eslint": "^8.51.0",
"typescript": "^5.0.4",
"vite": "^5.0.12",
"vite-plugin-checker": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion playground/config-no-runtime-in-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/react-dom": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"eslint": "^8.11.0",
"eslint": "^8.51.0",
"typescript": "^5.0.4",
"vite": "^5.0.12",
"vite-plugin-checker": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion playground/config-overlay-changes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/react-dom": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"eslint": "^8.11.0",
"eslint": "^8.51.0",
"typescript": "^5.0.4",
"vite": "^5.0.12",
"vite-plugin-checker": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion playground/config-overlay-false/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/react-dom": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"eslint": "^8.11.0",
"eslint": "^8.51.0",
"typescript": "^5.0.4",
"vite": "^5.0.12",
"vite-plugin-checker": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion playground/config-overlay-position-style/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/react-dom": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"eslint": "^8.11.0",
"eslint": "^8.51.0",
"typescript": "^5.0.4",
"vite": "^5.0.12",
"vite-plugin-checker": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion playground/config-terminal-false/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/react-dom": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"eslint": "^8.11.0",
"eslint": "^8.51.0",
"typescript": "^5.0.4",
"vite": "^5.0.12",
"vite-plugin-checker": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion playground/eslint-config-log-level/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"devDependencies": {
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"eslint": "^8.11.0",
"eslint": "^8.51.0",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"typescript": "^5.0.4",
Expand Down
2 changes: 1 addition & 1 deletion playground/eslint-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"devDependencies": {
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"eslint": "^8.11.0",
"eslint": "^8.51.0",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"typescript": "^5.0.4",
Expand Down
5 changes: 3 additions & 2 deletions playground/eslint-flat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"devDependencies": {
"eslint": "^8.51.0",
"vite": "^4.3.0",
"vite-plugin-checker": "workspace:*"
"vite": "^5.0.12",
"vite-plugin-checker": "workspace:*",
"@vite-plugin-checker/eslint": "workspace:*"
}
}
11 changes: 6 additions & 5 deletions playground/eslint-flat/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { defineConfig } from 'vite'
import checker from 'vite-plugin-checker'
import { checker } from 'vite-plugin-checker'
import { checker as eslint } from '@vite-plugin-checker/eslint'

export default defineConfig({
plugins: [
checker({
eslint: {
checker([
eslint({
lintCommand: 'eslint "./src/**/*.js"',
useFlatConfig: true,
},
}),
}),
]),
],
})
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`vue-tsc-vue3-ts4 > serve > get initial error and subsequent error 1`] = `"[{\\"checkerId\\":\\"vue-tsc\\",\\"frame\\":\\" 1 | <template>/n 2 | <img alt=/\\"Vue logo/\\" src=/\\"./assets/logo.png/\\" />/n > 3 | <HelloWorld msg1=/\\"Diana/\\" />/n | ^^^^^^^^^^/n 4 | </template>/n 5 |/n 6 | <script lang=/\\"ts/\\">\\",\\"id\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3-ts4/src/App.vue\\",\\"level\\":1,\\"loc\\":{\\"column\\":4,\\"file\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3-ts4/src/App.vue\\",\\"line\\":3},\\"message\\":\\"Argument of type '{ msg1: string; }' is not assignable to parameter of type 'Partial<{}> & Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never> & Record<...>'./n Property 'msg' is missing in type '{ msg1: string; }' but required in type 'Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.\\",\\"stack\\":\\"\\"}]"`;
exports[`vue-tsc-vue3-ts4 > serve > get initial error and subsequent error 1`] = `"[{\\"checkerId\\":\\"vue-tsc\\",\\"frame\\":\\" 1 | <template>/n 2 | <img alt=/\\"Vue logo/\\" src=/\\"./assets/logo.png/\\" />/n > 3 | <HelloWorld msg1=/\\"Diana/\\" />/n | ^^^^^^^^^^/n 4 | </template>/n 5 |/n 6 | <script lang=/\\"ts/\\">\\",\\"id\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3-ts4/src/App.vue\\",\\"level\\":1,\\"loc\\":{\\"column\\":4,\\"file\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3-ts4/src/App.vue\\",\\"line\\":3},\\"message\\":\\"Argument of type '{ msg1: string; }' is not assignable to parameter of type '{ readonly msg: string; style?: unknown; key?: string | number | symbol | undefined; ref?: VNodeRef | undefined; ref_for?: boolean | undefined; ref_key?: string | undefined; onVnodeBeforeMount?: VNodeMountHook | ... 1 more ... | undefined; ... 5 more ...; class?: unknown; } & Record<...>'./n Property 'msg' is missing in type '{ msg1: string; }' but required in type '{ readonly msg: string; style?: unknown; key?: string | number | symbol | undefined; ref?: VNodeRef | undefined; ref_for?: boolean | undefined; ref_key?: string | undefined; onVnodeBeforeMount?: VNodeMountHook | ... 1 more ... | undefined; ... 5 more ...; class?: unknown; }'.\\",\\"stack\\":\\"\\"}]"`;

exports[`vue-tsc-vue3-ts4 > serve > get initial error and subsequent error 2`] = `
"
ERROR(vue-tsc) Argument of type '{ msg1: string; }' is not assignable to parameter of type 'Partial<{}> & Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never> & Record<...>'.
Property 'msg' is missing in type '{ msg1: string; }' but required in type 'Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.
ERROR(vue-tsc) Argument of type '{ msg1: string; }' is not assignable to parameter of type '{ readonly msg: string; style?: unknown; key?: string | number | symbol | undefined; ref?: VNodeRef | undefined; ref_for?: boolean | undefined; ref_key?: string | undefined; onVnodeBeforeMount?: VNodeMountHook | ... 1 more ... | undefined; ... 5 more ...; class?: unknown; } & Record<...>'.
Property 'msg' is missing in type '{ msg1: string; }' but required in type '{ readonly msg: string; style?: unknown; key?: string | number | symbol | undefined; ref?: VNodeRef | undefined; ref_for?: boolean | undefined; ref_key?: string | undefined; onVnodeBeforeMount?: VNodeMountHook | ... 1 more ... | undefined; ... 5 more ...; class?: unknown; }'.
FILE <PROJECT_ROOT>/playground-temp/vue-tsc-vue3-ts4/src/App.vue:3:4
1 | <template>
Expand All @@ -19,12 +19,12 @@ exports[`vue-tsc-vue3-ts4 > serve > get initial error and subsequent error 2`] =
[vue-tsc] Found 1 error. Watching for file changes."
`;
exports[`vue-tsc-vue3-ts4 > serve > get initial error and subsequent error 3`] = `"[{\\"checkerId\\":\\"vue-tsc\\",\\"frame\\":\\" 1 | <template>/n 2 | <img alt=/\\"Vue logo/\\" src=/\\"./assets/logo.png/\\" />/n > 3 | <HelloWorld msg2=/\\"Diana/\\" />/n | ^^^^^^^^^^/n 4 | </template>/n 5 |/n 6 | <script lang=/\\"ts/\\">\\",\\"id\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3-ts4/src/App.vue\\",\\"level\\":1,\\"loc\\":{\\"column\\":4,\\"file\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3-ts4/src/App.vue\\",\\"line\\":3},\\"message\\":\\"Argument of type '{ msg2: string; }' is not assignable to parameter of type 'Partial<{}> & Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never> & Record<...>'./n Property 'msg' is missing in type '{ msg2: string; }' but required in type 'Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.\\",\\"stack\\":\\"\\"}]"`;
exports[`vue-tsc-vue3-ts4 > serve > get initial error and subsequent error 3`] = `"[{\\"checkerId\\":\\"vue-tsc\\",\\"frame\\":\\" 1 | <template>/n 2 | <img alt=/\\"Vue logo/\\" src=/\\"./assets/logo.png/\\" />/n > 3 | <HelloWorld msg2=/\\"Diana/\\" />/n | ^^^^^^^^^^/n 4 | </template>/n 5 |/n 6 | <script lang=/\\"ts/\\">\\",\\"id\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3-ts4/src/App.vue\\",\\"level\\":1,\\"loc\\":{\\"column\\":4,\\"file\\":\\"<PROJECT_ROOT>/playground-temp/vue-tsc-vue3-ts4/src/App.vue\\",\\"line\\":3},\\"message\\":\\"Argument of type '{ msg2: string; }' is not assignable to parameter of type '{ readonly msg: string; style?: unknown; class?: unknown; key?: string | number | symbol | undefined; ref?: VNodeRef | undefined; ref_for?: boolean | undefined; ref_key?: string | undefined; ... 5 more ...; onVnodeUnmounted?: VNodeMountHook | ... 1 more ... | undefined; } & Record<...>'./n Property 'msg' is missing in type '{ msg2: string; }' but required in type '{ readonly msg: string; style?: unknown; class?: unknown; key?: string | number | symbol | undefined; ref?: VNodeRef | undefined; ref_for?: boolean | undefined; ref_key?: string | undefined; onVnodeBeforeMount?: VNodeMountHook | ... 1 more ... | undefined; ... 4 more ...; onVnodeUnmounted?: VNodeMountHook | ... 1 mo...'.\\",\\"stack\\":\\"\\"}]"`;
exports[`vue-tsc-vue3-ts4 > serve > get initial error and subsequent error 4`] = `
"
ERROR(vue-tsc) Argument of type '{ msg2: string; }' is not assignable to parameter of type 'Partial<{}> & Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never> & Record<...>'.
Property 'msg' is missing in type '{ msg2: string; }' but required in type 'Omit<Readonly<ExtractPropTypes<{ msg: { type: StringConstructor; required: true; }; }>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.
ERROR(vue-tsc) Argument of type '{ msg2: string; }' is not assignable to parameter of type '{ readonly msg: string; style?: unknown; class?: unknown; key?: string | number | symbol | undefined; ref?: VNodeRef | undefined; ref_for?: boolean | undefined; ref_key?: string | undefined; ... 5 more ...; onVnodeUnmounted?: VNodeMountHook | ... 1 more ... | undefined; } & Record<...>'.
Property 'msg' is missing in type '{ msg2: string; }' but required in type '{ readonly msg: string; style?: unknown; class?: unknown; key?: string | number | symbol | undefined; ref?: VNodeRef | undefined; ref_for?: boolean | undefined; ref_key?: string | undefined; onVnodeBeforeMount?: VNodeMountHook | ... 1 more ... | undefined; ... 4 more ...; onVnodeUnmounted?: VNodeMountHook | ... 1 mo...'.
FILE <PROJECT_ROOT>/playground-temp/vue-tsc-vue3-ts4/src/App.vue:3:4
1 | <template>
Expand Down

0 comments on commit 0dbe77d

Please sign in to comment.