Skip to content

Commit 0ff97dd

Browse files
[fragment] Add a check for suffix of fragments files
1 parent 8ad19b3 commit 0ff97dd

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

script/check_newsfragments.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from __future__ import annotations
1010

1111
import argparse
12+
import difflib
1213
import re
1314
import sys
1415
from pathlib import Path
@@ -20,6 +21,21 @@
2021
"Follow-up in",
2122
"Fixes part of",
2223
]
24+
VALID_FILE_TYPE = frozenset(
25+
[
26+
"breaking",
27+
"user_action",
28+
"feature",
29+
"new_check",
30+
"removed_check",
31+
"extension",
32+
"false_positive",
33+
"false_negative",
34+
"bugfix",
35+
"other",
36+
"internal",
37+
]
38+
)
2339
ISSUES_KEYWORDS = "|".join(VALID_ISSUES_KEYWORDS)
2440
VALID_CHANGELOG_PATTERN = rf"(?P<description>(.*\n)*(.*\.\n))\n(?P<ref>({ISSUES_KEYWORDS}) (PyCQA/astroid)?#(?P<issue>\d+))"
2541
VALID_CHANGELOG_COMPILED_PATTERN: Pattern[str] = re.compile(
@@ -55,6 +71,18 @@ def check_file(file: Path, verbose: bool) -> bool:
5571
f"{file} must be named '{issue}.<fragmenttype>', after the issue it references."
5672
)
5773
return False
74+
if not any(file.suffix.endswith(t) for t in VALID_FILE_TYPE):
75+
suggestions = difflib.get_close_matches(file.suffix, VALID_FILE_TYPE)
76+
if suggestions:
77+
multiple_suggestions = "', '".join(f"{issue}.{s}" for s in suggestions)
78+
suggestion = f"should probably be named '{multiple_suggestions}'"
79+
else:
80+
multiple_suggestions = "', '".join(
81+
f"{issue}.{s}" for s in VALID_FILE_TYPE
82+
)
83+
suggestion = f"must be named one of '{multiple_suggestions}'"
84+
echo(f"{file} {suggestion} instead.")
85+
return False
5886
if verbose:
5987
echo(f"Checked '{file}': LGTM 🤖👍")
6088
return True

0 commit comments

Comments
 (0)