Skip to content

Commit 8673651

Browse files
committed
cshtml --diff-base-ignore-checkers: new option for diff scans
For example, if we know that SHELLCHECK_WARNING defects are produced by different versions of ShellCheck between base and the current scan, it does not make sense to compare their results with each other. With this option, we can make defects produced by certain checkers ignored in this comparison.
1 parent 7b87c29 commit 8673651

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

cshtml.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,16 @@ int main(int argc, char *argv[])
5555
+ " [options] proj.js, where options are", /* line_length */ 0x80);
5656

5757
typedef std::vector<string> TStringList;
58-
string defUrlTemplate, fnBase, plainTextUrl, spPosition;
58+
string defUrlTemplate, fnBase, checkerIgnRegex, plainTextUrl, spPosition;
5959

6060
try {
6161
desc.add_options()
6262
("defect-url-template", po::value(&defUrlTemplate),
6363
"e.g. http://localhost/index.php?proj=%d&defect=%d")
6464
("diff-base", po::value(&fnBase),
6565
"use the given list of defects as diff base")
66+
("diff-base-ignore-checkers", po::value(&checkerIgnRegex),
67+
"do not diff base for checkers matching the given regex")
6668
("plain-text-url", po::value(&plainTextUrl),
6769
"generate a link to plain-text version")
6870
("scan-props-placement",
@@ -145,7 +147,8 @@ int main(int argc, char *argv[])
145147

146148
if (!fnBase.empty()) {
147149
const std::string diffTitleFallback = titleFromFileName(fnBase);
148-
writer.setDiffBase(&baseLookup, baseProps, diffTitleFallback);
150+
writer.setDiffBase(&baseLookup, checkerIgnRegex, baseProps,
151+
diffTitleFallback);
149152
}
150153

151154
// write HTML

html-writer.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ struct HtmlWriter::Private {
290290
const boost::regex reEvent;
291291
unsigned defCnt;
292292
DefLookup *baseLookup;
293+
boost::regex checkerIgnRegex;
293294
std::string newDefMsg;
294295
std::string plainTextUrl;
295296

@@ -339,11 +340,13 @@ void HtmlWriter::setScanProps(const TScanProps &scanProps) {
339340

340341
void HtmlWriter::setDiffBase(
341342
DefLookup *baseLookup,
343+
const std::string &checkerIgnRegex,
342344
const TScanProps &baseProps,
343345
const std::string &baseTitleFallback)
344346
{
345347
assert(baseLookup);
346348
d->baseLookup = baseLookup;
349+
d->checkerIgnRegex = checkerIgnRegex;
347350

348351
// TODO: merge with already existing metadata stomping on the same keys
349352
TScanProps::const_iterator it = baseProps.find("cov-compilation-unit-count");
@@ -401,7 +404,16 @@ void HtmlWriter::Private::writeLinkToDetails(const Defect &def) {
401404
}
402405

403406
void HtmlWriter::Private::writeNewDefWarning(const Defect &def) {
404-
if (!this->baseLookup || this->baseLookup->lookup(def))
407+
if (!this->baseLookup)
408+
// not lookup set
409+
return;
410+
411+
if (boost::regex_match(def.checker, this->checkerIgnRegex))
412+
// user requested to ignore this checker for lookup
413+
return;
414+
415+
if (this->baseLookup->lookup(def))
416+
// defect found in the lookup
405417
return;
406418

407419
// a newly introduced defect

html-writer.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class HtmlWriter: public AbstractWriter {
4343
/// @attention baseLookup needs to stay valid long enough (no deep copy)
4444
void setDiffBase(
4545
DefLookup *baseLookup,
46+
const std::string &checkerIgnRegex,
4647
const TScanProps &baseProps,
4748
const std::string &baseTitleFallback);
4849

0 commit comments

Comments
 (0)