Skip to content

Commit

Permalink
csgrep --set-imp-level: set importance level on all defects
Browse files Browse the repository at this point in the history
... to the specified value

Related: https://issues.redhat.com/browse/OSH-343
Closes: #149
  • Loading branch information
kdudka committed Nov 9, 2023
1 parent d059bc7 commit f482df6
Show file tree
Hide file tree
Showing 7 changed files with 2,468 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/csgrep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ int main(int argc, char *argv[])
("warning-rate-limit", po::value<int>(), "stop processing a warning if the count of its occurrences exceeds the specified limit")
("limit-msg-len", po::value<int>(), "limit message length by a number provided")
("remove-duplicates,u", "remove defects that are not unique by their key event")
("set-imp-level", po::value<int>(), "set importance level on all defects to the specified value")
("set-scan-prop", po::value<TStringList>(), "NAME:VALUE pair to override the specified scan property")
("strip-path-prefix", po::value<string>(), "string prefix to strip from path (applied after all filters)")
("prepend-path-prefix", po::value<string>(), "string prefix to prepend to relative paths (applied after all filters)")
Expand Down Expand Up @@ -682,6 +683,7 @@ int main(int argc, char *argv[])
if (!chainDecoratorIntArg<EventPrunner>(&eng, vm, "prune-events")
|| !chainDecoratorIntArg<RateLimitter>(&eng, vm, "warning-rate-limit")
|| !chainDecoratorIntArg<MsgTrimmer>(&eng, vm, "limit-msg-len")
|| !chainDecoratorIntArg<ImpLevelSetter>(&eng, vm, "set-imp-level")
|| !chainDecoratorIntArg<CtxEmbedder>(&eng, vm, "embed-context"))
// error message already printed, eng already feeed
return 1;
Expand Down
11 changes: 11 additions & 0 deletions src/lib/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,14 @@ void MsgTrimmer::handleDef(const Defect &defOrig)

agent_->handleDef(def);
}


// /////////////////////////////////////////////////////////////////////////////
// implementation of ImpLevelSetter

void ImpLevelSetter::handleDef(const Defect &defOrig)
{
Defect def = defOrig;
def.imp = impLevel_;
agent_->handleDef(def);
}
15 changes: 15 additions & 0 deletions src/lib/filter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,19 @@ class MsgTrimmer: public GenericAbstractFilter {
void handleDef(const Defect &defOrig) override;
};

/// set importance level on all defects to the specified value
class ImpLevelSetter: public GenericAbstractFilter {
private:
const int impLevel_;

public:
ImpLevelSetter(AbstractWriter *agent, const int impLevel):
GenericAbstractFilter(agent),
impLevel_(impLevel)
{
}

void handleDef(const Defect &defOrig) override;
};

#endif /* H_GUARD_FILTER_H */
1 change: 1 addition & 0 deletions tests/csgrep/0117-csgrep-set-imp-level-args.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--mode=json --set-imp-level=0
1,222 changes: 1,222 additions & 0 deletions tests/csgrep/0117-csgrep-set-imp-level-stdin.txt

Large diffs are not rendered by default.

1,216 changes: 1,216 additions & 0 deletions tests/csgrep/0117-csgrep-set-imp-level-stdout.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/csgrep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ test_csgrep("0113-gitleaks-limit-msg-len" )
test_csgrep("0114-json-sc-column" )
test_csgrep("0115-csgrep-imp-filter" )
test_csgrep("0116-csgrep-warning-rate-limit" )
test_csgrep("0117-csgrep-set-imp-level" )

0 comments on commit f482df6

Please sign in to comment.