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.
This commit is contained in:
Jon Ross-Perkins
2023-03-15 18:01:48 -07:00
committed by GitHub
parent 2cc64ee38a
commit 584a50d0dc
3 changed files with 7 additions and 6 deletions
+3 -1
View File
@@ -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
View File
@@ -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:
@@ -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
// ============================================================================