From 7d13edfc52e2123f16dba3fb9d63434aa4f745f3 Mon Sep 17 00:00:00 2001 From: Zanie Date: Wed, 16 Aug 2023 13:17:20 -0500 Subject: [PATCH] Move `replacements` access to method --- .../src/rules/pylint/rules/bad_string_format_character.rs | 2 +- crates/ruff_python_literal/src/format.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/ruff/src/rules/pylint/rules/bad_string_format_character.rs b/crates/ruff/src/rules/pylint/rules/bad_string_format_character.rs index 24d69c79ad3f07..bbcdc5fad8b1a3 100644 --- a/crates/ruff/src/rules/pylint/rules/bad_string_format_character.rs +++ b/crates/ruff/src/rules/pylint/rules/bad_string_format_character.rs @@ -63,7 +63,7 @@ pub(crate) fn call(checker: &mut Checker, string: &str, range: TextRange) { } Err(_) => {} Ok(format_spec) => { - for replacement in format_spec.replacements { + for replacement in format_spec.replacements() { let FormatPart::Field { format_spec, .. } = replacement else { continue; }; diff --git a/crates/ruff_python_literal/src/format.rs b/crates/ruff_python_literal/src/format.rs index efdc914b6dc604..fa7039e0e14169 100644 --- a/crates/ruff_python_literal/src/format.rs +++ b/crates/ruff_python_literal/src/format.rs @@ -236,7 +236,7 @@ pub struct FormatSpec { // Ex) `f` in `'{:+f}'` format_type: Option, // Ex) `x` and `y` in `'{:*{x},{y}b}'` - pub replacements: Vec, + replacements: Vec, } fn get_num_digits(text: &str) -> usize { @@ -408,6 +408,10 @@ impl FormatSpec { }) } + pub fn replacements(&self) -> &[FormatPart] { + return self.replacements.as_slice(); + } + fn compute_fill_string(fill_char: char, fill_chars_needed: i32) -> String { (0..fill_chars_needed) .map(|_| fill_char)