Fix -Wno-error= parsing in clang-format.

As noted in https://reviews.llvm.org/D86137#2460135 parsing of
the clang-format parameter -Wno-error=unknown fails.
This currently is done by having `-Wno-error=unknown` as an option.
In this patch this is changed to make `-Wno-error=` parse an enum into a bit set.
This way the parsing is fixed and also we can possibly add new options easily.

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D93459

GitOrigin-RevId: c755e41c336c898873db6c3c58a2819a982f60de
diff --git a/ClangFormat.cpp b/ClangFormat.cpp
index a1b42a6..64f0e2b 100644
--- a/ClangFormat.cpp
+++ b/ClangFormat.cpp
@@ -104,18 +104,6 @@
              "SortIncludes style flag"),
     cl::cat(ClangFormatCategory));
 
-// using the full param name as Wno-error probably won't be a common use case in
-// clang-format
-static cl::opt<bool> AllowUnknownOptions(
-    "Wno-error=unknown",
-    cl::desc("If set, unknown format options are only warned about.\n"
-             "This can be used to enable formatting, even if the\n"
-             "configuration contains unknown (newer) options.\n"
-             "Use with caution, as this might lead to dramatically\n"
-             "differing format depending on an option being\n"
-             "supported or not."),
-    cl::init(false), cl::cat(ClangFormatCategory));
-
 static cl::opt<bool>
     Verbose("verbose", cl::desc("If set, shows the list of processed files"),
             cl::cat(ClangFormatCategory));
@@ -156,6 +144,23 @@
                      cl::desc("If set, changes formatting warnings to errors"),
                      cl::cat(ClangFormatCategory));
 
+namespace {
+enum class WNoError { Unknown };
+}
+
+static cl::bits<WNoError> WNoErrorList(
+    "Wno-error",
+    cl::desc("If set don't error out on the specified warning type."),
+    cl::values(
+        clEnumValN(WNoError::Unknown, "unknown",
+                   "If set, unknown format options are only warned about.\n"
+                   "This can be used to enable formatting, even if the\n"
+                   "configuration contains unknown (newer) options.\n"
+                   "Use with caution, as this might lead to dramatically\n"
+                   "differing format depending on an option being\n"
+                   "supported or not.")),
+    cl::cat(ClangFormatCategory));
+
 static cl::opt<bool>
     ShowColors("fcolor-diagnostics",
                cl::desc("If set, and on a color-capable terminal controls "
@@ -391,7 +396,7 @@
 
   llvm::Expected<FormatStyle> FormatStyle =
       getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer(),
-               nullptr, AllowUnknownOptions.getValue());
+               nullptr, WNoErrorList.isSet(WNoError::Unknown));
   if (!FormatStyle) {
     llvm::errs() << llvm::toString(FormatStyle.takeError()) << "\n";
     return true;