mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-25 21:21:37 +00:00
feat(tidy): add fairmq-modernize-progoptions-accessors
- Replace GetValue<T>(key) with GetProperty<T>(key, {}) and
GetStringValue(key) with GetPropertyAsString(key, {}). The {} default
keeps the old result for an unknown key, where the property API throws.
- Replace SetValue() with SetProperty() only where its always-zero
result is unused, because SetProperty() returns void.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
23
test/tidy/fairmq-modernize-progoptions-accessors.cxx
Normal file
23
test/tidy/fairmq-modernize-progoptions-accessors.cxx
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <fairmq/ProgOptions.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
void configure(fair::mq::ProgOptions& config, fair::mq::ProgOptions* cfg)
|
||||
{
|
||||
// CHECK-MESSAGES: :[[@LINE+1]]:29: warning: 'ProgOptions::GetValue()' is an old accessor; use 'GetProperty()' [fairmq-modernize-progoptions-accessors]
|
||||
int const rate = config.GetValue<int>("rate");
|
||||
// CHECK-FIXES: int const rate = config.GetProperty<int>("rate", {});
|
||||
// CHECK-MESSAGES: :[[@LINE+1]]:35: warning: 'ProgOptions::GetStringValue()' is an old accessor; use 'GetPropertyAsString()' [fairmq-modernize-progoptions-accessors]
|
||||
std::string const name = cfg->GetStringValue("name");
|
||||
// CHECK-FIXES: std::string const name = cfg->GetPropertyAsString("name", {});
|
||||
// CHECK-MESSAGES: :[[@LINE+1]]:12: warning: 'ProgOptions::SetValue()' is an old accessor; use 'SetProperty()' [fairmq-modernize-progoptions-accessors]
|
||||
config.SetValue("rate", rate + 1);
|
||||
// CHECK-FIXES: config.SetProperty("rate", rate + 1);
|
||||
// The result of SetValue() is used: report, but no fix.
|
||||
// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: 'ProgOptions::SetValue()' is an old accessor; use 'SetProperty()' [fairmq-modernize-progoptions-accessors]
|
||||
int const rc = config.SetValue("name", name);
|
||||
// CHECK-FIXES: int const rc = config.SetValue("name", name);
|
||||
// The property API is not reported.
|
||||
config.SetProperty("rc", rc);
|
||||
static_cast<void>(config.GetProperty<int>("rc"));
|
||||
}
|
||||
Reference in New Issue
Block a user