Files
FairMQ/fairmq/tidy/ProgOptionsAccessorsCheck.h
Claude 67fd7f2305 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>
2026-11-10 09:28:29 +00:00

41 lines
1.7 KiB
C++

/********************************************************************************
* Copyright (C) 2026 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#ifndef FAIR_MQ_TIDY_PROGOPTIONSACCESSORSCHECK_H
#define FAIR_MQ_TIDY_PROGOPTIONSACCESSORSCHECK_H
#include <clang-tidy/ClangTidyCheck.h>
namespace fair::mq::tidy {
/// Finds calls of the old `fair::mq::ProgOptions` accessors and calls the
/// property API instead:
/// - `GetValue<T>(key)` -> `GetProperty<T>(key, {})`
/// - `GetStringValue(key)` -> `GetPropertyAsString(key, {})`
/// - `SetValue(key, value)` -> `SetProperty(key, value)` (only if the
/// always-zero result of `SetValue` is not used)
///
/// The `{}` default keeps the behaviour for an unknown key: the old accessors
/// return a default-constructed value, the property API throws without it.
class ProgOptionsAccessorsCheck : public clang::tidy::ClangTidyCheck
{
public:
using ClangTidyCheck::ClangTidyCheck;
bool isLanguageVersionSupported(clang::LangOptions const& opts) const override
{
return opts.CPlusPlus17;
}
void registerMatchers(clang::ast_matchers::MatchFinder* finder) override;
void check(clang::ast_matchers::MatchFinder::MatchResult const& result) override;
};
} // namespace fair::mq::tidy
#endif /* FAIR_MQ_TIDY_PROGOPTIONSACCESSORSCHECK_H */