Skip to content

Commit

Permalink
Throw errors on non-existent paths (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
illright authored Oct 23, 2024
1 parent 8291fc7 commit c6db720
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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

0 comments on commit c6db720

Please sign in to comment.