Skip to content

Commit

Permalink
(feat) throw error on invalid tsconfig includes/excludes and on unkno…
Browse files Browse the repository at this point in the history
…wn options (#1974)

#1952
#1951
  • Loading branch information
dummdidumm committed Apr 4, 2023
1 parent 622c02e commit d5b29f0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/language-server/src/plugins/typescript/service.ts
Expand Up @@ -24,6 +24,7 @@ import {
export interface LanguageServiceContainer {
readonly tsconfigPath: string;
readonly compilerOptions: ts.CompilerOptions;
readonly configErrors: ts.Diagnostic[];
/**
* @internal Public for tests only
*/
Expand Down Expand Up @@ -167,6 +168,7 @@ async function createLanguageService(

const {
options: compilerOptions,
errors: configErrors,
fileNames: files,
raw,
extendedConfigPaths
Expand Down Expand Up @@ -247,6 +249,7 @@ async function createLanguageService(
return {
tsconfigPath,
compilerOptions,
configErrors,
getService: () => languageService,
updateSnapshot,
deleteSnapshot,
Expand Down
6 changes: 6 additions & 0 deletions packages/language-server/src/svelte-check.ts
Expand Up @@ -181,6 +181,12 @@ export class SvelteCheck {

private async getDiagnosticsForTsconfig(tsconfigPath: string) {
const lsContainer = await this.getLSContainer(tsconfigPath);

const noInputsFoundError = lsContainer.configErrors?.find((e) => e.code === 18003);
if (noInputsFoundError) {
throw new Error(noInputsFoundError.messageText.toString());
}

const lang = lsContainer.getService();
const files = lang.getProgram()?.getSourceFiles() || [];
const options = lang.getProgram()?.getCompilerOptions() || {};
Expand Down
4 changes: 3 additions & 1 deletion packages/svelte-check/src/options.ts
Expand Up @@ -81,7 +81,9 @@ export function parseOptions(cb: (opts: SvelteCheckCliOptions) => any) {
});
});

prog.parse(process.argv);
prog.parse(process.argv, {
unknown: (arg) => `Unknown option ${arg}`
});
}

const outputFormats = ['human', 'human-verbose', 'machine'] as const;
Expand Down
9 changes: 7 additions & 2 deletions packages/svelte-check/src/writers.ts
Expand Up @@ -112,8 +112,13 @@ export class HumanFriendlyWriter implements Writer {
const message = [
'svelte-check found ',
`${errorCount} ${errorCount === 1 ? 'error' : 'errors'} and `,
`${warningCount} ${warningCount === 1 ? 'warning' : 'warnings'} in `,
`${fileCountWithProblems} ${fileCountWithProblems === 1 ? 'file' : 'files'}\n`
`${warningCount} ${warningCount === 1 ? 'warning' : 'warnings'}`,
`${
fileCountWithProblems
? // prettier-ignore
` in ${fileCountWithProblems} ${fileCountWithProblems === 1 ? 'file' : 'files'}`
: ''
}\n`
].join('');
if (errorCount !== 0) {
this.stream.write(pc.red(message));
Expand Down

0 comments on commit d5b29f0

Please sign in to comment.