Skip to content

Commit 02c500c

Browse files
authored
fix: parse clang-tidy output when WarningsAsErrors is asserted (#190)
corresponds to cpp-linter/cpp-linter#162
1 parent 5ff6016 commit 02c500c

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

.github/workflows/run-dev-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,37 +182,31 @@ jobs:
182182
run: uvx nox -s test -- --profile ci
183183

184184
- name: Install clang v19
185-
if: runner.os == 'Linux'
186185
uses: ./.github/install-clang-action
187186
with:
188187
version: '19'
189188

190189
- name: Collect Coverage for clang v19
191-
if: runner.os == 'Linux'
192190
env:
193191
CLANG_VERSION: '19'
194192
run: uvx nox -s test -- --profile ci
195193

196194
- name: Install clang v20
197-
if: runner.os == 'Linux'
198195
uses: ./.github/install-clang-action
199196
with:
200197
version: '20'
201198

202199
- name: Collect Coverage for clang v20
203-
if: runner.os == 'Linux'
204200
env:
205201
CLANG_VERSION: '20'
206202
run: uvx nox -s test -- --profile ci
207203

208204
- name: Install clang v21
209-
if: runner.os == 'Linux'
210205
uses: ./.github/install-clang-action
211206
with:
212207
version: '21'
213208

214209
- name: Collect Coverage for clang v21
215-
if: runner.os == 'Linux'
216210
env:
217211
CLANG_VERSION: '21'
218212
run: uvx nox -s test -- --profile all

cpp-linter/src/clang_tools/clang_tidy.rs

Lines changed: 10 additions & 6 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,7 @@ mod test {
354357
common_fs::FileObj,
355358
};
356359

357-
use super::run_clang_tidy;
358-
use super::TidyNotification;
360+
use super::{run_clang_tidy, TidyNotification, NOTE_HEADER};
359361

360362
#[test]
361363
fn clang_diagnostic_link() {
@@ -397,13 +399,15 @@ mod test {
397399

398400
#[test]
399401
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();
402+
let src = "tests/demo/demo.hpp:11:11: \
403+
warning: use a trailing return type for this function \
404+
[modernize-use-trailing-return-type,-warnings-as-errors]";
405+
let pat = Regex::new(NOTE_HEADER).unwrap();
402406
let cap = pat.captures(src).unwrap();
403407
assert_eq!(
404408
cap.get(0).unwrap().as_str(),
405409
format!(
406-
"{}:{}:{}: {}:{}[{}]",
410+
"{}:{}:{}: {}:{}[{},-warnings-as-errors]",
407411
cap.get(1).unwrap().as_str(),
408412
cap.get(2).unwrap().as_str(),
409413
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'

0 commit comments

Comments
 (0)