Skip to content

csgrep --set-imp-level: set importance level on all defects #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" )