Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for dangling hyphens #56

Merged
merged 4 commits into from
Mar 15, 2023

Conversation

hugovk
Copy link
Collaborator

@hugovk hugovk commented Feb 25, 2023

Fixes #54.

The failures are caused by finding IRL trailing hyphens in friend projects: pandas, cpython, peps, sympy.

E         + /home/runner/work/sphinx-lint/sphinx-lint/tests/fixtures/friends/pandas/doc/source/ecosystem.rst:380: Line ends with dangling hyphen (dangling-hyphen)
E         + /home/runner/work/sphinx-lint/sphinx-lint/tests/fixtures/friends/pandas/doc/source/user_guide/integer_na.rst:61: Line ends with dangling hyphen (dangling-hyphen)
E         + /home/runner/work/sphinx-lint/sphinx-lint/tests/fixtures/friends/cpython/Doc/library/collections.rst:641: Line ends with dangling hyphen (dangling-hyphen)
E         + /home/runner/work/sphinx-lint/sphinx-lint/tests/fixtures/friends/cpython/Doc/library/decimal.rst:295: Line ends with dangling hyphen (dangling-hyphen)
E         + /home/runner/work/sphinx-lint/sphinx-lint/tests/fixtures/friends/cpython/Doc/library/decimal.rst:327: Line ends with dangling hyphen (dangling-hyphen)
E         + /home/runner/work/sphinx-lint/sphinx-lint/tests/fixtures/friends/peps/pep-0560.rst:283: Line ends with dangling hyphen (dangling-hyphen)
E         + /home/runner/work/sphinx-lint/sphinx-lint/tests/fixtures/friends/peps/pep-0554.rst:1274: Line ends with dangling hyphen (dangling-hyphen)
E         + /home/runner/work/sphinx-lint/sphinx-lint/tests/fixtures/friends/peps/pep-0633.rst:119: Line ends with dangling hyphen (dangling-hyphen)
E         + /home/runner/work/sphinx-lint/sphinx-lint/tests/fixtures/friends/sympy/doc/src/contributing/docstring.rst:50: Line ends with dangling hyphen (dangling-hyphen)
E         + /home/runner/work/sphinx-lint/sphinx-lint/tests/fixtures/friends/sympy/doc/src/contributing/docstring.rst:741: Line ends with dangling hyphen (dangling-hyphen)
E         + /home/runner/work/sphinx-lint/sphinx-lint/tests/fixtures/friends/sympy/doc/src/modules/vector/coordsys.rst:119: Line ends with dangling hyphen (dangling-hyphen)
E         + /home/runner/work/sphinx-lint/sphinx-lint/tests/fixtures/friends/sympy/doc/src/modules/vector/coordsys.rst:217: Line ends with dangling hyphen (dangling-hyphen)
E         + /home/runner/work/sphinx-lint/sphinx-lint/tests/fixtures/friends/sympy/doc/src/modules/combinatorics/fp_groups.rst:7: Line ends with dangling hyphen (dangling-hyphen)

Some false positives in there, such as:

E         + /home/runner/work/sphinx-lint/sphinx-lint/tests/fixtures/friends/cpython/Doc/library/decimal.rst:295: Line ends with dangling hyphen (dangling-hyphen)
E         + /home/runner/work/sphinx-lint/sphinx-lint/tests/fixtures/friends/cpython/Doc/library/decimal.rst:327: Line ends with dangling hyphen (dangling-hyphen)

Both are inside .. doctest:: blocks:

https://github.com/python/cpython/blob/a35fd38b57d3eb05074ca36f3d57e1993c44ddc9/Doc/library/decimal.rst?plain=1#L295
https://github.com/python/cpython/blob/a35fd38b57d3eb05074ca36f3d57e1993c44ddc9/Doc/library/decimal.rst?plain=1#L327

We're using rst_only=True in the check to skip things like code blocks, but we're detecting doctest blocks as non-code. So let's fix that too.


Also, on macOS, I get failures like this, due to the annoying habit of macOS to create .DS_Store files, so let's skip them:

tests/test_xpass_friends.py:30:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pathlib.py:1058: in read_text
    with self.open(mode='r', encoding=encoding, errors=errors) as f:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = PosixPath('/Users/huvankem/github/sphinx-lint/tests/fixtures/friends/.DS_Store/flags'), mode = 'r', buffering = -1, encoding = 'UTF-8'
errors = None, newline = None

    def open(self, mode='r', buffering=-1, encoding=None,
             errors=None, newline=None):
        """
        Open the file pointed by this path and return a file object, as
        the built-in open() function does.
        """
        if "b" not in mode:
            encoding = io.text_encoding(encoding)
>       return io.open(self, mode, buffering, encoding, errors, newline)
E       NotADirectoryError: [Errno 20] Not a directory: '/Users/huvankem/github/sphinx-lint/tests/fixtures/friends/.DS_Store/flags'

/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pathlib.py:1044: NotADirectoryError

That leaves:

E         + /Users/huvankem/github/sphinx-lint/tests/fixtures/friends/sympy/doc/src/contributing/docstring.rst:50: Line ends with dangling hyphen (dangling-hyphen)
E         + /Users/huvankem/github/sphinx-lint/tests/fixtures/friends/sympy/doc/src/contributing/docstring.rst:741: Line ends with dangling hyphen (dangling-hyphen)
E         + /Users/huvankem/github/sphinx-lint/tests/fixtures/friends/sympy/doc/src/modules/combinatorics/fp_groups.rst:7: Line ends with dangling hyphen (dangling-hyphen)
E         + /Users/huvankem/github/sphinx-lint/tests/fixtures/friends/sympy/doc/src/modules/vector/coordsys.rst:119: Line ends with dangling hyphen (dangling-hyphen)
E         + /Users/huvankem/github/sphinx-lint/tests/fixtures/friends/sympy/doc/src/modules/vector/coordsys.rst:217: Line ends with dangling hyphen (dangling-hyphen)
E         + /Users/huvankem/github/sphinx-lint/tests/fixtures/friends/peps/pep-0554.rst:1274: Line ends with dangling hyphen (dangling-hyphen)
E         + /Users/huvankem/github/sphinx-lint/tests/fixtures/friends/peps/pep-0633.rst:119: Line ends with dangling hyphen (dangling-hyphen)
E         + /Users/huvankem/github/sphinx-lint/tests/fixtures/friends/peps/pep-0560.rst:283: Line ends with dangling hyphen (dangling-hyphen)
E         + /Users/huvankem/github/sphinx-lint/tests/fixtures/friends/pandas/doc/source/ecosystem.rst:380: Line ends with dangling hyphen (dangling-hyphen)
E         + /Users/huvankem/github/sphinx-lint/tests/fixtures/friends/pandas/doc/source/user_guide/integer_na.rst:61: Line ends with dangling hyphen (dangling-hyphen)

These are valid, except these use hyphens like colons:

https://github.com/sympy/sympy/blob/5d2556f1546b1fe64e175fa808f495a58c3ac998/doc/src/modules/vector/coordsys.rst?plain=1#L119

https://github.com/sympy/sympy/blob/5d2556f1546b1fe64e175fa808f495a58c3ac998/doc/src/modules/vector/coordsys.rst?plain=1#L217


How should we deal with the failing "friend" tests?

@JelleZijlstra
Copy link
Contributor

Thanks! Perhaps the sympy ones could be considered true positives; it's not grammatical to use a hyphen there. Alternatively, perhaps we could exclude lines right before a blank line from the check.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@hugovk
Copy link
Collaborator Author

hugovk commented Feb 25, 2023

Thanks! Perhaps the sympy ones could be considered true positives; it's not grammatical to use a hyphen there. Alternatively, perhaps we could exclude lines right before a blank line from the check.

Yeah, I'd prefer a colon there too.

@JulienPalard
Copy link
Collaborator

Thanks a lot of this PR!

Let's fix friend projects and merge it! (Better not merge it before, it could break their CI if they did not pinned the sphinx-lint version).

@hugovk
Copy link
Collaborator Author

hugovk commented Mar 11, 2023

Thanks for fixing the friend projects! This CI is now passing: https://github.com/hugovk/sphinx-lint/actions/runs/4393071119

@JulienPalard JulienPalard merged commit 4328f8f into sphinx-contrib:main Mar 15, 2023
@JulienPalard
Copy link
Collaborator

Thanks for this PR!

@hugovk hugovk deleted the dangling-hyphen branch March 16, 2023 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lint against hyphens at the end of lines
3 participants