summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/whatsnew/fragments/4836.new_check (renamed from doc/whatsnew/fragments/4836.newcheck)0
-rw-r--r--script/check_newsfragments.py28
2 files changed, 28 insertions, 0 deletions
diff --git a/doc/whatsnew/fragments/4836.newcheck b/doc/whatsnew/fragments/4836.new_check
index ba14251af..ba14251af 100644
--- a/doc/whatsnew/fragments/4836.newcheck
+++ b/doc/whatsnew/fragments/4836.new_check
diff --git a/script/check_newsfragments.py b/script/check_newsfragments.py
index 3327d2d5d..62560c9da 100644
--- a/script/check_newsfragments.py
+++ b/script/check_newsfragments.py
@@ -9,6 +9,7 @@ Used by pre-commit.
from __future__ import annotations
import argparse
+import difflib
import re
import sys
from pathlib import Path
@@ -20,6 +21,21 @@ VALID_ISSUES_KEYWORDS = [
"Follow-up in",
"Fixes part of",
]
+VALID_FILE_TYPE = frozenset(
+ [
+ "breaking",
+ "user_action",
+ "feature",
+ "new_check",
+ "removed_check",
+ "extension",
+ "false_positive",
+ "false_negative",
+ "bugfix",
+ "other",
+ "internal",
+ ]
+)
ISSUES_KEYWORDS = "|".join(VALID_ISSUES_KEYWORDS)
VALID_CHANGELOG_PATTERN = rf"(?P<description>(.*\n)*(.*\.\n))\n(?P<ref>({ISSUES_KEYWORDS}) (PyCQA/astroid)?#(?P<issue>\d+))"
VALID_CHANGELOG_COMPILED_PATTERN: Pattern[str] = re.compile(
@@ -55,6 +71,18 @@ def check_file(file: Path, verbose: bool) -> bool:
f"{file} must be named '{issue}.<fragmenttype>', after the issue it references."
)
return False
+ if not any(file.suffix.endswith(t) for t in VALID_FILE_TYPE):
+ suggestions = difflib.get_close_matches(file.suffix, VALID_FILE_TYPE)
+ if suggestions:
+ multiple_suggestions = "', '".join(f"{issue}.{s}" for s in suggestions)
+ suggestion = f"should probably be named '{multiple_suggestions}'"
+ else:
+ multiple_suggestions = "', '".join(
+ f"{issue}.{s}" for s in VALID_FILE_TYPE
+ )
+ suggestion = f"must be named one of '{multiple_suggestions}'"
+ echo(f"{file} {suggestion} instead.")
+ return False
if verbose:
echo(f"Checked '{file}': LGTM 🤖👍")
return True