-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ESLint can report multiple errors
- Loading branch information
Showing
14 changed files
with
449 additions
and
20 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { NormalizedDiagnostic } from './logger' | ||
|
||
class FileDiagnosticManager { | ||
public diagnostics: NormalizedDiagnostic[] = [] | ||
|
||
public initWith(diagnostics: NormalizedDiagnostic[]) { | ||
diagnostics.forEach((d) => { | ||
this.diagnostics.push(d) | ||
}) | ||
} | ||
|
||
public getDiagnostics(fileName?: string) { | ||
if (fileName) { | ||
return this.diagnostics.filter((f) => f.id === fileName) | ||
} | ||
|
||
return this.diagnostics | ||
} | ||
|
||
// public get lastDiagnostic() { | ||
// return this.diagnostics[this.diagnostics.length - 1] | ||
// } | ||
|
||
public setFile(fileName: string, next: NormalizedDiagnostic[] | null) { | ||
for (let i = 0; i < this.diagnostics.length; i++) { | ||
if (this.diagnostics[i].id === fileName) { | ||
this.diagnostics.splice(i, 1) | ||
i-- | ||
} | ||
} | ||
|
||
if (next?.length) { | ||
this.diagnostics.push(...next) | ||
} | ||
} | ||
|
||
// public updateFile(next: NormalizedDiagnostic[] | null) { | ||
// for (let i = 0; i < this.diagnostics.length; i++) { | ||
// if (this.diagnostics[i].loc?.start.line === fileName) { | ||
// this.diagnostics.splice(i, 1) | ||
// i-- | ||
// } | ||
// } | ||
|
||
// if (next?.length) { | ||
// this.diagnostics.push(...next) | ||
// } | ||
// } | ||
} | ||
|
||
export { FileDiagnosticManager } |
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
148 changes: 148 additions & 0 deletions
148
playground/multiple/__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,148 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`multiple serve get initial error and subsequent error 1`] = `"[{\\"frame\\":\\" 1 | import { text } from './text'/n 2 |/n > 3 | var hello1: number = 'Hello1'/n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/n 4 | var hello2: boolean = 'Hello2'/n 5 |/n 6 | const rootDom = document.querySelector('#root')!\\",\\"id\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"loc\\":{\\"column\\":1,\\"file\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"line\\":3},\\"message\\":\\"Unexpected var, use let or const instead.\\",\\"plugin\\":\\"ESLint\\",\\"stack\\":\\"\\"},{\\"frame\\":\\" 2 |/n 3 | var hello1: number = 'Hello1'/n > 4 | var hello2: boolean = 'Hello2'/n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/n 5 |/n 6 | const rootDom = document.querySelector('#root')!/n 7 | rootDom.innerHTML = hello1 + text\\",\\"id\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"loc\\":{\\"column\\":1,\\"file\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"line\\":4},\\"message\\":\\"Unexpected var, use let or const instead.\\",\\"plugin\\":\\"ESLint\\",\\"stack\\":\\"\\"},{\\"frame\\":\\" 1 | import { text } from './text'/n 2 |/n > 3 | var hello1: number = 'Hello1'/n | ^^^^^^/n 4 | var hello2: boolean = 'Hello2'/n 5 |/n 6 | const rootDom = document.querySelector('#root')!\\",\\"id\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"loc\\":{\\"column\\":5,\\"file\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"line\\":3},\\"message\\":\\"Type 'string' is not assignable to type 'number'.\\",\\"plugin\\":\\"TypeScript\\",\\"stack\\":\\"\\"},{\\"frame\\":\\" 2 |/n 3 | var hello1: number = 'Hello1'/n > 4 | var hello2: boolean = 'Hello2'/n | ^^^^^^/n 5 |/n 6 | const rootDom = document.querySelector('#root')!/n 7 | rootDom.innerHTML = hello1 + text\\",\\"id\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"loc\\":{\\"column\\":5,\\"file\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"line\\":4},\\"message\\":\\"Type 'string' is not assignable to type 'boolean'.\\",\\"plugin\\":\\"TypeScript\\",\\"stack\\":\\"\\"}]"`; | ||
|
||
exports[`multiple serve get initial error and subsequent error 2`] = ` | ||
" ERROR(ESLint) Unexpected var, use let or const instead. | ||
FILE <PROJECT_ROOT>/temp/multiple/src/main.ts:3:1 | ||
1 | import { text } from './text' | ||
2 | | ||
> 3 | var hello1: number = 'Hello1' | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
4 | var hello2: boolean = 'Hello2' | ||
5 | | ||
6 | const rootDom = document.querySelector('#root')! | ||
ERROR(ESLint) Unexpected var, use let or const instead. | ||
FILE <PROJECT_ROOT>/temp/multiple/src/main.ts:4:1 | ||
2 | | ||
3 | var hello1: number = 'Hello1' | ||
> 4 | var hello2: boolean = 'Hello2' | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
5 | | ||
6 | const rootDom = document.querySelector('#root')! | ||
7 | rootDom.innerHTML = hello1 + text | ||
ERROR(TypeScript) Type 'string' is not assignable to type 'number'. | ||
FILE <PROJECT_ROOT>/temp/multiple/src/main.ts:3:5 | ||
1 | import { text } from './text' | ||
2 | | ||
> 3 | var hello1: number = 'Hello1' | ||
| ^^^^^^ | ||
4 | var hello2: boolean = 'Hello2' | ||
5 | | ||
6 | const rootDom = document.querySelector('#root')! | ||
ERROR(TypeScript) Type 'string' is not assignable to type 'boolean'. | ||
FILE <PROJECT_ROOT>/temp/multiple/src/main.ts:4:5 | ||
2 | | ||
3 | var hello1: number = 'Hello1' | ||
> 4 | var hello2: boolean = 'Hello2' | ||
| ^^^^^^ | ||
5 | | ||
6 | const rootDom = document.querySelector('#root')! | ||
7 | rootDom.innerHTML = hello1 + text | ||
Found 2 errors. Watching for file changes." | ||
`; | ||
exports[`multiple serve get initial error and subsequent error 3`] = `"[{\\"frame\\":\\" 1 | import { text } from './text'/n 2 |/n > 3 | var hello1: number = 'Hello1~'/n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/n 4 | var hello2: boolean = 'Hello2'/n 5 |/n 6 | const rootDom = document.querySelector('#root')!\\",\\"id\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"loc\\":{\\"column\\":1,\\"file\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"line\\":3},\\"message\\":\\"Unexpected var, use let or const instead.\\",\\"plugin\\":\\"ESLint\\",\\"stack\\":\\"\\"},{\\"frame\\":\\" 2 |/n 3 | var hello1: number = 'Hello1~'/n > 4 | var hello2: boolean = 'Hello2'/n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/n 5 |/n 6 | const rootDom = document.querySelector('#root')!/n 7 | rootDom.innerHTML = hello1 + text\\",\\"id\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"loc\\":{\\"column\\":1,\\"file\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"line\\":4},\\"message\\":\\"Unexpected var, use let or const instead.\\",\\"plugin\\":\\"ESLint\\",\\"stack\\":\\"\\"},{\\"frame\\":\\" 1 | import { text } from './text'/n 2 |/n > 3 | var hello1: number = 'Hello1~'/n | ^^^^^^/n 4 | var hello2: boolean = 'Hello2'/n 5 |/n 6 | const rootDom = document.querySelector('#root')!\\",\\"id\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"loc\\":{\\"column\\":5,\\"file\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"line\\":3},\\"message\\":\\"Type 'string' is not assignable to type 'number'.\\",\\"plugin\\":\\"TypeScript\\",\\"stack\\":\\"\\"},{\\"frame\\":\\" 2 |/n 3 | var hello1: number = 'Hello1~'/n > 4 | var hello2: boolean = 'Hello2'/n | ^^^^^^/n 5 |/n 6 | const rootDom = document.querySelector('#root')!/n 7 | rootDom.innerHTML = hello1 + text\\",\\"id\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"loc\\":{\\"column\\":5,\\"file\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"line\\":4},\\"message\\":\\"Type 'string' is not assignable to type 'boolean'.\\",\\"plugin\\":\\"TypeScript\\",\\"stack\\":\\"\\"}]"`; | ||
exports[`multiple serve get initial error and subsequent error 4`] = ` | ||
" ERROR(ESLint) Unexpected var, use let or const instead. | ||
FILE <PROJECT_ROOT>/temp/multiple/src/main.ts:3:1 | ||
1 | import { text } from './text' | ||
2 | | ||
> 3 | var hello1: number = 'Hello1~' | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
4 | var hello2: boolean = 'Hello2' | ||
5 | | ||
6 | const rootDom = document.querySelector('#root')! | ||
ERROR(ESLint) Unexpected var, use let or const instead. | ||
FILE <PROJECT_ROOT>/temp/multiple/src/main.ts:4:1 | ||
2 | | ||
3 | var hello1: number = 'Hello1~' | ||
> 4 | var hello2: boolean = 'Hello2' | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
5 | | ||
6 | const rootDom = document.querySelector('#root')! | ||
7 | rootDom.innerHTML = hello1 + text | ||
ERROR(TypeScript) Type 'string' is not assignable to type 'number'. | ||
FILE <PROJECT_ROOT>/temp/multiple/src/main.ts:3:5 | ||
1 | import { text } from './text' | ||
2 | | ||
> 3 | var hello1: number = 'Hello1~' | ||
| ^^^^^^ | ||
4 | var hello2: boolean = 'Hello2' | ||
5 | | ||
6 | const rootDom = document.querySelector('#root')! | ||
ERROR(TypeScript) Type 'string' is not assignable to type 'boolean'. | ||
FILE <PROJECT_ROOT>/temp/multiple/src/main.ts:4:5 | ||
2 | | ||
3 | var hello1: number = 'Hello1~' | ||
> 4 | var hello2: boolean = 'Hello2' | ||
| ^^^^^^ | ||
5 | | ||
6 | const rootDom = document.querySelector('#root')! | ||
7 | rootDom.innerHTML = hello1 + text | ||
Found 2 errors. Watching for file changes." | ||
`; | ||
exports[`multiple serve get initial error and subsequent error 5`] = `"[{\\"frame\\":\\" 1 | import { text } from './text'/n 2 |/n > 3 | var hello1: number = 'Hello1~'/n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/n 4 | var hello2: boolean = 'Hello2'/n 5 |/n 6 | const rootDom = document.querySelector('#root')!\\",\\"id\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"loc\\":{\\"column\\":1,\\"file\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"line\\":3},\\"message\\":\\"Unexpected var, use let or const instead.\\",\\"plugin\\":\\"ESLint\\",\\"stack\\":\\"\\"},{\\"frame\\":\\" 2 |/n 3 | var hello1: number = 'Hello1~'/n > 4 | var hello2: boolean = 'Hello2'/n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/n 5 |/n 6 | const rootDom = document.querySelector('#root')!/n 7 | rootDom.innerHTML = hello1 + text\\",\\"id\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"loc\\":{\\"column\\":1,\\"file\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"line\\":4},\\"message\\":\\"Unexpected var, use let or const instead.\\",\\"plugin\\":\\"ESLint\\",\\"stack\\":\\"\\"},{\\"frame\\":\\" 1 | import { text } from './text'/n 2 |/n > 3 | var hello1: number = 'Hello1~'/n | ^^^^^^/n 4 | var hello2: boolean = 'Hello2'/n 5 |/n 6 | const rootDom = document.querySelector('#root')!\\",\\"id\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"loc\\":{\\"column\\":5,\\"file\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"line\\":3},\\"message\\":\\"Type 'string' is not assignable to type 'number'.\\",\\"plugin\\":\\"TypeScript\\",\\"stack\\":\\"\\"},{\\"frame\\":\\" 2 |/n 3 | var hello1: number = 'Hello1~'/n > 4 | var hello2: boolean = 'Hello2'/n | ^^^^^^/n 5 |/n 6 | const rootDom = document.querySelector('#root')!/n 7 | rootDom.innerHTML = hello1 + text\\",\\"id\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"loc\\":{\\"column\\":5,\\"file\\":\\"<PROJECT_ROOT>/temp/multiple/src/main.ts\\",\\"line\\":4},\\"message\\":\\"Type 'string' is not assignable to type 'boolean'.\\",\\"plugin\\":\\"TypeScript\\",\\"stack\\":\\"\\"}]"`; | ||
exports[`multiple serve get initial error and subsequent error 6`] = ` | ||
" ERROR(ESLint) Unexpected var, use let or const instead. | ||
FILE <PROJECT_ROOT>/temp/multiple/src/main.ts:3:1 | ||
1 | import { text } from './text' | ||
2 | | ||
> 3 | var hello1: number = 'Hello1~' | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
4 | var hello2: boolean = 'Hello2' | ||
5 | | ||
6 | const rootDom = document.querySelector('#root')! | ||
ERROR(ESLint) Unexpected var, use let or const instead. | ||
FILE <PROJECT_ROOT>/temp/multiple/src/main.ts:4:1 | ||
2 | | ||
3 | var hello1: number = 'Hello1~' | ||
> 4 | var hello2: boolean = 'Hello2' | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
5 | | ||
6 | const rootDom = document.querySelector('#root')! | ||
7 | rootDom.innerHTML = hello1 + text | ||
ERROR(TypeScript) Type 'string' is not assignable to type 'number'. | ||
FILE <PROJECT_ROOT>/temp/multiple/src/main.ts:3:5 | ||
1 | import { text } from './text' | ||
2 | | ||
> 3 | var hello1: number = 'Hello1~' | ||
| ^^^^^^ | ||
4 | var hello2: boolean = 'Hello2' | ||
5 | | ||
6 | const rootDom = document.querySelector('#root')! | ||
ERROR(TypeScript) Type 'string' is not assignable to type 'boolean'. | ||
FILE <PROJECT_ROOT>/temp/multiple/src/main.ts:4:5 | ||
2 | | ||
3 | var hello1: number = 'Hello1~' | ||
> 4 | var hello2: boolean = 'Hello2' | ||
| ^^^^^^ | ||
5 | | ||
6 | const rootDom = document.querySelector('#root')! | ||
7 | rootDom.innerHTML = hello1 + text | ||
Found 2 errors. Watching for file changes." | ||
`; |
Oops, something went wrong.