ruff/crates
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
..
ruff Bump version to 0.3.3 (#10425) 2024-03-15 12:51:49 -05:00
ruff_benchmark Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_cache Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_dev Fix pylint upstream categories not showing in docs (#10441) 2024-03-18 01:27:39 +00:00
ruff_diagnostics Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_formatter Spellcheck & grammar (#10375) 2024-03-13 02:34:23 +00:00
ruff_index Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_linter [`flake8-quotes`] Fix Autofix Error (`Q000, Q002`) (#10199) 2024-03-18 01:31:25 +00:00
ruff_macros Spellcheck & grammar (#10375) 2024-03-13 02:34:23 +00:00
ruff_notebook Spellcheck & grammar (#10375) 2024-03-13 02:34:23 +00:00
ruff_python_ast Use `ExprFString` for `StringLike::FString` variant (#10311) 2024-03-14 13:30:22 +05:30
ruff_python_codegen Unify enums used for internal representation of quoting style (#10383) 2024-03-13 17:19:17 +00:00
ruff_python_formatter Unify enums used for internal representation of quoting style (#10383) 2024-03-13 17:19:17 +00:00
ruff_python_index Fix Indexer fails to identify continuation preceded by newline #10351 (#10354) 2024-03-12 00:35:41 -04:00
ruff_python_literal Unify enums used for internal representation of quoting style (#10383) 2024-03-13 17:19:17 +00:00
ruff_python_parser Unify enums used for internal representation of quoting style (#10383) 2024-03-13 17:19:17 +00:00
ruff_python_resolver Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_python_semantic Track conditional deletions in the semantic model (#10415) 2024-03-14 20:45:46 -04:00
ruff_python_stdlib [`pylint`] Include builtin warnings in useless-exception-statement (`PLW0133`) (#10394) 2024-03-13 15:26:11 -04:00
ruff_python_trivia Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
ruff_server Spellcheck & grammar (#10375) 2024-03-13 02:34:23 +00:00
ruff_shrinking Bump version to 0.3.3 (#10425) 2024-03-15 12:51:49 -05:00
ruff_source_file `ruff server` - A new built-in LSP for Ruff, written in Rust (#10158) 2024-03-08 20:57:23 -08:00
ruff_text_size Range formatting: Fix invalid syntax after parenthesizing expression (#9751) 2024-02-02 17:56:25 +01:00
ruff_wasm Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_workspace Remove `F401` fix for `__init__` imports by default and allow opt-in to unsafe fix (#10365) 2024-03-13 12:58:25 -05:00