ruff/crates/ruff_linter/src
Charlie Marsh c3ca34543f
Skip LibCST parsing for standard dedent adjustments (#9769)
## Summary

Often, when fixing, we need to dedent a block of code (e.g., if we
remove an `if` and dedent its body). Today, we use LibCST to parse and
adjust the indentation, which is really expensive -- but this is only
really necessary if the block contains a multiline string, since naively
adjusting the indentation for such a string can change the whitespace
_within_ the string.

This PR uses a simple dedent implementation for cases in which the block
doesn't intersect with a multi-line string (or an f-string, since we
don't support tracking multi-line strings for f-strings right now).

We could improve this even further by using the ranges to guide the
dedent function, such that we don't apply the dedent if the line starts
within a multiline string. But that would also need to take f-strings
into account, which is a little tricky.

## Test Plan

`cargo test`
2024-02-02 18:13:46 +00:00
..
checkers Use AhoCorasick to speed up quote match (#9773) 2024-02-02 09:57:39 -05:00
comments Rename ruff crate to ruff_linter (#7529) 2023-09-20 08:38:27 +02:00
cst Update string nodes for implicit concatenation (#7927) 2023-11-24 17:55:41 -06:00
docstrings Disambiguate argument descriptors from section headers (#9427) 2024-01-07 22:41:00 -05:00
fix Skip LibCST parsing for standard dedent adjustments (#9769) 2024-02-02 18:13:46 +00: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 Skip LibCST parsing for standard dedent adjustments (#9769) 2024-02-02 18:13:46 +00:00
settings Replace --show-source and --no-show-source with --output_format=<full|concise> (#9687) 2024-02-01 13:35:02 -06:00
snapshots Detect automagic-like assignments in notebooks (#9653) 2024-01-29 12:55:44 +00:00
codes.rs Restore RUF011 documentation (#9758) 2024-02-01 13:35:02 -06:00
directives.rs Use comment_ranges for isort directive extraction (#9414) 2024-01-06 16:05:13 -05: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 Add tests for redirected rules (#9754) 2024-02-01 13:35:02 -06:00
logging.rs Deduplicate deprecation warnings for v0.2.0 release (#9764) 2024-02-01 17:10:24 -06:00
noqa.rs add instructions on line-level suppression to file-level suppression warning (#8052) 2023-10-18 18:46:59 -04: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 [pylint] Implement empty-comment (PLR2044) (#9174) 2023-12-29 02:53:56 +00:00
renamer.rs Add a BindingKind for WithItem variables (#8594) 2023-11-09 22:44:49 -05:00
rule_redirects.rs Bump version to 0.2.0 (#9762) 2024-02-01 17:10:33 -06:00
rule_selector.rs Restore RUF011 documentation (#9758) 2024-02-01 13:35:02 -06:00
source_kind.rs Use SourceKind::diff for formatter (#8240) 2023-10-26 11:08:13 +05:30
test.rs Avoid rendering display-only rules as fixable (#9649) 2024-01-26 09:47:01 -05:00
upstream_categories.rs Misc. small tweaks from perusing modules (#9383) 2024-01-03 12:30:25 -05:00