diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2022-12-05 19:23:51 +0100 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2022-12-05 23:29:44 +0100 |
commit | 0ff97ddd3ff4fc1e044f76b72cea6c3e1b7e6127 (patch) | |
tree | 9d10565719cca94fa5c73f46e7f776210542d6a6 /script | |
parent | 8ad19b328cfab643176cca004d685ef17228fd32 (diff) | |
download | pylint-git-0ff97ddd3ff4fc1e044f76b72cea6c3e1b7e6127.tar.gz |
[fragment] Add a check for suffix of fragments files
Diffstat (limited to 'script')
-rw-r--r-- | script/check_newsfragments.py | 28 |
1 files changed, 28 insertions, 0 deletions
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 |