diff --git a/.changeset/mean-buses-tan.md b/.changeset/mean-buses-tan.md new file mode 100644 index 0000000..59d52a6 --- /dev/null +++ b/.changeset/mean-buses-tan.md @@ -0,0 +1,5 @@ +--- +'steiger': patch +--- + +Fix the non-existent paths showing up as a success diff --git a/packages/steiger/src/cli.ts b/packages/steiger/src/cli.ts index 61cdc52..32065b0 100755 --- a/packages/steiger/src/cli.ts +++ b/packages/steiger/src/cli.ts @@ -1,6 +1,7 @@ #!/usr/bin/env node import { resolve, relative, dirname } from 'node:path' +import { stat } from 'node:fs/promises' import * as process from 'node:process' import yargs from 'yargs' import prexit from 'prexit' @@ -68,8 +69,20 @@ try { } } +const targetPath = resolve(consoleArgs._[0]) + +try { + if (!(await stat(targetPath)).isDirectory()) { + console.error(`${consoleArgs._[0]} is a file, must be a folder`) + process.exit(102) + } +} catch { + console.error(`Folder ${consoleArgs._[0]} does not exist`) + process.exit(101) +} + if (consoleArgs.watch) { - const [diagnosticsChanged, stopWatching] = await linter.watch(resolve(consoleArgs._[0])) + const [diagnosticsChanged, stopWatching] = await linter.watch(targetPath) const unsubscribe = diagnosticsChanged.watch((state) => { console.clear() reportPretty(state, process.cwd()) @@ -82,7 +95,7 @@ if (consoleArgs.watch) { unsubscribe() }) } else { - const diagnostics = await linter.run(resolve(consoleArgs._[0])) + const diagnostics = await linter.run(targetPath) let stillRelevantDiagnostics = diagnostics reportPretty(diagnostics, process.cwd())