mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00

Previously the rule documentation referenced configuration options via full https:// URLs, which was bad for several reasons: * changing the website would mean you'd have to change all URLs * the links didn't work when building mkdocs locally * the URLs showed up in the `ruff rule` output * broken references weren't detected by our CI This commit solves all of these problems by post-processing the Markdown, recognizing sections such as: ## Options * `flake8-tidy-imports.ban-relative-imports` `cargo dev generate-all` will automatically linkify such references and panic if the referenced option doesn't exist. Note that the option can also be linked in the other Markdown sections via e.g. [`flake8-tidy-imports.ban-relative-imports`] since the post-processing code generates a CommonMark link definition. Resolves #2766.
1 KiB
1 KiB
relative-imports (TID252)
Derived from the flake8-tidy-imports linter.
Autofix is sometimes available.
What it does
Checks for relative imports.
Why is this bad?
Absolute imports, or relative imports from siblings, are recommended by PEP 8:
Absolute imports are recommended, as they are usually more readable and tend to be better behaved...
import mypkg.sibling from mypkg import sibling from mypkg.sibling import example
However, explicit relative imports are an acceptable alternative to absolute imports, especially when dealing with complex package layouts where using absolute imports would be unnecessarily verbose:
from . import sibling from .sibling import example
Options
Example
from .. import foo
Use instead:
from mypkg import foo