Swift: make help links optional argument more explicit

This commit is contained in:
Paolo Tranquilli
2023-05-16 16:52:22 +02:00
parent 8291b2229a
commit 7e61e99e4a
2 changed files with 16 additions and 6 deletions

View File

@@ -54,6 +54,11 @@ struct SwiftDiagnostic {
error,
};
// wrapper for passing optional help links to constructor
struct HelpLinks {
std::string_view value;
};
static constexpr std::string_view extractorName = "swift";
std::string_view id;
@@ -72,9 +77,9 @@ struct SwiftDiagnostic {
// notice help links are really required only for plaintext messages, otherwise they should be
// directly embedded in the markdown message
// optional arguments can be any of
// * std::string_view for setting helpLinks
// * Severity, Visibility or Format to set the corresponding field
// optional arguments can be any of HelpLinks, Severity, Visibility or Format to set the
// corresponding field
// TODO(C++20) this constructor won't really be necessary anymore with designated initializers
template <typename... OptionalArgs>
constexpr SwiftDiagnostic(std::string_view id,
std::string_view name,
@@ -107,10 +112,14 @@ struct SwiftDiagnostic {
private:
bool has(Visibility v) const;
constexpr void setOptionalArg(std::string_view h) { helpLinks = h; }
constexpr void setOptionalArg(HelpLinks h) { helpLinks = h.value; }
constexpr void setOptionalArg(Format f) { format = f; }
constexpr void setOptionalArg(Visibility v) { visibility = v; }
constexpr void setOptionalArg(Severity s) { severity = s; }
// intentionally left undefined
template <typename T>
constexpr void setOptionalArg(T);
};
inline constexpr SwiftDiagnostic::Visibility operator|(SwiftDiagnostic::Visibility lhs,

View File

@@ -1,12 +1,13 @@
#include <string_view>
#include "swift/logging/SwiftDiagnostics.h"
namespace codeql {
constexpr std::string_view customizingBuildAction = "Set up a manual build command.";
constexpr std::string_view customizingBuildHelpLinks =
constexpr SwiftDiagnostic::HelpLinks customizingBuildHelpLinks{
"https://docs.github.com/en/enterprise-server/code-security/code-scanning/"
"automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning "
"https://docs.github.com/en/enterprise-server/code-security/code-scanning/"
"automatically-scanning-your-code-for-vulnerabilities-and-errors/"
"configuring-the-codeql-workflow-for-compiled-languages#adding-build-steps-for-a-compiled-"
"language";
"language"};
} // namespace codeql