ruff/crates/ruff_linter/src
Robin Caloudis 2edd61709f
[flake8-quotes] Fix Autofix Error (Q000, Q002) (#10199)
## Summary
In issue https://github.com/astral-sh/ruff/issues/6785 it is reported
that a docstring in the form of `''"assert" ' SAM macro definitions '''`
is autocorrected to `"""assert" ' SAM macro definitions '''` (note the
triple quotes one only one side), which breaks the python program due
`undetermined string lateral`.

* `Q002`: Not only would docstrings in the form of `''"assert" ' SAM
macro definitions '''` (single quotes) be autofixed wrongly, but also
e.g. `""'assert' ' SAM macro definitions '''` (double quotes). The bug
is present for docstrings in all scopes (e.g. module docstrings, class
docstrings, function docstrings)

* `Q000`: The autofix error is not only present for `Q002` (docstrings),
but also for inline strings (`Q000`). Therefore `s = ''"assert" ' SAM
macro definitions '''` will also be wrongly autofixed.

Note that situation in which the first string is non-empty can be fixed,
e.g. `'123'"assert" ' SAM macro definitions '''` -> `"123""assert" ' SAM
macro definitions '''` is valid.

## What
* Change FixAvailability of `Q000` `Q002` to `Sometimes`
* Changed both rules such that docstrings/inline strings that cannot be
fixed are still reported as bad quotes via diagnostics, but no fix is
provided

## Test Plan
* For `Q000`: Add docstrings in different scopes that (partially) would
have been autofixed wrongly
* For `Q002`: Add inline strings that (partially) would have been
autofixed wrongly

Closes https://github.com/astral-sh/ruff/issues/6785
2024-03-18 01:31:25 +00:00
..
checkers [pylint] Implement nonlocal-and-global (E115) (#10407) 2024-03-18 00:43:02 +00:00
comments Rename ruff crate to ruff_linter (#7529) 2023-09-20 08:38:27 +02:00
cst Wrap expressions in parentheses when negating (#10346) 2024-03-11 18:20:55 -04:00
docstrings [pydocstyle-D405] Allow using parameters as a sub-section header (#9894) 2024-02-08 21:54:32 -05:00
fix [pyupgrade] Allow fixes for f-string rule regardless of line length (UP032) (#10263) 2024-03-07 08:59:29 -05:00
importer Remove source path from parser errors (#9322) 2023-12-30 20:33:05 +00:00
lex Rename ruff crate to ruff_linter (#7529) 2023-09-20 08:38:27 +02:00
message Feature: Add SARIF output support (#9078) 2023-12-13 00:33:19 -05:00
registry --show-settings displays active settings in a far more readable format (#9464) 2024-01-12 14:30:29 -05:00
rules [flake8-quotes] Fix Autofix Error (Q000, Q002) (#10199) 2024-03-18 01:31:25 +00:00
settings Remove F401 fix for __init__ imports by default and allow opt-in to unsafe fix (#10365) 2024-03-13 12:58:25 -05:00
snapshots Detect automagic-like assignments in notebooks (#9653) 2024-01-29 12:55:44 +00:00
codes.rs [pylint] Implement nonlocal-and-global (E115) (#10407) 2024-03-18 00:43:02 +00:00
directives.rs Track quoting style in the tokenizer (#10256) 2024-03-08 08:40:06 +00:00
doc_lines.rs Split Constant to individual literal nodes (#8064) 2023-10-30 12:13:23 +05:30
fs.rs Rename ruff crate to ruff_linter (#7529) 2023-09-20 08:38:27 +02:00
lib.rs Rename Autofix to Fix (#7657) 2023-09-28 10:53:05 +00:00
line_width.rs --show-settings displays active settings in a far more readable format (#9464) 2024-01-12 14:30:29 -05:00
linter.rs [pycodestyle] Implement redundant-backslash (E502) (#10292) 2024-03-11 21:15:06 -04:00
logging.rs Make --config and --isolated global flags (#10150) 2024-03-04 11:19:40 +00:00
noqa.rs Respect external codes in file-level exemptions (#10203) 2024-03-03 00:20:36 +00:00
packaging.rs Rename ruff crate to ruff_linter (#7529) 2023-09-20 08:38:27 +02:00
pyproject_toml.rs Update pyproject-toml to 0.8 (#8351) 2023-10-30 10:05:37 +00:00
registry.rs [pycodestyle] Implement blank-line-at-end-of-file (W391) (#10243) 2024-03-11 22:07:59 -04:00
renamer.rs Track conditional deletions in the semantic model (#10415) 2024-03-14 20:45:46 -04:00
rule_redirects.rs Bump version to 0.2.0 (#9762) 2024-02-01 17:10:33 -06:00
rule_selector.rs Fix clippy unused variable warning (#9902) 2024-02-08 22:13:31 +00:00
source_kind.rs CLI: Color entire line in Diffs (#10183) 2024-03-01 13:53:45 +01:00
test.rs Avoid rendering display-only rules as fixable (#9649) 2024-01-26 09:47:01 -05:00
upstream_categories.rs Fix pylint upstream categories not showing in docs (#10441) 2024-03-18 01:27:39 +00:00