Преглед изворни кода

Fix check-diagnostics for pre-commit (#2683)

Unused diagnostics were incorrectly always returning "false" regardless of whether there was an issue. It was still looking for registry file changes, not kind file changes. Also, this should only be run once per pre-commit run (pass_filenames=false).

Remove the one unused diagnostic.
Jon Ross-Perkins пре 3 година
родитељ
комит
584a50d0dc

+ 3 - 1
.pre-commit-config.yaml

@@ -103,8 +103,10 @@ repos:
           (?x)^(
               toolchain/.*\.cpp|
               toolchain/.*\.h|
-              toolchain/diagnostics/diagnostic_registry\.def
+              toolchain/diagnostics/check_diagnostics\.py|
+              toolchain/diagnostics/diagnostic_kind\.def
           )$
+        pass_filenames: false
 
   # Run linters last, as formatters and other checks may fix issues.
   - repo: local

+ 4 - 2
toolchain/diagnostics/check_diagnostics.py

@@ -15,8 +15,8 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 import collections
 from concurrent import futures
 import itertools
-from pathlib import Path
 import os
+from pathlib import Path
 import re
 import sys
 from typing import Dict, List, NamedTuple, Set
@@ -98,9 +98,11 @@ def check_uniqueness(uses: Dict[str, List[Location]]) -> bool:
 def check_unused(decls: Set[str], uses: Dict[str, List[Location]]) -> bool:
     """If any diagnostic is unused, prints an error and returns true."""
     unused = decls.difference(uses.keys())
+    if not unused:
+        return False
     for diag in sorted(unused):
         print(f"Unused diagnostic: {diag}")
-    return False
+    return True
 
 
 def main() -> None:

+ 0 - 3
toolchain/diagnostics/diagnostic_kind.def

@@ -84,9 +84,6 @@ CARBON_DIAGNOSTIC_KIND(ExpectedDeclarationName)
 CARBON_DIAGNOSTIC_KIND(ExpectedDeclarationSemiOrDefinition)
 CARBON_DIAGNOSTIC_KIND(MethodImplNotAllowed)
 
-// Class and interface diagnostics
-CARBON_DIAGNOSTIC_KIND(ExpectedDeducedParam)
-
 // ============================================================================
 // Semantics diagnostics
 // ============================================================================