Change "indexes" to "indices" in various contexts (#3856)

This commit is contained in:
Charlie Marsh 2023-04-02 19:08:03 -04:00 committed by GitHub
parent 08e5b3fa61
commit 924bebbb4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 41 deletions

View file

@ -23,7 +23,7 @@ pub(crate) fn error_to_string(err: &FormatParseError) -> String {
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct FormatSummary { pub(crate) struct FormatSummary {
pub autos: Vec<usize>, pub autos: Vec<usize>,
pub indexes: Vec<usize>, pub indices: Vec<usize>,
pub keywords: Vec<String>, pub keywords: Vec<String>,
pub has_nested_parts: bool, pub has_nested_parts: bool,
pub format_string: FormatString, pub format_string: FormatString,
@ -36,7 +36,7 @@ impl TryFrom<&str> for FormatSummary {
let format_string = FormatString::from_str(literal)?; let format_string = FormatString::from_str(literal)?;
let mut autos = Vec::new(); let mut autos = Vec::new();
let mut indexes = Vec::new(); let mut indices = Vec::new();
let mut keywords = Vec::new(); let mut keywords = Vec::new();
let mut has_nested_parts = false; let mut has_nested_parts = false;
@ -51,7 +51,7 @@ impl TryFrom<&str> for FormatSummary {
let parsed = FieldName::parse(field_name)?; let parsed = FieldName::parse(field_name)?;
match parsed.field_type { match parsed.field_type {
FieldType::Auto => autos.push(autos.len()), FieldType::Auto => autos.push(autos.len()),
FieldType::Index(i) => indexes.push(i), FieldType::Index(i) => indices.push(i),
FieldType::Keyword(k) => keywords.push(k), FieldType::Keyword(k) => keywords.push(k),
}; };
@ -63,7 +63,7 @@ impl TryFrom<&str> for FormatSummary {
let parsed = FieldName::parse(&field_name)?; let parsed = FieldName::parse(&field_name)?;
match parsed.field_type { match parsed.field_type {
FieldType::Auto => autos.push(autos.len()), FieldType::Auto => autos.push(autos.len()),
FieldType::Index(i) => indexes.push(i), FieldType::Index(i) => indices.push(i),
FieldType::Keyword(k) => keywords.push(k), FieldType::Keyword(k) => keywords.push(k),
}; };
has_nested_parts = true; has_nested_parts = true;
@ -72,7 +72,7 @@ impl TryFrom<&str> for FormatSummary {
Ok(FormatSummary { Ok(FormatSummary {
autos, autos,
indexes, indices,
keywords, keywords,
has_nested_parts, has_nested_parts,
format_string, format_string,
@ -89,7 +89,7 @@ mod tests {
let literal = "foo{foo}a{}b{2}c{2}d{1}{}{}e{bar}{foo}f{spam}"; let literal = "foo{foo}a{}b{2}c{2}d{1}{}{}e{bar}{foo}f{spam}";
let expected_autos = [0usize, 1usize, 2usize].to_vec(); let expected_autos = [0usize, 1usize, 2usize].to_vec();
let expected_indexes = [2usize, 2usize, 1usize].to_vec(); let expected_indices = [2usize, 2usize, 1usize].to_vec();
let expected_keywords: Vec<_> = ["foo", "bar", "foo", "spam"] let expected_keywords: Vec<_> = ["foo", "bar", "foo", "spam"]
.into_iter() .into_iter()
.map(String::from) .map(String::from)
@ -98,7 +98,7 @@ mod tests {
let format_summary = FormatSummary::try_from(literal).unwrap(); let format_summary = FormatSummary::try_from(literal).unwrap();
assert_eq!(format_summary.autos, expected_autos); assert_eq!(format_summary.autos, expected_autos);
assert_eq!(format_summary.indexes, expected_indexes); assert_eq!(format_summary.indices, expected_indices);
assert_eq!(format_summary.keywords, expected_keywords); assert_eq!(format_summary.keywords, expected_keywords);
assert!(!format_summary.has_nested_parts); assert!(!format_summary.has_nested_parts);
} }
@ -108,7 +108,7 @@ mod tests {
let literal = "foo{foo}a{:{}{}}b{2:{3}{4}}c{2}d{1}{}e{bar:{spam}{eggs}}"; let literal = "foo{foo}a{:{}{}}b{2:{3}{4}}c{2}d{1}{}e{bar:{spam}{eggs}}";
let expected_autos = [0usize, 1usize, 2usize, 3usize].to_vec(); let expected_autos = [0usize, 1usize, 2usize, 3usize].to_vec();
let expected_indexes = [2usize, 3usize, 4usize, 2usize, 1usize].to_vec(); let expected_indices = [2usize, 3usize, 4usize, 2usize, 1usize].to_vec();
let expected_keywords: Vec<_> = ["foo", "bar", "spam", "eggs"] let expected_keywords: Vec<_> = ["foo", "bar", "spam", "eggs"]
.into_iter() .into_iter()
.map(String::from) .map(String::from)
@ -117,7 +117,7 @@ mod tests {
let format_summary = FormatSummary::try_from(literal).unwrap(); let format_summary = FormatSummary::try_from(literal).unwrap();
assert_eq!(format_summary.autos, expected_autos); assert_eq!(format_summary.autos, expected_autos);
assert_eq!(format_summary.indexes, expected_indexes); assert_eq!(format_summary.indices, expected_indices);
assert_eq!(format_summary.keywords, expected_keywords); assert_eq!(format_summary.keywords, expected_keywords);
assert!(format_summary.has_nested_parts); assert!(format_summary.has_nested_parts);
} }

View file

@ -498,7 +498,7 @@ pub(crate) fn string_dot_format_extra_positional_arguments(
} }
let missing: Vec<usize> = (0..args.len()) let missing: Vec<usize> = (0..args.len())
.filter(|i| !(summary.autos.contains(i) || summary.indexes.contains(i))) .filter(|i| !(summary.autos.contains(i) || summary.indices.contains(i)))
.collect(); .collect();
if missing.is_empty() { if missing.is_empty() {
@ -551,7 +551,7 @@ pub(crate) fn string_dot_format_missing_argument(
let missing: Vec<String> = summary let missing: Vec<String> = summary
.autos .autos
.iter() .iter()
.chain(summary.indexes.iter()) .chain(summary.indices.iter())
.filter(|&&i| i >= args.len()) .filter(|&&i| i >= args.len())
.map(ToString::to_string) .map(ToString::to_string)
.chain( .chain(
@ -577,7 +577,7 @@ pub(crate) fn string_dot_format_mixing_automatic(
summary: &FormatSummary, summary: &FormatSummary,
location: Range, location: Range,
) { ) {
if !(summary.autos.is_empty() || summary.indexes.is_empty()) { if !(summary.autos.is_empty() || summary.indices.is_empty()) {
checker checker
.diagnostics .diagnostics
.push(Diagnostic::new(StringDotFormatMixingAutomatic, location)); .push(Diagnostic::new(StringDotFormatMixingAutomatic, location));

View file

@ -24,7 +24,7 @@ impl AlwaysAutofixableViolation for FormatLiterals {
} }
fn autofix_title(&self) -> String { fn autofix_title(&self) -> String {
"Remove explicit positional indexes".to_string() "Remove explicit positional indices".to_string()
} }
} }
@ -135,7 +135,7 @@ pub(crate) fn format_literals(checker: &mut Checker, summary: &FormatSummary, ex
if !summary.autos.is_empty() { if !summary.autos.is_empty() {
return; return;
} }
if !(0..summary.indexes.len()).all(|index| summary.indexes.contains(&index)) { if !(0..summary.indices.len()).all(|index| summary.indices.contains(&index)) {
return; return;
} }
@ -144,7 +144,7 @@ pub(crate) fn format_literals(checker: &mut Checker, summary: &FormatSummary, ex
// Currently, the only issue we know of is in LibCST: // Currently, the only issue we know of is in LibCST:
// https://github.com/Instagram/LibCST/issues/846 // https://github.com/Instagram/LibCST/issues/846
if let Ok(contents) = if let Ok(contents) =
generate_call(expr, &summary.indexes, checker.locator, checker.stylist) generate_call(expr, &summary.indices, checker.locator, checker.stylist)
{ {
diagnostic.set_fix(Edit::replacement( diagnostic.set_fix(Edit::replacement(
contents, contents,

View file

@ -5,7 +5,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 3 row: 3
@ -26,7 +26,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 5 row: 5
@ -47,7 +47,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 9 row: 9
@ -68,7 +68,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 11 row: 11
@ -89,7 +89,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 13 row: 13
@ -110,7 +110,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 15 row: 15
@ -131,7 +131,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 17 row: 17
@ -152,7 +152,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 20 row: 20
@ -173,7 +173,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 22 row: 22
@ -194,7 +194,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 24 row: 24
@ -208,7 +208,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 29 row: 29
@ -222,7 +222,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 34 row: 34

View file

@ -5,7 +5,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 6 row: 6
@ -26,7 +26,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 8 row: 8
@ -47,7 +47,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 10 row: 10
@ -68,7 +68,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 12 row: 12
@ -89,7 +89,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 14 row: 14
@ -103,7 +103,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 16 row: 16
@ -124,7 +124,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 18 row: 18
@ -145,7 +145,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 20 row: 20
@ -166,7 +166,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 22 row: 22
@ -187,7 +187,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 24 row: 24
@ -208,7 +208,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 26 row: 26
@ -229,7 +229,7 @@ expression: diagnostics
- kind: - kind:
name: FormatLiterals name: FormatLiterals
body: Use implicit references for positional format fields body: Use implicit references for positional format fields
suggestion: Remove explicit positional indexes suggestion: Remove explicit positional indices
fixable: true fixable: true
location: location:
row: 28 row: 28

View file

@ -23,14 +23,14 @@ use crate::visibility::{module_visibility, Modifier, VisibleScope};
pub struct Context<'a> { pub struct Context<'a> {
pub typing_modules: &'a [String], pub typing_modules: &'a [String],
pub module_path: Option<Vec<String>>, pub module_path: Option<Vec<String>>,
// Retain all scopes and parent nodes, along with a stack of indexes to track which are active // Retain all scopes and parent nodes, along with a stack of indices to track which are active
// at various points in time. // at various points in time.
pub parents: Vec<RefEquality<'a, Stmt>>, pub parents: Vec<RefEquality<'a, Stmt>>,
pub depths: FxHashMap<RefEquality<'a, Stmt>, usize>, pub depths: FxHashMap<RefEquality<'a, Stmt>, usize>,
pub child_to_parent: FxHashMap<RefEquality<'a, Stmt>, RefEquality<'a, Stmt>>, pub child_to_parent: FxHashMap<RefEquality<'a, Stmt>, RefEquality<'a, Stmt>>,
// A stack of all bindings created in any scope, at any point in execution. // A stack of all bindings created in any scope, at any point in execution.
pub bindings: Bindings<'a>, pub bindings: Bindings<'a>,
// Map from binding index to indexes of bindings that redefine it in other scopes. // Map from binding index to indices of bindings that redefine it in other scopes.
pub redefinitions: pub redefinitions:
std::collections::HashMap<BindingId, Vec<BindingId>, BuildNoHashHasher<BindingId>>, std::collections::HashMap<BindingId, Vec<BindingId>, BuildNoHashHasher<BindingId>>,
pub exprs: Vec<RefEquality<'a, Expr>>, pub exprs: Vec<RefEquality<'a, Expr>>,