Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/svelte-check/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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"

`--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"
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 12 additions & 2 deletions packages/svelte-check/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Result = {
fileCount: number;
errorCount: number;
warningCount: number;
hintCount: number;
};

function openAllDocuments(
Expand Down Expand Up @@ -56,6 +57,7 @@ async function getDiagnostics(
fileCount: diagnostics.length,
errorCount: 0,
warningCount: 0,
hintCount: 0,
};

for (const diagnostic of diagnostics) {
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
52 changes: 30 additions & 22 deletions packages/svelte-check/src/writers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion packages/svelte2tsx/svelte-jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
//
// Event Handler Types
// ----------------------------------------------------------------------
type EventHandler<E = Event, T = HTMLElement> = (event: E & { currentTarget: EventTarget & T}) => any;
type EventHandler<E = Event, T = HTMLElement> =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was 102 characters, creating a linting error.

(event: E & { currentTarget: EventTarget & T}) => any;

type ClipboardEventHandler<T> = EventHandler<ClipboardEvent, T>;
type CompositionEventHandler<T> = EventHandler<CompositionEvent, T>;
Expand Down