diff options
-rw-r--r-- | .pre-commit-config.yaml | 4 | ||||
-rw-r--r-- | script/fix_documentation.py | 21 | ||||
-rw-r--r-- | tests/checkers/unittest_spelling.py | 56 |
3 files changed, 37 insertions, 44 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f7c58420f..3f595c9ab 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,6 +38,10 @@ repos: - id: black args: [--safe, --quiet] exclude: *fixtures +- repo: https://github.com/Pierre-Sassoulas/black-disable-checker/ + rev: 0.0.1 + hooks: + - id: black-disable-checker - repo: local hooks: - id: pylint diff --git a/script/fix_documentation.py b/script/fix_documentation.py index f83327ec3..b83e4f3ec 100644 --- a/script/fix_documentation.py +++ b/script/fix_documentation.py @@ -1,11 +1,13 @@ """Small script to fix various issues with the documentation. Used by pre-commit.""" -# fmt: off + import argparse import re import sys from typing import List, Union -INVALID_CODE_BLOCK_PATTERN = r"(?<=\s`)([\w\-\.\(\)\=]+\s{0,1}[\w\-\.\(\)\=]*)(?=`[,\.]{0,1}\s|$)" +INVALID_CODE_BLOCK_PATTERN = ( + r"(?<=\s`)([\w\-\.\(\)\=]+\s{0,1}[\w\-\.\(\)\=]*)(?=`[,\.]{0,1}\s|$)" +) FILE_CHANGELOG = "ChangeLog" CHANGELOG_WHATS_NEW_PREFIX = "What's New in Pylint" @@ -23,25 +25,24 @@ def fix_inline_code_blocks(file_content: str) -> str: def changelog_insert_empty_lines(file_content: str) -> str: """Insert up to two empty lines before `What's New` entry in ChangeLog""" - lines = file_content.split('\n') + lines = file_content.split("\n") version_count = 0 for i, line in enumerate(lines): if line.startswith(CHANGELOG_WHATS_NEW_PREFIX): version_count += 1 - if ( - version_count == 1 or i < 2 - or lines[i - 1] == '' and lines[i - 2] == '' - ): + if version_count == 1 or i < 2 or lines[i - 1] == "" and lines[i - 2] == "": continue - lines.insert(i, '') - return '\n'.join(lines) + lines.insert(i, "") + return "\n".join(lines) def main(argv: Union[List[str], None] = None) -> int: argv = argv or sys.argv[1:] parser = argparse.ArgumentParser() parser.add_argument( - "filenames", nargs="*", metavar="FILES", + "filenames", + nargs="*", + metavar="FILES", help="File names to modify", ) args = parser.parse_args(argv) diff --git a/tests/checkers/unittest_spelling.py b/tests/checkers/unittest_spelling.py index 101357933..c14062d2d 100644 --- a/tests/checkers/unittest_spelling.py +++ b/tests/checkers/unittest_spelling.py @@ -388,12 +388,10 @@ class TestSpellingChecker(CheckerTestCase): @set_config(spelling_dict=spell_dict) def test_docstring_lines_that_look_like_comments_1(self): stmt = astroid.extract_node( - # fmt: off - 'def f():\n' - ' """\n' - ' # msitake\n' - ' """' - # fmt: on + '''def f(): + """ + # msitake + """''' ) with self.assertAddsMessages( Message( @@ -413,10 +411,8 @@ class TestSpellingChecker(CheckerTestCase): @set_config(spelling_dict=spell_dict) def test_docstring_lines_that_look_like_comments_2(self): stmt = astroid.extract_node( - # fmt: off - 'def f():\n' - ' """# msitake"""' - # fmt: on + '''def f(): + """# msitake"""''' ) with self.assertAddsMessages( Message( @@ -436,12 +432,10 @@ class TestSpellingChecker(CheckerTestCase): @set_config(spelling_dict=spell_dict) def test_docstring_lines_that_look_like_comments_3(self): stmt = astroid.extract_node( - # fmt: off - 'def f():\n' - ' """\n' - '# msitake\n' - ' """' - # fmt: on + '''def f(): + """ +# msitake + """''' ) with self.assertAddsMessages( Message( @@ -461,12 +455,10 @@ class TestSpellingChecker(CheckerTestCase): @set_config(spelling_dict=spell_dict) def test_docstring_lines_that_look_like_comments_4(self): stmt = astroid.extract_node( - # fmt: off - 'def f():\n' - ' """\n' - ' # cat\n' - ' """' - # fmt: on + '''def f(): + """ + # cat + """''' ) with self.assertAddsMessages(): self.checker.visit_functiondef(stmt) @@ -475,12 +467,10 @@ class TestSpellingChecker(CheckerTestCase): @set_config(spelling_dict=spell_dict) def test_docstring_lines_that_look_like_comments_5(self): stmt = astroid.extract_node( - # fmt: off - 'def f():\n' - ' """\n' - ' msitake # cat\n' - ' """' - # fmt: on + '''def f(): + """ + msitake # cat + """''' ) with self.assertAddsMessages( Message( @@ -500,12 +490,10 @@ class TestSpellingChecker(CheckerTestCase): @set_config(spelling_dict=spell_dict) def test_docstring_lines_that_look_like_comments_6(self): stmt = astroid.extract_node( - # fmt: off - 'def f():\n' - ' """\n' - ' cat # msitake\n' - ' """' - # fmt: on + '''def f(): + """ + cat # msitake + """''' ) with self.assertAddsMessages( Message( |