Skip to content

Commit 173b23d

Browse files
authored
(feat) svelte-check CLI argument --fail-on-hints (#582)
1 parent cc7b4f1 commit 173b23d

File tree

4 files changed

+48
-28
lines changed

4 files changed

+48
-28
lines changed

packages/svelte-check/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ Usage:
6060

6161
`--fail-on-warnings` Will also exit with error code when there are warnings
6262

63+
`--fail-on-hints` Will also exit with error code when there are hints
64+
6365
`--compiler-warnings <code1:error|ignore,code2:error|ignore>` 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"
6466

6567
`--diagnostic-sources <js,svelte,css>` 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
99101
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`"
100102
```
101103

102-
The output concludes with a `COMPLETED` message that summarizes total numbers of files, errors,
103-
and warnings that were encountered during the check.
104+
The output concludes with a `COMPLETED` message that summarizes total numbers of files, errors, warnings and hints that were encountered during the check.
104105

105106
###### Example:
106107

107108
```
108-
1590680326807 COMPLETED 20 FILES 21 ERRORS 1 WARNINGS
109+
1590680326807 COMPLETED 20 FILES 21 ERRORS 1 WARNINGS 0 HINTS
109110
```
110111

111112
If the application experiences a runtime error, this error will appear as a `FAILURE` record.

packages/svelte-check/src/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Result = {
1919
fileCount: number;
2020
errorCount: number;
2121
warningCount: number;
22+
hintCount: number;
2223
};
2324

2425
function openAllDocuments(
@@ -56,6 +57,7 @@ async function getDiagnostics(
5657
fileCount: diagnostics.length,
5758
errorCount: 0,
5859
warningCount: 0,
60+
hintCount: 0,
5961
};
6062

6163
for (const diagnostic of diagnostics) {
@@ -71,11 +73,18 @@ async function getDiagnostics(
7173
result.errorCount += 1;
7274
} else if (d.severity === DiagnosticSeverity.Warning) {
7375
result.warningCount += 1;
76+
} else if (d.severity === DiagnosticSeverity.Hint) {
77+
result.hintCount += 1;
7478
}
7579
});
7680
}
7781

78-
writer.completion(result.fileCount, result.errorCount, result.warningCount);
82+
writer.completion(
83+
result.fileCount,
84+
result.errorCount,
85+
result.warningCount,
86+
result.hintCount,
87+
);
7988
return result;
8089
} catch (err) {
8190
writer.failure(err);
@@ -198,7 +207,8 @@ function getOptions(myArgs: argv.ParsedArgs): SvelteCheckOptions {
198207
if (
199208
result &&
200209
result.errorCount === 0 &&
201-
(!myArgs['fail-on-warnings'] || result.warningCount === 0)
210+
(!myArgs['fail-on-warnings'] || result.warningCount === 0) &&
211+
(!myArgs['fail-on-hints'] || result.hintCount === 0)
202212
) {
203213
process.exit(0);
204214
} else {

packages/svelte-check/src/writers.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import { offsetAt } from 'svelte-language-server';
77
export interface Writer {
88
start: (workspaceDir: string) => void;
99
file: (d: Diagnostic[], workspaceDir: string, filename: string, text: string) => void;
10-
completion: (fileCount: number, errorCount: number, warningCount: number) => void;
10+
completion: (
11+
fileCount: number,
12+
errorCount: number,
13+
warningCount: number,
14+
hintCount: number,
15+
) => void;
1116
failure: (err: Error) => void;
1217
}
1318

@@ -87,27 +92,22 @@ export class HumanFriendlyWriter implements Writer {
8792
);
8893
}
8994

90-
completion(_f: number, errorCount: number, warningCount: number) {
95+
completion(_f: number, errorCount: number, warningCount: number, hintCount: number) {
9196
this.stream.write('====================================\n');
92-
93-
if (errorCount === 0 && warningCount === 0) {
94-
this.stream.write(chalk.green(`svelte-check found no errors and no warnings\n`));
95-
} else if (errorCount === 0) {
96-
this.stream.write(
97-
chalk.yellow(
98-
`svelte-check found ${warningCount} ${
99-
warningCount === 1 ? 'warning' : 'warnings'
100-
}\n`,
101-
),
102-
);
97+
const message = [
98+
'svelte-check found ',
99+
`${errorCount} ${errorCount === 1 ? 'error' : 'errors'}, `,
100+
`${warningCount} ${warningCount === 1 ? 'warning' : 'warnings'} and `,
101+
`${hintCount} ${hintCount === 1 ? 'hint' : 'hints'}\n`,
102+
].join('');
103+
if (errorCount !== 0) {
104+
this.stream.write(chalk.red(message));
105+
} else if (warningCount !== 0) {
106+
this.stream.write(chalk.yellow(message));
107+
} else if (hintCount !== 0) {
108+
this.stream.write(chalk.grey(message));
103109
} else {
104-
this.stream.write(
105-
chalk.red(
106-
`svelte-check found ${errorCount} ${
107-
errorCount === 1 ? 'error' : 'errors'
108-
} and ${warningCount} ${warningCount === 1 ? 'warning' : 'warnings'}\n`,
109-
),
110-
);
110+
this.stream.write(chalk.green(message));
111111
}
112112
}
113113

@@ -146,8 +146,16 @@ export class MachineFriendlyWriter implements Writer {
146146
});
147147
}
148148

149-
completion(fileCount: number, errorCount: number, warningCount: number) {
150-
this.log(`COMPLETED ${fileCount} FILES ${errorCount} ERRORS ${warningCount} WARNINGS`);
149+
completion(fileCount: number, errorCount: number, warningCount: number, hintCount: number) {
150+
this.log(
151+
[
152+
'COMPLETED',
153+
`${fileCount} FILES`,
154+
`${errorCount} ERRORS`,
155+
`${warningCount} WARNINGS`,
156+
`${hintCount} HINTS`,
157+
].join(' '),
158+
);
151159
}
152160

153161
failure(err: Error) {

packages/svelte2tsx/svelte-jsx.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
//
4040
// Event Handler Types
4141
// ----------------------------------------------------------------------
42-
type EventHandler<E = Event, T = HTMLElement> = (event: E & { currentTarget: EventTarget & T}) => any;
42+
type EventHandler<E = Event, T = HTMLElement> =
43+
(event: E & { currentTarget: EventTarget & T}) => any;
4344

4445
type ClipboardEventHandler<T> = EventHandler<ClipboardEvent, T>;
4546
type CompositionEventHandler<T> = EventHandler<CompositionEvent, T>;

0 commit comments

Comments
 (0)