Skip to content

Commit 2848539

Browse files
committed
gcc-parser: move [SC1234] suffix to the key event ID
... in SHELLCHECK_WARNING reports
1 parent 7edc921 commit 2848539

File tree

6 files changed

+138
-115
lines changed

6 files changed

+138
-115
lines changed

gcc-parser.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ class PostProcessor {
541541
PostProcessor():
542542
reGccAnalCoreEvt_("^(.*) (\\[-Wanalyzer-[A-Za-z0-9-]+\\])$"),
543543
reGccAnalCwe_("^(.*) \\[CWE-([0-9]+)\\]$"),
544-
reGccWarningEvt_("^(.*) (\\[-W[A-Za-z0-9-]+\\])$")
544+
reGccWarningEvt_("^(.*) (\\[-W[A-Za-z0-9-]+\\])$"),
545+
reShellCheckId_("(^.*) (\\[SC([0-9]+)\\])$")
545546
{
546547
}
547548

@@ -552,10 +553,12 @@ class PostProcessor {
552553
const boost::regex reGccAnalCoreEvt_;
553554
const boost::regex reGccAnalCwe_;
554555
const boost::regex reGccWarningEvt_;
556+
const boost::regex reShellCheckId_;
555557
const LangDetector langDetector_;
556558

557559
void transGccAnal(Defect *pDef);
558560
void transGccSuffix(Defect *pDef);
561+
void transShellCheckId(Defect *pDef);
559562
};
560563

561564
void PostProcessor::transGccAnal(Defect *pDef) {
@@ -599,9 +602,26 @@ void PostProcessor::transGccSuffix(Defect *pDef) {
599602
keyEvt.msg = sm[/* msg */ 1];
600603
}
601604

605+
void PostProcessor::transShellCheckId(Defect *pDef) {
606+
if ("SHELLCHECK_WARNING" != pDef->checker)
607+
return;
608+
609+
// check for [SC1234] suffix in message of the key event
610+
DefEvent &keyEvt = pDef->events[pDef->keyEventIdx];
611+
boost::smatch sm;
612+
if (!boost::regex_match(keyEvt.msg, sm, reShellCheckId_))
613+
return;
614+
615+
// append [SC1234] to key event ID and remove it from event msg
616+
keyEvt.event += sm[/* id */ 2];
617+
// this invalidates sm
618+
keyEvt.msg = sm[/* msg */ 1];
619+
}
620+
602621
void PostProcessor::apply(Defect *pDef) {
603622
this->transGccAnal(pDef);
604623
this->transGccSuffix(pDef);
624+
this->transShellCheckId(pDef);
605625
this->langDetector_.inferLangFromChecker(pDef);
606626
}
607627

0 commit comments

Comments
 (0)