Move W605 to the AST checker (#11402)

## Summary

This PR moves the `W605` rule to the AST checker.

This is part of #11401

## Test Plan

`cargo test`
This commit is contained in:
Dhruv Manilawala 2024-05-13 21:43:06 +05:30 committed by GitHub
parent 4b41e4de7f
commit ca99e9e2f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 98 additions and 56 deletions

View file

@ -2,8 +2,7 @@ use std::iter::FusedIterator;
use ruff_text_size::{Ranged, TextRange};
use crate::AnyNodeRef;
use crate::{self as ast, Expr};
use crate::{self as ast, AnyNodeRef, AnyStringFlags, Expr};
/// Unowned pendant to [`ast::Expr`] that stores a reference instead of a owned value.
#[derive(Copy, Clone, Debug, PartialEq)]
@ -452,6 +451,17 @@ pub enum StringLikePart<'a> {
FString(&'a ast::FString),
}
impl StringLikePart<'_> {
/// Returns the [`AnyStringFlags`] for the current string-like part.
pub fn flags(&self) -> AnyStringFlags {
match self {
StringLikePart::String(string) => AnyStringFlags::from(string.flags),
StringLikePart::Bytes(bytes) => AnyStringFlags::from(bytes.flags),
StringLikePart::FString(f_string) => AnyStringFlags::from(f_string.flags),
}
}
}
impl<'a> From<&'a ast::StringLiteral> for StringLikePart<'a> {
fn from(value: &'a ast::StringLiteral) -> Self {
StringLikePart::String(value)