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

Fix reference definition labels for backtick-quoted shortcut links #16035

Merged
merged 4 commits into from
Feb 10, 2025

Conversation

InSyncWithFoo
Copy link
Contributor

@InSyncWithFoo InSyncWithFoo commented Feb 8, 2025

Summary

Resolves #16010.

The changes boil down to something like this:

-/// The [FastAPI documentation] recommends the use of [`typing.Annotated`]
+/// The [FastAPI documentation] recommends the use of [`typing.Annotated`][typing-annotated]

-/// [typing.Annotated]: https://docs.python.org/3/library/typing.html#typing.Annotated
+/// [typing-annotated]: https://docs.python.org/3/library/typing.html#typing.Annotated

Test Plan

Mkdocs:

GitHub:

Why is this bad?

The FastAPI documentation recommends the use of typing.Annotated

...

CommonMark dingus:

<h2>Why is this bad?</h2>
<p>The <a href="https://fastapi.tiangolo.com/tutorial/query-params-str-validations/?h=annotated#advantages-of-annotated">FastAPI documentation</a> recommends the use of <a href="https://docs.python.org/3/library/typing.html#typing.Annotated"><code>typing.Annotated</code></a></p>
<p>...</p>

@InSyncWithFoo
Copy link
Contributor Author

InSyncWithFoo commented Feb 8, 2025

That Mkdocs recognizes links like [`typing.Annotated`] in the first place is probably because it uses @Python-Markdown/markdown, an implementation of the original Markdown rather than CommonMark or GFM.


I think that's all of them. More importantly, there should be a test somewhere so that such a link can't possibly be accidentally introduced again. Where would I even put that?

Copy link
Contributor

github-actions bot commented Feb 8, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@Daverball
Copy link
Contributor

I think that's all of them. More importantly, there should be a test somewhere so that such a link can't possibly be accidentally introduced again. Where would I even put that?

Possibly here? https://github.com/astral-sh/ruff/blob/main/scripts/check_docs_formatted.py

That's where all of the other custom docs checks appear to happen. Although the main purpose appears to be ensuring that the examples are formatted correctly, there are a couple of unrelated checks as well, like ensuring the required sections for rule docs are present.

@InSyncWithFoo
Copy link
Contributor Author

Possibly here? https://github.com/astral-sh/ruff/blob/main/scripts/check_docs_formatted.py

Section headers and code blocks are easy to check for, but inline links aren't. I imagine that would take quite some manual parsing/regexes on top of a list of every option known to Ruff.

@MichaReiser
Copy link
Member

Would you mind updating your test plan and showing the rendered documentation for a page before/after your change (doesn't have to be for all of them, just pick one ;))

@MichaReiser MichaReiser added the documentation Improvements or additions to documentation label Feb 8, 2025
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

It would be great if we'd have some linting or at least, guidance in the contribution guidelines. I otherwise worry, that we'll introduce incompatible links in the future. But that's something we can do separately.

Thank you!

@MichaReiser MichaReiser merged commit b69eb90 into astral-sh:main Feb 10, 2025
21 checks passed
@InSyncWithFoo InSyncWithFoo deleted the docs-links-without-targets branch February 10, 2025 16:15
dcreager added a commit that referenced this pull request Feb 10, 2025
* main: (991 commits)
  [red-knot] Resolve `Options` to `Settings` (#16000)
  Bump version to 0.9.6 (#16074)
  Revert tailwindcss v4 update (#16075)
  Improve migration document (#16072)
  Fix reference definition labels for backtick-quoted shortcut links (#16035)
  RUF009 should behave similar to B008 and ignore attributes with immutable types (#16048)
  [`pylint`] Also report when the object isn't a literal (`PLE1310`) (#15985)
  Update Rust crate rustc-hash to v2.1.1 (#16060)
  Root exclusions in the server to project root (#16043)
  Directly include `Settings` struct for the server (#16042)
  Update Rust crate clap to v4.5.28 (#16059)
  Update Rust crate strum_macros to 0.27.0 (#16065)
  Update NPM Development dependencies (#16067)
  Update Rust crate uuid to v1.13.1 (#16066)
  Update Rust crate strum to 0.27.0 (#16064)
  Update pre-commit dependencies (#16063)
  Update dependency ruff to v0.9.5 (#16062)
  Update Rust crate toml to v0.8.20 (#16061)
  [`flake8-builtins`] Make strict module name comparison optional (`A005`) (#15951)
  [`ruff`] Indented form feeds (`RUF054`) (#16049)
  ...
MichaReiser pushed a commit that referenced this pull request Feb 14, 2025
## Summary

Follow-up to #16035.

`check_docs_formatted.py` will now report backtick-quoted shortcut links
in rule documentation. It uses a regular expression to find them. Such a
link:

* Starts with `[`, followed by <code>\`</code>, then a "name" sequence
of at least one non-backtick non-newline character, followed by another
<code>\`</code>, then ends with `]`.
* Is not followed by either a `[` or a `(`.
* Is not placed within a code block.

If the name is a known Ruff option name, that link is not considered a
violation.

## Test Plan

Manual.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Backtick-quoted shortcut links in rule documentation
3 participants