Skip to content

Lint RST on GitHub Actions #1802

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

Merged
merged 4 commits into from
Feb 8, 2021
Merged

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented Feb 7, 2021

New version of #1668, main difference is the linter has been updated so the rst-backticks skips code blocks (lines beginning with four spaces).


Lint rules

This PR adds two reStructuredText lint rules and runs them on the CI using GitHub Actions. Example run.

  1. Detect single backticks, which should be double in RST for inline code, e.g. stuff fixed in Fix RST backticks #1554.

  2. Detect inline code touching normal text, e.g. stuff fixed in Fix incorrect backticks #1560.

make lint

It adds a standalone make command to lint locally:

make lint

The pre-commit dependency is installed if needed.

Optional git pre-commit hook

This uses the pre-commit tool for linting. It's possible, but completely optional, to use it locally and it'll check your changes when you're committing, and fail before commit if something is found.

Optional local set up (run once):

pip install -U pre-commit && pre-commit install

Then make changes and commit as normal:

git commit -m "PEP XXX: etc"

Lint all files:

pre-commit run --all-files

# Or this does the same thing
make lint

The very first run takes a little while to set things up, after that it's quick.

But again, local use of pre-commit is completely optional for those who aren't keen, and the CI will run the checks anyway.

And make lint can be used completely independently of the git pre-commit hook.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Do you have powers to merge here?

FWIW I think there are a few more PEPs that fail this test, maybe you can re-trigger a run?

@hugovk hugovk force-pushed the lint-rst-backticks branch from 7ccc045 to 9e1db9d Compare February 8, 2021 11:22
@hugovk
Copy link
Member Author

hugovk commented Feb 8, 2021

No, I don't have merge rights. I've rebased and fixed the new issues found PEP 646.

A couple of notes.

Note 1

3d9f45c

This:

(``Union`` is the one exception to this rule; see `Type Variable Tuples with ``Union```.)

Should be a link to this header:

Type Variable Tuples with ``Union``
-----------------------------------

But RST doesn't like code formatting inside links, make pep-0646.html gives:

docutils.utils.SystemMessage: pep-0646.rst:284: (ERROR/3) Unknown target name: "type variable tuples with ``union``".

See https://stackoverflow.com/q/4743845/724176 for ugly workarounds. So instead I've made the link without code formatting, and the HTML generation and link works.

Note 2

9e1db9d

@mrahtz:

This looks like it should be a link to a header:

Following `Type Variable Tuples Must Have Finite Length When Bound`, note

But there's no header with that name. "Type Variable Tuples Must Have Known Length" looks the closest to me. Is that the right one?

@mrahtz
Copy link
Contributor

mrahtz commented Feb 8, 2021

Super nice work! I was always a bit worried about linting when writing PEP 646.

Note 2 - yes, that's right, it should be "Type Variable Tuples Must Have Known Length". Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants