Skip to content

Commit cb9f7b6

Browse files
committed
docs(rules): expand D300 description to include single quotes
1 parent 7947ac3 commit cb9f7b6

2 files changed

Lines changed: 68 additions & 2 deletions

File tree

crates/ruff_linter/src/rules/pydocstyle/rules/triple_quotes.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::docstrings::Docstring;
77
use crate::{Edit, Fix, FixAvailability, Violation};
88

99
/// ## What it does
10-
/// Checks for docstrings that use `'''triple single quotes'''` instead of
11-
/// `"""triple double quotes"""`.
10+
/// Checks for docstrings that use single quotes (`'`) or triple single quotes (`'''`)
11+
/// instead of triple double quotes (`"""`).
1212
///
1313
/// ## Why is this bad?
1414
/// [PEP 257](https://peps.python.org/pep-0257/#what-is-a-docstring) recommends
@@ -19,12 +19,18 @@ use crate::{Edit, Fix, FixAvailability, Violation};
1919
/// ```python
2020
/// def kos_root():
2121
/// '''Return the pathname of the KOS root directory.'''
22+
///
23+
/// def kos_branch():
24+
/// 'Return the branch name.'
2225
/// ```
2326
///
2427
/// Use instead:
2528
/// ```python
2629
/// def kos_root():
2730
/// """Return the pathname of the KOS root directory."""
31+
///
32+
/// def kos_branch():
33+
/// """Return the branch name."""
2834
/// ```
2935
///
3036
/// ## Formatter compatibility

docs/rules/triple-single-quotes.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# triple-single-quotes (D300)
2+
3+
<small>
4+
Added in <a href="https://github.com/astral-sh/ruff/releases/tag/v0.0.69">v0.0.69</a> ·
5+
<a href="https://github.com/astral-sh/ruff/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20(%27triple-single-quotes%27%20OR%20D300)" target="_blank">Related issues</a> ·
6+
<a href="https://github.com/astral-sh/ruff/blob/main/crates%2Fruff_linter%2Fsrc%2Frules%2Fpydocstyle%2Frules%2Ftriple_quotes.rs#L50" target="_blank">View source</a>
7+
</small>
8+
9+
Derived from the **[pydocstyle](../rules.md#pydocstyle-d)** linter.
10+
11+
Fix is sometimes available.
12+
13+
## What it does
14+
15+
Checks for docstrings that use single quotes (`'`) or triple single quotes (`'''`)
16+
instead of triple double quotes (`"""`).
17+
18+
## Why is this bad?
19+
20+
[PEP 257](https://peps.python.org/pep-0257/#what-is-a-docstring) recommends
21+
the use of `"""triple double quotes"""` for docstrings, to ensure
22+
consistency.
23+
24+
## Example
25+
26+
```python
27+
def kos_root():
28+
'''Return the pathname of the KOS root directory.'''
29+
30+
def kos_branch():
31+
'Return the branch name.'
32+
```
33+
34+
Use instead:
35+
36+
```python
37+
def kos_root():
38+
"""Return the pathname of the KOS root directory."""
39+
40+
def kos_branch():
41+
"""Return the branch name."""
42+
```
43+
44+
## Formatter compatibility
45+
46+
We recommend against using this rule alongside the [formatter]. The
47+
formatter enforces consistent quotes, making the rule redundant.
48+
49+
## Options
50+
51+
- [`lint.pydocstyle.ignore-decorators`][lint.pydocstyle.ignore-decorators]
52+
53+
## References
54+
55+
- [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
56+
- [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html)
57+
- [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings)
58+
59+
[formatter]: https://docs.astral.sh/ruff/formatter/
60+
[lint.pydocstyle.ignore-decorators]: ../settings.md#lint_pydocstyle_ignore-decorators

0 commit comments

Comments
 (0)