ruff/crates
Jane Lewis 20217e9bbd
Fix panic on RUF027 (#9990)
## Summary

Fixes #9895 

The cause for this panic came from an offset error in the code. When
analyzing a hypothetical f-string, we attempt to re-parse it as an
f-string, and use the AST data to determine, among other things, whether
the format specifiers are correct. To determine the 'correctness' of a
format specifier, we actually have to re-parse the format specifier, and
this is where the issue lies. To get the source text for the specifier,
we were taking a slice from the original file source text... even though
the AST data for the specifier belongs to the standalone parsed f-string
expression, meaning that the ranges are going to be way off. In a file
with Unicode, this can cause panics if the slice is inside a char
boundary.

To fix this, we now slice from the temporary source we created earlier
to parse the literal as an f-string.

## Test Plan

The RUF027 snapshot test was amended to include a string with format
specifiers which we _should_ be calling out. This is to ensure we do
slice format specifiers from the source text correctly.
2024-02-16 20:04:39 +00:00
..
ruff Use atomic write when persisting cache (#9981) 2024-02-14 15:09:21 +01: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 Allow arbitrary configuration options to be overridden via the CLI (#9599) 2024-02-09 21:56:37 +00:00
ruff_diagnostics Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_formatter Use Rust 1.76 (#9897) 2024-02-08 18:20:08 +00:00
ruff_index Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_linter Fix panic on RUF027 (#9990) 2024-02-16 20:04:39 +00:00
ruff_macros Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_notebook Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_python_ast [perflint] Catch a wider range of mutations in PERF101 (#9955) 2024-02-12 12:17:55 -05:00
ruff_python_codegen Use non-parenthesized range for DebugText (#9953) 2024-02-12 23:00:02 +05:30
ruff_python_formatter Preview minimal f-string formatting (#9642) 2024-02-16 20:28:11 +05:30
ruff_python_index Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_python_literal Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_python_parser Use non-parenthesized range for DebugText (#9953) 2024-02-12 23:00:02 +05:30
ruff_python_resolver Run doctests as part of CI pipeline (#9939) 2024-02-12 10:18:58 +01:00
ruff_python_semantic Respect tuple assignments in typing analyzer (#9969) 2024-02-13 05:02:52 +00:00
ruff_python_stdlib Slight speed-up for lowercase and uppercase identifier checks (#9798) 2024-02-03 14:40:41 +00:00
ruff_python_trivia Add fast-path for comment detection (#9808) 2024-02-05 11:00:18 -05:00
ruff_shrinking Bump version to v0.2.1 (#9843) 2024-02-05 15:31:05 -05:00
ruff_source_file Fix blank-line docstring rules for module-level docstrings (#9878) 2024-02-07 16:48:28 -05: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 Stabilize quote-style preserve (#9922) 2024-02-12 09:30:07 +00:00