Skip to content

Commit c4414a8

Browse files
authored
Adding the support for the actual input of analyzers in SARIF format (#357)
### What's done: - supported reading of actual warnings in SARIF format
1 parent 10dce68 commit c4414a8

16 files changed

Lines changed: 108 additions & 13 deletions

File tree

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
object Versions {
44
object IntegrationTest {
5-
const val ktlint = "0.39.0"
5+
const val ktlint = "0.43.2"
66
const val ktlintLink = "https://github.com/pinterest/ktlint/releases/download/$ktlint/ktlint"
7-
const val diktat = "1.0.0-rc.2"
7+
const val diktat = "1.0.2"
88
const val diktatLink = "https://github.com/cqfn/diKTat/releases/download/v$diktat/diktat-$diktat.jar"
9+
10+
const val oldKtlint = "0.39.0"
11+
const val oldKtlintLink = "https://github.com/pinterest/ktlint/releases/download/$oldKtlint/ktlint"
12+
const val oldDiktat = "1.0.0-rc.2"
13+
const val oldDiktatLink = "https://github.com/cqfn/diKTat/releases/download/v$oldDiktat/diktat-$oldDiktat.jar"
914
}
1015
}

buildSrc/src/main/kotlin/org/cqfn/save/buildutils/DiktatConfiguration.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ fun Project.createDiktatTask() {
3333
apply<DiktatGradlePlugin>()
3434
configure<DiktatExtension> {
3535
diktatConfigFile = rootProject.file("diktat-analysis.yml")
36+
// FixMe: temporary before the release 1.0.3 of diktat
37+
// reporterType = "sarif"
3638
inputs {
3739
include(
3840
"$rootDir/buildSrc/src/**/*.kt",
@@ -54,4 +56,9 @@ fun Project.createDiktatTask() {
5456
tasks.findByName("diktatFix")?.let { this@register.dependsOn(it) }
5557
}
5658
}
59+
60+
// FixMe: temporary before the release 1.0.3 of diktat
61+
/* this.configurations.getByName("diktat").dependencies.add(
62+
this.dependencies.create("com.pinterest.ktlint:ktlint-reporter-sarif:0.43.2")
63+
) */
5764
}

examples/kotlin-diktat/fix_and_warn/save.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
tags = ["fix and warn"]
33
description = "Autofixing of issues discovered by diKTat on smoke tests and warn about issues, which couldn't be auto-corrected"
44
suiteName = "Autofix and Warn"
5-
execCmd = "java -jar ktlint -R diktat.jar"
65

76
["fix and warn"]
87
["fix and warn".fix]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[general]
2+
tags = ["warn", "sarif"]
3+
description = "Test warnings discovered by diKTat, reading expected warnings from SARIF file"
4+
suiteName = "Only Warnings: with SARIF format"
5+
expectedWarningsPattern = "// ;warn:?(.*):(\\d+):? ?(.+)?"
6+
execCmd = "java -jar ktlint --disabled_rules=standard -R diktat.jar"
7+
8+
9+
10+
[warn]
11+
execFlags = "--reporter=sarif"
12+
# regular expression to detect tests
13+
testNameRegex = ".*Test.kt"
14+
actualWarningsFormat = "SARIF"
15+
fileNameCaptureGroupOut = 1
16+
lineCaptureGroupOut = 2
17+
columnCaptureGroupOut = 3
18+
messageCaptureGroupOut = 4
19+
exactWarningsMatch = false
20+
warningTextHasColumn = true
21+
warningTextHasLine = true

examples/kotlin-diktat/sarif/src/kotlin/EnumValueSnakeCaseTest.kt renamed to examples/kotlin-diktat/sarif-actual/src/kotlin/EnumValueSnakeCaseTest.kt

File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.cqfn.diktat.test.resources.test.paragraph1.naming.enum_
2+
3+
// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumValueSnakeCaseTest (cannot be auto-corrected)
4+
// ;warn:35: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect
5+
// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon
6+
enum class EnumValueSnakeCaseTest {
7+
// ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l
8+
paSC_SAl_l,
9+
10+
// ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f
11+
PascAsl_f
12+
// ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma
13+
14+
// ;warn:1:9: {{.*}}[PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: org.cqfn.save{{.*}}
15+
}

examples/kotlin-diktat/save.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[general]
2-
execCmd = "java -jar ktlint -R diktat.jar"
2+
execCmd = "java -jar ktlint-old --disabled_rules=standard -R diktat-old.jar"
33
description = "Test for diktat - linter and formatter for Kotlin"
44
language = "Kotlin"
55
# this is the default value, you don't need to add it explicitly, but can be useful, if you have different pattern:

examples/kotlin-diktat/warn-dir/save.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[general]
2-
execCmd = "java -jar ktlint --disabled_rules=standard -R diktat.jar"
2+
execCmd = "java -jar ktlint-old --disabled_rules=standard -R diktat-old.jar"
33
tags = ["warn"]
44
description = "Test for directory mode"
55

0 commit comments

Comments
 (0)