-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support eslint flat config (#282)
* feat: support eslint flat config * chore: add test * feat: add useFlatConfig option * chore: update * docs: useFlatConfig option for eslint * chore: update changesets
- Loading branch information
Showing
14 changed files
with
440 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'vite-plugin-checker': patch | ||
--- | ||
|
||
support eslint flat config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
playground/eslint-flat/__tests__/__snapshots__/test.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`eslint > serve > get initial error and subsequent error 1`] = `"[{\\"checkerId\\":\\"ESLint\\",\\"frame\\":\\" > 1 | const a = /\\"hello/\\"/n | ^/n > 2 |/n | ^\\",\\"id\\":\\"<PROJECT_ROOT>/playground-temp/eslint-flat/src/index.js\\",\\"level\\":1,\\"loc\\":{\\"column\\":18,\\"file\\":\\"<PROJECT_ROOT>/playground-temp/eslint-flat/src/index.js\\",\\"line\\":1},\\"message\\":\\"Missing semicolon. (semi)\\",\\"stack\\":\\"\\"}]"`; | ||
|
||
exports[`eslint > serve > get initial error and subsequent error 2`] = ` | ||
" ERROR(ESLint) Missing semicolon. (semi) | ||
FILE <PROJECT_ROOT>/playground-temp/eslint-flat/src/index.js:1:18 | ||
> 1 | const a = \\"hello\\" | ||
| ^ | ||
> 2 | | ||
| ^ | ||
[ESLint] Found 1 error and 0 warning" | ||
`; | ||
exports[`eslint > serve > get initial error and subsequent error 3`] = `"[{\\"checkerId\\":\\"ESLint\\",\\"frame\\":\\" > 1 | const a = /\\"hello/\\"/n | ^/n > 2 |/n | ^\\",\\"id\\":\\"<PROJECT_ROOT>/playground-temp/eslint-flat/src/index.js\\",\\"level\\":1,\\"loc\\":{\\"column\\":18,\\"file\\":\\"<PROJECT_ROOT>/playground-temp/eslint-flat/src/index.js\\",\\"line\\":1},\\"message\\":\\"Missing semicolon. (semi)\\",\\"stack\\":\\"\\"}]"`; | ||
exports[`eslint > serve > get initial error and subsequent error 4`] = ` | ||
" ERROR(ESLint) Missing semicolon. (semi) | ||
FILE <PROJECT_ROOT>/playground-temp/eslint-flat/src/index.js:1:18 | ||
> 1 | const a = \\"hello\\" | ||
| ^ | ||
> 2 | | ||
| ^ | ||
[ESLint] Found 1 error and 0 warning" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import stringify from 'fast-json-stable-stringify' | ||
import { describe, expect, it } from 'vitest' | ||
import { | ||
diagnostics, | ||
editFile, | ||
expectStderrContains, | ||
isBuild, | ||
isServe, | ||
log, | ||
resetReceivedLog, | ||
sleepForEdit, | ||
sleepForServerReady, | ||
stripedLog, | ||
} from '../../testUtils' | ||
|
||
describe('eslint', () => { | ||
describe.runIf(isServe)('serve', () => { | ||
it('get initial error and subsequent error', async () => { | ||
await sleepForServerReady() | ||
expect(stringify(diagnostics)).toMatchSnapshot() | ||
expect(stripedLog).toMatchSnapshot() | ||
|
||
console.log('-- edit error file --') | ||
resetReceivedLog() | ||
editFile('src/index.js', (code) => code.replace(`Hello`, `Hello~`)) | ||
await sleepForEdit() | ||
expect(stringify(diagnostics)).toMatchSnapshot() | ||
expect(stripedLog).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe.runIf(isBuild)('build', () => { | ||
const expectedMsg = 'Missing semicolon' | ||
|
||
it('should fail', async () => { | ||
expectStderrContains(log, expectedMsg) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default [ | ||
{ | ||
files: ["src/**/*"], | ||
rules: { | ||
semi: 'error', | ||
}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="src/favicon.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite App</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"private": true, | ||
"name": "@playground/eslint-flat", | ||
"type": "module", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"serve": "vite preview", | ||
"lint": "eslint ." | ||
}, | ||
"devDependencies": { | ||
"eslint": "^8.51.0", | ||
"vite": "^4.3.0", | ||
"vite-plugin-checker": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const a = "hello" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"lib": ["DOM", "DOM.Iterable", "ESNext"], | ||
"types": ["vite/client"], | ||
"allowJs": false, | ||
"skipLibCheck": false, | ||
"esModuleInterop": false, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true | ||
}, | ||
"include": ["./src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { defineConfig } from 'vite' | ||
import checker from 'vite-plugin-checker' | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
checker({ | ||
eslint: { | ||
lintCommand: 'eslint "./src/**/*.js"', | ||
useFlatConfig: true, | ||
}, | ||
}), | ||
], | ||
}) |
Oops, something went wrong.