Skip to content

Commit

Permalink
sarif: support %SRCROOT% as a root path
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed Jan 16, 2025
1 parent 470e0ad commit c0d636c
Showing 1 changed file with 106 additions and 1 deletion.
107 changes: 106 additions & 1 deletion qlty-check/src/parser/sarif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct RuleDefaultConfiguration {

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct OriginalUriBaseIds {
#[serde(alias = "ROOTPATH")]
#[serde(alias = "ROOTPATH", alias = "%SRCROOT%")]
pub root_path: RootPath,
}

Expand Down Expand Up @@ -549,6 +549,111 @@ mod test {
"#);
}

#[test]
fn parse_srcroot_root_path() {
let input = r###"
{
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [
{
"originalUriBaseIds": {
"%SRCROOT%": {
"uri": "file:///path/to/test"
}
},
"results": [
{
"level": "error",
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "/path/to/src/Main.kt",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startColumn": 37,
"startLine": 1
}
}
}
],
"message": {
"text": "First line of body expression fits on same line as function signature"
},
"ruleId": "standard:function-signature"
},
{
"level": "error",
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "/path/to/src/Main.kt",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startColumn": 1,
"startLine": 5
}
}
}
],
"message": {
"text": "Class body should not start with blank line"
},
"ruleId": "standard:no-empty-first-line-in-class-body"
}
],
"tool": {
"driver": {
"downloadUri": "https://github.com/pinterest/ktlint/releases/tag/1.5.0",
"fullName": "ktlint",
"informationUri": "https://github.com/pinterest/ktlint/",
"language": "en",
"name": "ktlint",
"organization": "pinterest",
"rules": [
],
"semanticVersion": "1.5.0",
"version": "1.5.0"
}
}
}
]
}
"###;

let issues = Sarif::default().parse("sarif", input);
insta::assert_yaml_snapshot!(issues.unwrap(), @r#"
- tool: sarif
ruleKey: "standard:function-signature"
message: First line of body expression fits on same line as function signature
level: LEVEL_HIGH
category: CATEGORY_LINT
location:
path: /path/to/test/path/to/src/Main.kt
range:
startLine: 1
startColumn: 37
endLine: 1
endColumn: 37
- tool: sarif
ruleKey: "standard:no-empty-first-line-in-class-body"
message: Class body should not start with blank line
level: LEVEL_HIGH
category: CATEGORY_LINT
location:
path: /path/to/test/path/to/src/Main.kt
range:
startLine: 5
startColumn: 1
endLine: 5
endColumn: 1
"#);
}

#[test]
fn parse_rule_level() {
let input = r###"
Expand Down

0 comments on commit c0d636c

Please sign in to comment.