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

Unify behavior with the IDEA-based linters in case when baseline file is not present. #24

Merged
merged 1 commit into from
Apr 30, 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
11 changes: 6 additions & 5 deletions baseline-cli/src/main/kotlin/BaselineCli.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ internal object BaselineCli {
cliPrinter: (String) -> Unit,
errPrinter: (String) -> Unit
): Int {
if (!Files.exists(baselinePath)) {
errPrinter("Please provide valid baseline report path")
return ERROR_EXIT
}
val baseline: SarifReport
try {
baseline = SarifUtil.readReport(baselinePath) ?: createSarifReport(emptyList())
if (!Files.exists(baselinePath)) {
cliPrinter("Can't find baseline report file: $baselinePath. Baseline will be calculated against empty report.")
baseline = createSarifReport(emptyList())
} else {
baseline = SarifUtil.readReport(baselinePath) ?: createSarifReport(emptyList())
}
} catch (e: JsonSyntaxException) {
errPrinter("Error reading baseline report: ${e.message}")
return ERROR_EXIT
Expand Down
5 changes: 3 additions & 2 deletions baseline-cli/src/test/kotlin/BaselineCliTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ class BaselineCliTest {
}

// Assert
assertEquals(ERROR_EXIT, exitCode)
assertEquals("Please provide valid baseline report path", stderr.toString())
assertEquals(0, exitCode)
assertTrue(stdout.contains("Can't find baseline report file: nonExistentBaselineReport.sarif."))
assertTrue(stderr.contains("Found 2 new problems according to the checks applied"))
}

@Test
Expand Down
Loading