Skip to content

Commit

Permalink
Rename variants to remove Literal prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Mar 9, 2024
1 parent 2ba6168 commit ab4b600
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ impl Violation for HardcodedBindAllInterfaces {
/// S104
pub(crate) fn hardcoded_bind_all_interfaces(checker: &mut Checker, string: StringLike) {
match string {
StringLike::StringLiteral(ast::ExprStringLiteral { value, .. }) => {
StringLike::String(ast::ExprStringLiteral { value, .. }) => {
if value == "0.0.0.0" {
checker
.diagnostics
.push(Diagnostic::new(HardcodedBindAllInterfaces, string.range()));
}
}
StringLike::FStringLiteral(ast::ExprFString { value, .. }) => {
StringLike::FString(ast::ExprFString { value, .. }) => {
for part in value {
match part {
ast::FStringPart::Literal(literal) => {
Expand All @@ -69,6 +69,6 @@ pub(crate) fn hardcoded_bind_all_interfaces(checker: &mut Checker, string: Strin
}
}
}
StringLike::BytesLiteral(_) => (),
StringLike::Bytes(_) => (),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ impl Violation for HardcodedTempFile {
/// S108
pub(crate) fn hardcoded_tmp_directory(checker: &mut Checker, string: StringLike) {
match string {
StringLike::StringLiteral(ast::ExprStringLiteral { value, .. }) => {
StringLike::String(ast::ExprStringLiteral { value, .. }) => {
check(checker, value.to_str(), string.range());
}
StringLike::FStringLiteral(ast::ExprFString { value, .. }) => {
StringLike::FString(ast::ExprFString { value, .. }) => {
for part in value {
match part {
ast::FStringPart::Literal(literal) => {
Expand All @@ -71,7 +71,7 @@ pub(crate) fn hardcoded_tmp_directory(checker: &mut Checker, string: StringLike)
}
}
}
StringLike::BytesLiteral(_) => (),
StringLike::Bytes(_) => (),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ pub(crate) fn string_or_bytes_too_long(checker: &mut Checker, string: StringLike
}

let length = match string {
StringLike::StringLiteral(ast::ExprStringLiteral { value, .. }) => value.chars().count(),
StringLike::BytesLiteral(ast::ExprBytesLiteral { value, .. }) => value.len(),
StringLike::FStringLiteral(node) => count_f_string_chars(node),
StringLike::String(ast::ExprStringLiteral { value, .. }) => value.chars().count(),
StringLike::Bytes(ast::ExprBytesLiteral { value, .. }) => value.len(),
StringLike::FString(node) => count_f_string_chars(node),
};
if length <= 50 {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub(crate) fn ambiguous_unicode_character_string(checker: &mut Checker, string_l
};

match string_like {
StringLike::StringLiteral(node) => {
StringLike::String(node) => {
for literal in &node.value {
let text = checker.locator().slice(literal);
ambiguous_unicode_character(
Expand All @@ -205,7 +205,7 @@ pub(crate) fn ambiguous_unicode_character_string(checker: &mut Checker, string_l
);
}
}
StringLike::FStringLiteral(node) => {
StringLike::FString(node) => {
for part in &node.value {
match part {
ast::FStringPart::Literal(literal) => {
Expand Down Expand Up @@ -233,7 +233,7 @@ pub(crate) fn ambiguous_unicode_character_string(checker: &mut Checker, string_l
}
}
}
StringLike::BytesLiteral(_) => (),
StringLike::Bytes(_) => (),
}
}

Expand Down
18 changes: 9 additions & 9 deletions crates/ruff_python_ast/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,35 +399,35 @@ impl LiteralExpressionRef<'_> {
/// f-strings.
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum StringLike<'a> {
StringLiteral(&'a ast::ExprStringLiteral),
BytesLiteral(&'a ast::ExprBytesLiteral),
FStringLiteral(&'a ast::ExprFString),
String(&'a ast::ExprStringLiteral),
Bytes(&'a ast::ExprBytesLiteral),
FString(&'a ast::ExprFString),
}

impl<'a> From<&'a ast::ExprStringLiteral> for StringLike<'a> {
fn from(value: &'a ast::ExprStringLiteral) -> Self {
StringLike::StringLiteral(value)
StringLike::String(value)
}
}

impl<'a> From<&'a ast::ExprBytesLiteral> for StringLike<'a> {
fn from(value: &'a ast::ExprBytesLiteral) -> Self {
StringLike::BytesLiteral(value)
StringLike::Bytes(value)
}
}

impl<'a> From<&'a ast::ExprFString> for StringLike<'a> {
fn from(value: &'a ast::ExprFString) -> Self {
StringLike::FStringLiteral(value)
StringLike::FString(value)
}
}

impl Ranged for StringLike<'_> {
fn range(&self) -> TextRange {
match self {
StringLike::StringLiteral(literal) => literal.range(),
StringLike::BytesLiteral(literal) => literal.range(),
StringLike::FStringLiteral(literal) => literal.range(),
StringLike::String(literal) => literal.range(),
StringLike::Bytes(literal) => literal.range(),
StringLike::FString(literal) => literal.range(),
}
}
}

0 comments on commit ab4b600

Please sign in to comment.