Skip to content

Commit

Permalink
Add rst-directive-space check
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Jan 10, 2023
1 parent 72bd2c9 commit 83f55a4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
entry: '^\s*\.\. [a-z]+:$'
language: pygrep
types: [rst]
- id: rst-directive-space
name: rst directives space before two colons
description: 'Detect mistake of additional space in rst directive'
entry: '^\s*\.\. [a-z]+ ::$'
language: pygrep
types: [rst]
- id: rst-inline-touching-normal
name: rst ``inline code`` next to normal text
description: 'Detect mistake of inline code touching normal text in rst'
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ For example, a hook which targets python will be called `python-...`.
- **`python-use-type-annotations`**: Enforce that python3.6+ type annotations are used instead of type comments
- **`rst-backticks`**: Detect common mistake of using single backticks when writing rst
- **`rst-directive-colons`**: Detect mistake of rst directive not ending with double colon
- **`rst-directive-space`**: Detect mistake of additional space in rst directive
- **`rst-inline-touching-normal`**: Detect mistake of inline code touching normal text in rst
- **`text-unicode-replacement-char`**: Forbid files which have a UTF-8 Unicode replacement character
22 changes: 22 additions & 0 deletions tests/hooks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,27 @@ def test_rst_directive_colons_negative(s):
assert not HOOKS['rst-directive-colons'].search(s)


@pytest.mark.parametrize(
's',
(
' .. warning ::',
'.. warning ::',
),
)
def test_rst_directive_space_positive(s):
assert HOOKS['rst-directive-space'].search(s)


@pytest.mark.parametrize(
's',
(
'.. warning::',
'.. code:: python',
),
)
def test_rst_directive_space_negative(s):
assert not HOOKS['rst-directive-space'].search(s)


def test_that_hooks_are_sorted():
assert list(HOOKS) == sorted(HOOKS)

0 comments on commit 83f55a4

Please sign in to comment.