Skip to content

Commit

Permalink
csgrep --imp-level=1: filter out important defects
Browse files Browse the repository at this point in the history
  • Loading branch information
kdudka committed Sep 27, 2023
1 parent 77561f5 commit 9cf1eec
Show file tree
Hide file tree
Showing 5 changed files with 14,474 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/csgrep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,23 @@ class ToolPredicate: public IPredicate {
}
};

class ImpLevelFilter: public AbstractFilter {
private:
const int minLevel_;

public:
ImpLevelFilter(AbstractWriter *agent, const int minLevel):
AbstractFilter(agent),
minLevel_(minLevel)
{
}

protected:
bool matchDef(const Defect &def) override {
return minLevel_ <= def.imp;
}
};

class KeyEventPredicate: public IPredicate {
private:
const RE re_;
Expand Down Expand Up @@ -526,7 +543,7 @@ bool chainFilters(
return false;
}

return true;
return chainDecoratorIntArg<ImpLevelFilter>(pEng, vm, "imp-level");
}

int main(int argc, char *argv[])
Expand All @@ -552,6 +569,7 @@ int main(int argc, char *argv[])
("tool", po::value<string>(), "defect matches if it was detected by tool that matches the given regex")
("annot", po::value<string>(), "defect matches if its annotation matches the given regex")
("src-annot", po::value<string>(), "defect matches if an annotation in the _source_ file matches the given regex")
("imp-level", po::value<int>(), "defect matches if the importance level is greater or equal than the given number")

("drop-scan-props", "do not propagate scan properties")
("embed-context,U", po::value<int>(), "embed a number of lines of context from the source file for the key event")
Expand Down
1 change: 1 addition & 0 deletions tests/csgrep/0115-csgrep-imp-filter-args.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--mode=json --imp-level=1
Loading

0 comments on commit 9cf1eec

Please sign in to comment.