Skip to content

Commit b69eb90

Browse files
Fix reference definition labels for backtick-quoted shortcut links (#16035)
## Summary Resolves #16010. The changes boil down to something like this: ```diff -/// 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: ![](https://github.com/user-attachments/assets/a2e6bf22-56fa-4b2c-9500-1c1256c5a218) GitHub: > ## Why is this bad? > The [FastAPI documentation] recommends the use of [`typing.Annotated`][typing-annotated] > > ... > > [FastAPI documentation]: https://fastapi.tiangolo.com/tutorial/query-params-str-validations/?h=annotated#advantages-of-annotated > [typing-annotated]: https://docs.python.org/3/library/typing.html#typing.Annotated [CommonMark dingus](https://spec.commonmark.org/dingus/?text=%23%23%20Why%20is%20this%20bad%3F%0AThe%20%5BFastAPI%20documentation%5D%20recommends%20the%20use%20of%20%5B%60typing.Annotated%60%5D%5Btyping-annotated%5D%0A%0A...%0A%0A%5BFastAPI%20documentation%5D%3A%20https%3A%2F%2Ffastapi.tiangolo.com%2Ftutorial%2Fquery-params-str-validations%2F%3Fh%3Dannotated%23advantages-of-annotated%0A%5Btyping-annotated%5D%3A%20https%3A%2F%2Fdocs.python.org%2F3%2Flibrary%2Ftyping.html%23typing.Annotated): ```html <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> ```
1 parent d2f661f commit b69eb90

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ use crate::settings::types::PythonVersion;
1414
/// Identifies FastAPI routes with deprecated uses of `Depends` or similar.
1515
///
1616
/// ## Why is this bad?
17-
/// The [FastAPI documentation] recommends the use of [`typing.Annotated`] for
18-
/// defining route dependencies and parameters, rather than using `Depends`,
17+
/// The [FastAPI documentation] recommends the use of [`typing.Annotated`][typing-annotated]
18+
/// for defining route dependencies and parameters, rather than using `Depends`,
1919
/// `Query` or similar as a default value for a parameter. Using this approach
2020
/// everywhere helps ensure consistency and clarity in defining dependencies
2121
/// and parameters.
2222
///
2323
/// `Annotated` was added to the `typing` module in Python 3.9; however,
24-
/// the third-party [`typing_extensions`] package provides a backport that can be
25-
/// used on older versions of Python.
24+
/// the third-party [`typing_extensions`][typing-extensions] package
25+
/// provides a backport that can be used on older versions of Python.
2626
///
2727
/// ## Example
2828
///
@@ -60,9 +60,9 @@ use crate::settings::types::PythonVersion;
6060
/// return commons
6161
/// ```
6262
///
63-
/// [fastAPI documentation]: https://fastapi.tiangolo.com/tutorial/query-params-str-validations/?h=annotated#advantages-of-annotated
64-
/// [typing.Annotated]: https://docs.python.org/3/library/typing.html#typing.Annotated
65-
/// [typing_extensions]: https://typing-extensions.readthedocs.io/en/stable/
63+
/// [FastAPI documentation]: https://fastapi.tiangolo.com/tutorial/query-params-str-validations/?h=annotated#advantages-of-annotated
64+
/// [typing-annotated]: https://docs.python.org/3/library/typing.html#typing.Annotated
65+
/// [typing-extensions]: https://typing-extensions.readthedocs.io/en/stable/
6666
#[derive(ViolationMetadata)]
6767
pub(crate) struct FastApiNonAnnotatedDependency {
6868
py_version: PythonVersion,

crates/ruff_linter/src/rules/flake8_bandit/rules/shell_injection.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ impl Violation for StartProcessWithAShell {
194194
/// This rule specifically flags functions in the `os` module that spawn
195195
/// subprocesses *without* the use of a shell. Note that these typically pose a
196196
/// much smaller security risk than subprocesses that are started *with* a
197-
/// shell, which are flagged by [`start-process-with-a-shell`] (`S605`). This
198-
/// gives you the option of enabling one rule while disabling the other if you
199-
/// decide that the security risk from these functions is acceptable for your
200-
/// use case.
197+
/// shell, which are flagged by [`start-process-with-a-shell`][S605] (`S605`).
198+
/// This gives you the option of enabling one rule while disabling the other
199+
/// if you decide that the security risk from these functions is acceptable
200+
/// for your use case.
201201
///
202202
/// ## Example
203203
/// ```python
@@ -208,7 +208,7 @@ impl Violation for StartProcessWithAShell {
208208
/// os.spawnlp(os.P_NOWAIT, "/bin/mycmd", "mycmd", arbitrary_user_input)
209209
/// ```
210210
///
211-
/// [start-process-with-a-shell]: https://docs.astral.sh/ruff/rules/start-process-with-a-shell/#start-process-with-a-shell-s605
211+
/// [S605]: https://docs.astral.sh/ruff/rules/start-process-with-a-shell
212212
#[derive(ViolationMetadata)]
213213
pub(crate) struct StartProcessWithNoShell;
214214

crates/ruff_linter/src/rules/pyupgrade/rules/pep695/private_type_parameter.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ use crate::{
5555
/// ## See also
5656
///
5757
/// This rule renames private [PEP 695] type parameters but doesn't convert pre-[PEP 695] generics
58-
/// to the new format. See [`non-pep695-generic-function`] and [`non-pep695-generic-class`] for
59-
/// rules that will make this transformation. Those rules do not remove unused type variables after
60-
/// their changes, so you may also want to consider enabling [`unused-private-type-var`] to complete
58+
/// to the new format. See [`non-pep695-generic-function`][UP047] and
59+
/// [`non-pep695-generic-class`][UP046] for rules that will make this transformation.
60+
/// Those rules do not remove unused type variables after their changes,
61+
/// so you may also want to consider enabling [`unused-private-type-var`][PYI018] to complete
6162
/// the transition to [PEP 695] generics.
6263
///
6364
/// [PEP 695]: https://peps.python.org/pep-0695/
64-
/// [non-pep695-generic-function]: https://docs.astral.sh/ruff/rules/non-pep695-generic-function
65-
/// [non-pep695-generic-class]: https://docs.astral.sh/ruff/rules/non-pep695-generic-class
66-
/// [unused-private-type-var]: https://docs.astral.sh/ruff/rules/unused-private-type-var
65+
/// [UP047]: https://docs.astral.sh/ruff/rules/non-pep695-generic-function
66+
/// [UP046]: https://docs.astral.sh/ruff/rules/non-pep695-generic-class
67+
/// [PYI018]: https://docs.astral.sh/ruff/rules/unused-private-type-var
6768
#[derive(ViolationMetadata)]
6869
pub(crate) struct PrivateTypeParameter {
6970
kind: ParamKind,

crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ use crate::Locator;
3535
/// 5. The string references variables that are not in scope, or it doesn't capture variables at all.
3636
/// 6. Any format specifiers in the potential f-string are invalid.
3737
/// 7. The string is part of a function call that is known to expect a template string rather than an
38-
/// evaluated f-string: for example, a [`logging`] call, a [`gettext`] call, or a [fastAPI path].
38+
/// evaluated f-string: for example, a [`logging`][logging] call, a [`gettext`][gettext] call,
39+
/// or a [FastAPI path].
3940
///
4041
/// ## Example
4142
///
@@ -54,7 +55,7 @@ use crate::Locator;
5455
///
5556
/// [logging]: https://docs.python.org/3/howto/logging-cookbook.html#using-particular-formatting-styles-throughout-your-application
5657
/// [gettext]: https://docs.python.org/3/library/gettext.html
57-
/// [fastAPI path]: https://fastapi.tiangolo.com/tutorial/path-params/
58+
/// [FastAPI path]: https://fastapi.tiangolo.com/tutorial/path-params/
5859
#[derive(ViolationMetadata)]
5960
pub(crate) struct MissingFStringSyntax;
6061

crates/ruff_linter/src/rules/ruff/rules/unsafe_markup_use.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ use ruff_text_size::Ranged;
99
use crate::{checkers::ast::Checker, settings::LinterSettings};
1010

1111
/// ## What it does
12-
/// Checks for non-literal strings being passed to [`markupsafe.Markup`].
12+
/// Checks for non-literal strings being passed to [`markupsafe.Markup`][markupsafe-markup].
1313
///
1414
/// ## Why is this bad?
15-
/// [`markupsafe.Markup`] does not perform any escaping, so passing dynamic
16-
/// content, like f-strings, variables or interpolated strings will potentially
17-
/// lead to XSS vulnerabilities.
15+
/// [`markupsafe.Markup`][markupsafe-markup] does not perform any escaping,
16+
/// so passing dynamic content, like f-strings, variables or interpolated strings
17+
/// will potentially lead to XSS vulnerabilities.
1818
///
19-
/// Instead you should interpolate the [`markupsafe.Markup`] object.
19+
/// Instead you should interpolate the `Markup` object.
2020
///
2121
/// Using [`lint.ruff.extend-markup-names`] additional objects can be
22-
/// treated like [`markupsafe.Markup`].
22+
/// treated like `Markup`.
2323
///
2424
/// This rule was originally inspired by [flake8-markupsafe] but doesn't carve
2525
/// out any exceptions for i18n related calls by default.
@@ -72,7 +72,7 @@ use crate::{checkers::ast::Checker, settings::LinterSettings};
7272
/// - [MarkupSafe](https://pypi.org/project/MarkupSafe/)
7373
/// - [`markupsafe.Markup`](https://markupsafe.palletsprojects.com/en/stable/escaping/#markupsafe.Markup)
7474
///
75-
/// [markupsafe.Markup]: https://markupsafe.palletsprojects.com/en/stable/escaping/#markupsafe.Markup
75+
/// [markupsafe-markup]: https://markupsafe.palletsprojects.com/en/stable/escaping/#markupsafe.Markup
7676
/// [flake8-markupsafe]: https://github.com/vmagamedov/flake8-markupsafe
7777
#[derive(ViolationMetadata)]
7878
pub(crate) struct UnsafeMarkupUse {
@@ -87,9 +87,7 @@ impl Violation for UnsafeMarkupUse {
8787
}
8888
}
8989

90-
/// Checks for unsafe calls to `[markupsafe.Markup]`.
91-
///
92-
/// [markupsafe.Markup]: https://markupsafe.palletsprojects.com/en/stable/escaping/#markupsafe.Markup
90+
/// RUF035
9391
pub(crate) fn unsafe_markup_call(checker: &Checker, call: &ExprCall) {
9492
if checker.settings.ruff.extend_markup_names.is_empty()
9593
&& !(checker.semantic().seen_module(Modules::MARKUPSAFE)

0 commit comments

Comments
 (0)