Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw errors on non-existent paths #108

Merged
merged 1 commit into from
Oct 23, 2024
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
5 changes: 5 additions & 0 deletions .changeset/mean-buses-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'steiger': patch
---

Fix the non-existent paths showing up as a success
17 changes: 15 additions & 2 deletions packages/steiger/src/cli.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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())
Expand All @@ -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())
Expand Down