From ab4b600ec35fd93b70e2639a6946257232009a6d Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Sat, 9 Mar 2024 17:29:13 +0530 Subject: [PATCH] Rename variants to remove `Literal` prefix --- .../rules/hardcoded_bind_all_interfaces.rs | 6 +++--- .../rules/hardcoded_tmp_directory.rs | 6 +++--- .../rules/string_or_bytes_too_long.rs | 6 +++--- .../ruff/rules/ambiguous_unicode_character.rs | 6 +++--- crates/ruff_python_ast/src/expression.rs | 18 +++++++++--------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs index 7e65372ab72e7..aea1850771de0 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs @@ -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) => { @@ -69,6 +69,6 @@ pub(crate) fn hardcoded_bind_all_interfaces(checker: &mut Checker, string: Strin } } } - StringLike::BytesLiteral(_) => (), + StringLike::Bytes(_) => (), }; } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs index 69b19fdb3578f..4304e1482907c 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_tmp_directory.rs @@ -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) => { @@ -71,7 +71,7 @@ pub(crate) fn hardcoded_tmp_directory(checker: &mut Checker, string: StringLike) } } } - StringLike::BytesLiteral(_) => (), + StringLike::Bytes(_) => (), } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs index b4f4be3402b6d..a51886046dbc3 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs @@ -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; diff --git a/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs b/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs index 88112233a28bc..85f73f3db9610 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs @@ -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( @@ -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) => { @@ -233,7 +233,7 @@ pub(crate) fn ambiguous_unicode_character_string(checker: &mut Checker, string_l } } } - StringLike::BytesLiteral(_) => (), + StringLike::Bytes(_) => (), } } diff --git a/crates/ruff_python_ast/src/expression.rs b/crates/ruff_python_ast/src/expression.rs index 9dc40b53a30aa..1ef7247f5a373 100644 --- a/crates/ruff_python_ast/src/expression.rs +++ b/crates/ruff_python_ast/src/expression.rs @@ -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(), } } }