Skip to content

Commit

Permalink
D300: prevent autofix when both triples are in body
Browse files Browse the repository at this point in the history
  • Loading branch information
Tester authored and Tester committed Nov 3, 2023
1 parent 7fa6ac9 commit 5cba785
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 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,8 @@ def ends_in_quote():

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


# OK
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 5cba785

Please sign in to comment.