Skip to content

Commit

Permalink
D300: prevent autofix when both triples are in body (#8462)
Browse files Browse the repository at this point in the history
## Summary
Addresses
#8402 (comment)

## Test Plan

Added associated test
  • Loading branch information
T-256 authored Nov 3, 2023
1 parent 536ac55 commit 4982694
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
16 changes: 16 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pydocstyle/D300.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@ def ends_in_quote():

def contains_quote():
'Sum"\\mary.'


# OK
def contains_triples(t):
"""('''|\""")"""


# OK
def contains_triples(t):
'''(\'''|""")'''


# TODO: here should raise D300 for using dobule quotes instead,
# because escaped double quote does allow us.
def contains_triples(t):
'''(\""")'''
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ impl Violation for TripleSingleQuotes {
pub(crate) fn triple_quotes(checker: &mut Checker, docstring: &Docstring) {
let leading_quote = docstring.leading_quote();

let prefixes = docstring
.leading_quote()
let prefixes = leading_quote
.trim_end_matches(|c| c == '\'' || c == '"')
.to_owned();

let expected_quote = if docstring.body().contains("\"\"\"") {
if docstring.body().contains("\'\'\'") {
return;
}
Quote::Single
} else {
Quote::Double
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/ruff_linter/src/rules/pydocstyle/mod.rs
assertion_line: 134
---
D300.py:6:5: D300 Use triple double quotes `"""`
|
Expand All @@ -23,5 +24,8 @@ D300.py:10:5: D300 [*] Use triple double quotes `"""`
9 9 | def contains_quote():
10 |- 'Sum"\\mary.'
10 |+ """Sum"\\mary."""
11 11 |
12 12 |
13 13 | # OK


0 comments on commit 4982694

Please sign in to comment.