-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
146 additions
and
323 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
packages/checker-eslint/__tests__/__snapshots__/logger.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,68 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`eslint logger > normalizeEslintDiagnostic > get multiple diagnostics 1`] = ` | ||
[ | ||
{ | ||
"checker": "ESLint", | ||
"codeFrame": " [0m [90m 1 |[39m [36mimport[39m { text } [36mfrom[39m [32m'./text'[39m[0m | ||
[0m [90m 2 |[39m[0m | ||
[0m[31m[1m>[22m[39m[90m 3 |[39m [36mvar[39m hello [33m=[39m [32m'Hello'[39m[0m | ||
[0m [90m |[39m [31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[0m | ||
[0m [90m 4 |[39m [36mvar[39m hello1 [33m=[39m [32m'Hello1'[39m[0m | ||
[0m [90m 5 |[39m[0m | ||
[0m [90m 6 |[39m [36mconst[39m rootDom [33m=[39m document[33m.[39mquerySelector([32m'#root'[39m)[33m![39m[0m", | ||
"conclusion": "", | ||
"id": "/Users/vite-plugin-checker/playground/eslint/src/main.ts", | ||
"level": 1, | ||
"loc": { | ||
"end": { | ||
"column": 20, | ||
"line": 3, | ||
}, | ||
"start": { | ||
"column": 1, | ||
"line": 3, | ||
}, | ||
}, | ||
"message": "Unexpected var, use let or const instead. (no-var)", | ||
"stripedCodeFrame": " 1 | import { text } from './text' | ||
2 | | ||
> 3 | var hello = 'Hello' | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
4 | var hello1 = 'Hello1' | ||
5 | | ||
6 | const rootDom = document.querySelector('#root')!", | ||
}, | ||
{ | ||
"checker": "ESLint", | ||
"codeFrame": " [0m [90m 2 |[39m[0m | ||
[0m [90m 3 |[39m [36mvar[39m hello [33m=[39m [32m'Hello'[39m[0m | ||
[0m[31m[1m>[22m[39m[90m 4 |[39m [36mvar[39m hello1 [33m=[39m [32m'Hello1'[39m[0m | ||
[0m [90m |[39m [31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[0m | ||
[0m [90m 5 |[39m[0m | ||
[0m [90m 6 |[39m [36mconst[39m rootDom [33m=[39m document[33m.[39mquerySelector([32m'#root'[39m)[33m![39m[0m | ||
[0m [90m 7 |[39m rootDom[33m.[39minnerHTML [33m=[39m hello [33m+[39m text[0m", | ||
"conclusion": "", | ||
"id": "/Users/vite-plugin-checker/playground/eslint/src/main.ts", | ||
"level": 1, | ||
"loc": { | ||
"end": { | ||
"column": 22, | ||
"line": 4, | ||
}, | ||
"start": { | ||
"column": 1, | ||
"line": 4, | ||
}, | ||
}, | ||
"message": "Unexpected var, use let or const instead. (no-var)", | ||
"stripedCodeFrame": " 2 | | ||
3 | var hello = 'Hello' | ||
> 4 | var hello1 = 'Hello1' | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
5 | | ||
6 | const rootDom = document.querySelector('#root')! | ||
7 | rootDom.innerHTML = hello + text", | ||
}, | ||
] | ||
`; |
55 changes: 55 additions & 0 deletions
55
packages/checker-eslint/__tests__/fixtures/eslintDiagnostic.ts
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,55 @@ | ||
import type { NormalizedDiagnostic } from './../../src/logger' | ||
import type { ESLint } from 'eslint' | ||
|
||
export const error1: NormalizedDiagnostic = { | ||
message: 'Unexpected var, use let or const instead.', | ||
conclusion: '', | ||
codeFrame: | ||
" \u001b[0m \u001b[90m 1 |\u001b[39m \u001b[36mimport\u001b[39m { text } \u001b[36mfrom\u001b[39m \u001b[32m'./text'\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m 2 |\u001b[39m\u001b[0m\n \u001b[0m\u001b[31m\u001b[1m>\u001b[22m\u001b[39m\u001b[90m 3 |\u001b[39m \u001b[36mvar\u001b[39m hello \u001b[33m=\u001b[39m \u001b[32m'Hello'\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m |\u001b[39m \u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m 4 |\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m 5 |\u001b[39m \u001b[36mconst\u001b[39m rootDom \u001b[33m=\u001b[39m document\u001b[33m.\u001b[39mquerySelector(\u001b[32m'#root'\u001b[39m)\u001b[33m!\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m 6 |\u001b[39m rootDom\u001b[33m.\u001b[39minnerHTML \u001b[33m=\u001b[39m hello \u001b[33m+\u001b[39m text\u001b[0m", | ||
stripedCodeFrame: | ||
" 1 | import { text } from './text'\n 2 |\n > 3 | var hello = 'Hello'\n | ^^^^^^^^^^^^^^^^^^^\n 4 |\n 5 | const rootDom = document.querySelector('#root')!\n 6 | rootDom.innerHTML = hello + text", | ||
id: '/Users/vite-plugin-checker/playground/eslint/src/main.ts', | ||
checker: 'ESLint', | ||
loc: { start: { line: 3, column: 1 }, end: { line: 3, column: 20 } }, | ||
level: 1, | ||
} | ||
|
||
export const warning1: NormalizedDiagnostic = { ...error1, level: 0 } | ||
|
||
export const eslintResult1: ESLint.LintResult = { | ||
filePath: '/Users/vite-plugin-checker/playground/eslint/src/main.ts', | ||
messages: [ | ||
{ | ||
ruleId: 'no-var', | ||
severity: 2, | ||
message: 'Unexpected var, use let or const instead.', | ||
line: 3, | ||
column: 1, | ||
nodeType: 'VariableDeclaration', | ||
messageId: 'unexpectedVar', | ||
endLine: 3, | ||
endColumn: 20, | ||
fix: { range: [31, 34], text: 'let' }, | ||
}, | ||
{ | ||
ruleId: 'no-var', | ||
severity: 2, | ||
message: 'Unexpected var, use let or const instead.', | ||
line: 4, | ||
column: 1, | ||
nodeType: 'VariableDeclaration', | ||
messageId: 'unexpectedVar', | ||
endLine: 4, | ||
endColumn: 22, | ||
fix: { range: [51, 54], text: 'let' }, | ||
}, | ||
], | ||
errorCount: 2, | ||
fatalErrorCount: 2, | ||
warningCount: 0, | ||
fixableErrorCount: 2, | ||
fixableWarningCount: 0, | ||
source: | ||
"import { text } from './text'\n\nvar hello = 'Hello'\nvar hello1 = 'Hello1'\n\nconst rootDom = document.querySelector('#root')!\nrootDom.innerHTML = hello + text\n\nexport {}\n", | ||
usedDeprecatedRules: [], | ||
} |
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 { describe, expect, it } from 'vitest' | ||
|
||
import { normalizeEslintDiagnostic } from '../src/logger.js' | ||
import { eslintResult1 } from './fixtures/eslintDiagnostic.js' | ||
|
||
describe('eslint logger', () => { | ||
describe('normalizeEslintDiagnostic', () => { | ||
it('get multiple diagnostics', () => { | ||
const received = normalizeEslintDiagnostic(eslintResult1) | ||
expect(received).toMatchSnapshot() | ||
}) | ||
}) | ||
}) |
2 changes: 1 addition & 1 deletion
2
...ts__/__snapshots__/vlsConfig.spec.ts.snap → ...ts__/__snapshots__/vlsConfig.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
8 changes: 6 additions & 2 deletions
8
...lugin-checker/__tests__/vlsConfig.spec.ts → ...s/checker-vls/__tests__/vlsConfig.spec.ts
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
Oops, something went wrong.