Skip to content

Commit

Permalink
Move D300 fix to preview
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Oct 19, 2023
1 parent 669558c commit c26ce2b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

### Rule changes
- Add unsafe fix for `escape-sequence-in-docstring` (`D301`) (#7970)
- Add fix for `triple-single-quotes` (`D300`) (#7967)

### Configuration
- Respect `#(deprecated)` attribute in configuration options (#8035)
Expand All @@ -18,6 +17,7 @@
- [`pylint`] Implement `misplaced-bare-raise` (`E0704`) (#7961)
- [`pylint`] Implement `global-at-module-level` (`W0604`) (#8058)
- [`pylint`] Implement `unspecified-encoding` (`PLW1514`) (#7939)
- Add fix for `triple-single-quotes` (`D300`) (#7967)


### Formatter
Expand Down
28 changes: 16 additions & 12 deletions crates/ruff_linter/src/rules/pydocstyle/rules/triple_quotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ pub(crate) fn triple_quotes(checker: &mut Checker, docstring: &Docstring) {
let mut diagnostic =
Diagnostic::new(TripleSingleQuotes { expected_quote }, docstring.range());

let body = docstring.body().as_str();
if !body.ends_with('\'') {
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
format!("{prefixes}'''{body}'''"),
docstring.range(),
)));
if checker.settings.preview.is_enabled() {
let body = docstring.body().as_str();
if !body.ends_with('\'') {
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
format!("{prefixes}'''{body}'''"),
docstring.range(),
)));
}
}

checker.diagnostics.push(diagnostic);
Expand All @@ -94,12 +96,14 @@ pub(crate) fn triple_quotes(checker: &mut Checker, docstring: &Docstring) {
let mut diagnostic =
Diagnostic::new(TripleSingleQuotes { expected_quote }, docstring.range());

let body = docstring.body().as_str();
if !body.ends_with('"') {
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
format!("{prefixes}\"\"\"{body}\"\"\""),
docstring.range(),
)));
if checker.settings.preview.is_enabled() {
let body = docstring.body().as_str();
if !body.ends_with('"') {
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
format!("{prefixes}\"\"\"{body}\"\"\""),
docstring.range(),
)));
}
}

checker.diagnostics.push(diagnostic);
Expand Down

0 comments on commit c26ce2b

Please sign in to comment.