diff --git a/packages/svelte-check/README.md b/packages/svelte-check/README.md index 7b448319c..7a498601d 100644 --- a/packages/svelte-check/README.md +++ b/packages/svelte-check/README.md @@ -60,6 +60,8 @@ Usage: `--fail-on-warnings` Will also exit with error code when there are warnings +`--fail-on-hints` Will also exit with error code when there are hints + `--compiler-warnings ` A list of Svelte compiler warning codes. Each entry defines whether that warning should be ignored or treated as an error. Warnings are comma-separated, between warning code and error level is a colon; all inside quotes. Example: --compiler-warnings "css-unused-selector:ignore,unused-export-let:error" `--diagnostic-sources ` A list of diagnostic sources which should run diagnostics on your code. Possible values are `js` (includes TS), `svelte`, `css`. Comma-separated, inside quotes. By default all are active. Example: --diagnostic-sources "js,svelte" @@ -99,13 +101,12 @@ to the workspace directory. The filename and the message are both wrapped in quo 1590680326778 WARNING "imported-file.svelte" 0:37 "Component has unused export property 'prop'. If it is for external reference only, please consider using `export const prop`" ``` -The output concludes with a `COMPLETED` message that summarizes total numbers of files, errors, -and warnings that were encountered during the check. +The output concludes with a `COMPLETED` message that summarizes total numbers of files, errors, warnings and hints that were encountered during the check. ###### Example: ``` -1590680326807 COMPLETED 20 FILES 21 ERRORS 1 WARNINGS +1590680326807 COMPLETED 20 FILES 21 ERRORS 1 WARNINGS 0 HINTS ``` If the application experiences a runtime error, this error will appear as a `FAILURE` record. diff --git a/packages/svelte-check/src/index.ts b/packages/svelte-check/src/index.ts index fc6bd139d..f266c6e67 100644 --- a/packages/svelte-check/src/index.ts +++ b/packages/svelte-check/src/index.ts @@ -19,6 +19,7 @@ type Result = { fileCount: number; errorCount: number; warningCount: number; + hintCount: number; }; function openAllDocuments( @@ -56,6 +57,7 @@ async function getDiagnostics( fileCount: diagnostics.length, errorCount: 0, warningCount: 0, + hintCount: 0, }; for (const diagnostic of diagnostics) { @@ -71,11 +73,18 @@ async function getDiagnostics( result.errorCount += 1; } else if (d.severity === DiagnosticSeverity.Warning) { result.warningCount += 1; + } else if (d.severity === DiagnosticSeverity.Hint) { + result.hintCount += 1; } }); } - writer.completion(result.fileCount, result.errorCount, result.warningCount); + writer.completion( + result.fileCount, + result.errorCount, + result.warningCount, + result.hintCount, + ); return result; } catch (err) { writer.failure(err); @@ -198,7 +207,8 @@ function getOptions(myArgs: argv.ParsedArgs): SvelteCheckOptions { if ( result && result.errorCount === 0 && - (!myArgs['fail-on-warnings'] || result.warningCount === 0) + (!myArgs['fail-on-warnings'] || result.warningCount === 0) && + (!myArgs['fail-on-hints'] || result.hintCount === 0) ) { process.exit(0); } else { diff --git a/packages/svelte-check/src/writers.ts b/packages/svelte-check/src/writers.ts index 76edc8db0..eaab22fee 100644 --- a/packages/svelte-check/src/writers.ts +++ b/packages/svelte-check/src/writers.ts @@ -7,7 +7,12 @@ import { offsetAt } from 'svelte-language-server'; export interface Writer { start: (workspaceDir: string) => void; file: (d: Diagnostic[], workspaceDir: string, filename: string, text: string) => void; - completion: (fileCount: number, errorCount: number, warningCount: number) => void; + completion: ( + fileCount: number, + errorCount: number, + warningCount: number, + hintCount: number, + ) => void; failure: (err: Error) => void; } @@ -87,27 +92,22 @@ export class HumanFriendlyWriter implements Writer { ); } - completion(_f: number, errorCount: number, warningCount: number) { + completion(_f: number, errorCount: number, warningCount: number, hintCount: number) { this.stream.write('====================================\n'); - - if (errorCount === 0 && warningCount === 0) { - this.stream.write(chalk.green(`svelte-check found no errors and no warnings\n`)); - } else if (errorCount === 0) { - this.stream.write( - chalk.yellow( - `svelte-check found ${warningCount} ${ - warningCount === 1 ? 'warning' : 'warnings' - }\n`, - ), - ); + const message = [ + 'svelte-check found ', + `${errorCount} ${errorCount === 1 ? 'error' : 'errors'}, `, + `${warningCount} ${warningCount === 1 ? 'warning' : 'warnings'} and `, + `${hintCount} ${hintCount === 1 ? 'hint' : 'hints'}\n`, + ].join(''); + if (errorCount !== 0) { + this.stream.write(chalk.red(message)); + } else if (warningCount !== 0) { + this.stream.write(chalk.yellow(message)); + } else if (hintCount !== 0) { + this.stream.write(chalk.grey(message)); } else { - this.stream.write( - chalk.red( - `svelte-check found ${errorCount} ${ - errorCount === 1 ? 'error' : 'errors' - } and ${warningCount} ${warningCount === 1 ? 'warning' : 'warnings'}\n`, - ), - ); + this.stream.write(chalk.green(message)); } } @@ -146,8 +146,16 @@ export class MachineFriendlyWriter implements Writer { }); } - completion(fileCount: number, errorCount: number, warningCount: number) { - this.log(`COMPLETED ${fileCount} FILES ${errorCount} ERRORS ${warningCount} WARNINGS`); + completion(fileCount: number, errorCount: number, warningCount: number, hintCount: number) { + this.log( + [ + 'COMPLETED', + `${fileCount} FILES`, + `${errorCount} ERRORS`, + `${warningCount} WARNINGS`, + `${hintCount} HINTS`, + ].join(' '), + ); } failure(err: Error) { diff --git a/packages/svelte2tsx/svelte-jsx.d.ts b/packages/svelte2tsx/svelte-jsx.d.ts index a84c487c8..6043f8597 100644 --- a/packages/svelte2tsx/svelte-jsx.d.ts +++ b/packages/svelte2tsx/svelte-jsx.d.ts @@ -39,7 +39,8 @@ // // Event Handler Types // ---------------------------------------------------------------------- - type EventHandler = (event: E & { currentTarget: EventTarget & T}) => any; + type EventHandler = + (event: E & { currentTarget: EventTarget & T}) => any; type ClipboardEventHandler = EventHandler; type CompositionEventHandler = EventHandler;