ruff/crates/ruff_python_ast/src
Dhruv Manilawala 96ae9fe685
Introduce `StringLike` enum (#9016)
## Summary

This PR introduces a new `StringLike` enum which is a narrow type to
indicate string-like nodes. These includes the string literals, bytes
literals, and the literal parts of f-strings.

The main motivation behind this is to avoid repetition of rule calling
in the AST checker. We add a new `analyze::string_like` function which
takes in the enum and calls all the respective rule functions which
expects atleast 2 of the variants of this enum.

I'm open to discarding this if others think it's not that useful at this
stage as currently only 3 rules require these nodes.

As suggested
[here](https://github.com/astral-sh/ruff/pull/8835#discussion_r1414746934)
and
[here](https://github.com/astral-sh/ruff/pull/8835#discussion_r1414750204).

## Test Plan

`cargo test`
2023-12-07 16:39:13 +00:00
..
visitor New AST nodes for f-string elements (#8835) 2023-12-07 10:28:05 -06:00
all.rs Rename `as_str` to `to_str` (#8886) 2023-11-28 18:50:42 -06:00
call_path.rs Store call paths rather than stringified names (#6102) 2023-08-05 15:21:50 +00:00
comparable.rs New AST nodes for f-string elements (#8835) 2023-12-07 10:28:05 -06:00
docstrings.rs Move Python whitespace utilities into new `ruff_python_whitespace` crate (#4993) 2023-06-10 00:59:57 +00:00
expression.rs Introduce `StringLike` enum (#9016) 2023-12-07 16:39:13 +00:00
hashable.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
helpers.rs New AST nodes for f-string elements (#8835) 2023-12-07 10:28:05 -06:00
identifier.rs Update to Rust 1.74 and use new clippy lints table (#8722) 2023-11-16 18:12:46 -05:00
imports.rs Include alias when formatting import-from structs (#5786) 2023-07-15 15:53:21 -04:00
int.rs Include radix base prefix in large number representation (#7700) 2023-09-28 20:38:06 +00:00
lib.rs Update `E402` to work at cell level for notebooks (#8872) 2023-11-29 00:32:35 +00:00
node.rs New AST nodes for f-string elements (#8835) 2023-12-07 10:28:05 -06:00
nodes.rs New AST nodes for f-string elements (#8835) 2023-12-07 10:28:05 -06:00
parenthesize.rs Comments outside expression parentheses (#7873) 2023-10-19 09:24:11 +00:00
relocate.rs New AST nodes for f-string elements (#8835) 2023-12-07 10:28:05 -06:00
statement_visitor.rs Remove `Stmt::TryStar` (#6566) 2023-08-14 13:39:44 -04:00
stmt_if.rs Move `Ranged` into `ruff_text_size` (#6919) 2023-08-27 14:12:51 -04:00
str.rs Replace dynamic implicit concatenation detection with parser flag (#6513) 2023-08-14 10:27:17 -04:00
traversal.rs [refurb] Implement `repeated-append` rule (`FURB113`) (#6702) 2023-08-28 22:51:59 +00:00
types.rs Remove `RefEquality` (#6393) 2023-08-07 16:04:50 +00:00
visitor.rs New AST nodes for f-string elements (#8835) 2023-12-07 10:28:05 -06:00
whitespace.rs Move `Ranged` into `ruff_text_size` (#6919) 2023-08-27 14:12:51 -04:00