Skip to content

Commit 7e61e99

Browse files
committed
Swift: make help links optional argument more explicit
1 parent 8291b22 commit 7e61e99

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

swift/logging/SwiftDiagnostics.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ struct SwiftDiagnostic {
5454
error,
5555
};
5656

57+
// wrapper for passing optional help links to constructor
58+
struct HelpLinks {
59+
std::string_view value;
60+
};
61+
5762
static constexpr std::string_view extractorName = "swift";
5863

5964
std::string_view id;
@@ -72,9 +77,9 @@ struct SwiftDiagnostic {
7277

7378
// notice help links are really required only for plaintext messages, otherwise they should be
7479
// directly embedded in the markdown message
75-
// optional arguments can be any of
76-
// * std::string_view for setting helpLinks
77-
// * Severity, Visibility or Format to set the corresponding field
80+
// optional arguments can be any of HelpLinks, Severity, Visibility or Format to set the
81+
// corresponding field
82+
// TODO(C++20) this constructor won't really be necessary anymore with designated initializers
7883
template <typename... OptionalArgs>
7984
constexpr SwiftDiagnostic(std::string_view id,
8085
std::string_view name,
@@ -107,10 +112,14 @@ struct SwiftDiagnostic {
107112
private:
108113
bool has(Visibility v) const;
109114

110-
constexpr void setOptionalArg(std::string_view h) { helpLinks = h; }
115+
constexpr void setOptionalArg(HelpLinks h) { helpLinks = h.value; }
111116
constexpr void setOptionalArg(Format f) { format = f; }
112117
constexpr void setOptionalArg(Visibility v) { visibility = v; }
113118
constexpr void setOptionalArg(Severity s) { severity = s; }
119+
120+
// intentionally left undefined
121+
template <typename T>
122+
constexpr void setOptionalArg(T);
114123
};
115124

116125
inline constexpr SwiftDiagnostic::Visibility operator|(SwiftDiagnostic::Visibility lhs,
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#include <string_view>
2+
#include "swift/logging/SwiftDiagnostics.h"
23

34
namespace codeql {
45
constexpr std::string_view customizingBuildAction = "Set up a manual build command.";
5-
constexpr std::string_view customizingBuildHelpLinks =
6+
constexpr SwiftDiagnostic::HelpLinks customizingBuildHelpLinks{
67
"https://docs.github.com/en/enterprise-server/code-security/code-scanning/"
78
"automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning "
89
"https://docs.github.com/en/enterprise-server/code-security/code-scanning/"
910
"automatically-scanning-your-code-for-vulnerabilities-and-errors/"
1011
"configuring-the-codeql-workflow-for-compiled-languages#adding-build-steps-for-a-compiled-"
11-
"language";
12+
"language"};
1213
} // namespace codeql

0 commit comments

Comments
 (0)