Skip to content

Commit baa7dea

Browse files
committed
fix: parse clang-tidy output when WarningsAsErrors is asserted
corresponds to cpp-linter/cpp-linter#162
1 parent 5ff6016 commit baa7dea

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

cpp-linter/src/clang_tools/clang_tidy.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ impl MakeSuggestions for TidyAdvice {
130130
}
131131
}
132132

133+
/// A regex pattern to capture the clang-tidy note header.
134+
const NOTE_HEADER: &str = r"^(.+):(\d+):(\d+):\s(\w+):(.*)\[([a-zA-Z\d\-\.]+),?[^\]]*\]$";
135+
133136
/// Parses clang-tidy stdout.
134137
///
135138
/// Here it helps to have the JSON database deserialized for normalizing paths present
@@ -138,7 +141,7 @@ fn parse_tidy_output(
138141
tidy_stdout: &[u8],
139142
database_json: &Option<Vec<CompilationUnit>>,
140143
) -> Result<TidyAdvice> {
141-
let note_header = Regex::new(r"^(.+):(\d+):(\d+):\s(\w+):(.*)\[([a-zA-Z\d\-\.]+)\]$").unwrap();
144+
let note_header = Regex::new(NOTE_HEADER).unwrap();
142145
let fixed_note =
143146
Regex::new(r"^.+:(\d+):\d+:\snote: FIX-IT applied suggested code changes$").unwrap();
144147
let mut found_fix = false;
@@ -354,8 +357,8 @@ mod test {
354357
common_fs::FileObj,
355358
};
356359

357-
use super::run_clang_tidy;
358360
use super::TidyNotification;
361+
use super::{run_clang_tidy, NOTE_HEADER};
359362

360363
#[test]
361364
fn clang_diagnostic_link() {
@@ -397,13 +400,15 @@ mod test {
397400

398401
#[test]
399402
fn test_capture() {
400-
let src = "tests/demo/demo.hpp:11:11: warning: use a trailing return type for this function [modernize-use-trailing-return-type]";
401-
let pat = Regex::new(r"^(.+):(\d+):(\d+):\s(\w+):(.*)\[([a-zA-Z\d\-\.]+)\]$").unwrap();
403+
let src = "tests/demo/demo.hpp:11:11: \
404+
warning: use a trailing return type for this function \
405+
[modernize-use-trailing-return-type,-warnings-as-errors]";
406+
let pat = Regex::new(NOTE_HEADER).unwrap();
402407
let cap = pat.captures(src).unwrap();
403408
assert_eq!(
404409
cap.get(0).unwrap().as_str(),
405410
format!(
406-
"{}:{}:{}: {}:{}[{}]",
411+
"{}:{}:{}: {}:{}[{},-warnings-as-errors]",
407412
cap.get(1).unwrap().as_str(),
408413
cap.get(2).unwrap().as_str(),
409414
cap.get(3).unwrap().as_str(),

cpp-linter/tests/demo/.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,performance-*,bugprone-*,clang-analyzer-*,mpi-*,misc-*,readability-*'
3-
WarningsAsErrors: ''
3+
WarningsAsErrors: '*'
44
HeaderFilterRegex: ''
55
AnalyzeTemporaryDtors: false
66
FormatStyle: 'file'

cspell.config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,4 @@ ignorePaths:
124124
- cpp-linter/tests/**/.clang-tidy
125125
- .vscode/extensions.json
126126
- .yarn/releases/*
127+
- "*.lock"

0 commit comments

Comments
 (0)