diff --git a/rust/src/data/ruff-21.expected.toml b/rust/src/data/ruff-21.expected.toml new file mode 100644 index 0000000..ecd99c9 --- /dev/null +++ b/rust/src/data/ruff-21.expected.toml @@ -0,0 +1,14 @@ +[tool.ruff] +lint.select = [ + "ALL", +] +lint.ignore = [ + # We do not annotate the type of 'self'. + "ANN101", +] +# Do not automatically remove commented out code. +# We comment out code during development, and with VSCode auto-save, this code +# is sometimes annoyingly removed. +lint.unfixable = [ + "ERA001", +] diff --git a/rust/src/data/ruff-21.start.toml b/rust/src/data/ruff-21.start.toml new file mode 100644 index 0000000..c756765 --- /dev/null +++ b/rust/src/data/ruff-21.start.toml @@ -0,0 +1,12 @@ +[tool.ruff.lint] +select = ["ALL"] + +ignore = [ + # We do not annotate the type of 'self'. + "ANN101", +] + +# Do not automatically remove commented out code. +# We comment out code during development, and with VSCode auto-save, this code +# is sometimes annoyingly removed. +unfixable = ["ERA001"] diff --git a/rust/src/helpers/array.rs b/rust/src/helpers/array.rs index 1913d22..3b8e6ef 100644 --- a/rust/src/helpers/array.rs +++ b/rust/src/helpers/array.rs @@ -2,6 +2,7 @@ use std::cell::RefCell; use std::collections::HashMap; use lexical_sort::{natural_lexical_cmp, StringSort}; +use taplo::syntax::SyntaxKind::{ARRAY, COMMA, NEWLINE, STRING, VALUE, WHITESPACE}; use taplo::syntax::{SyntaxElement, SyntaxKind, SyntaxNode}; use crate::helpers::create::{make_comma, make_newline}; @@ -12,9 +13,9 @@ where F: Fn(&str) -> String, { for array in node.children_with_tokens() { - if array.kind() == SyntaxKind::ARRAY { + if array.kind() == ARRAY { for array_entry in array.as_node().unwrap().children_with_tokens() { - if array_entry.kind() == SyntaxKind::VALUE { + if array_entry.kind() == VALUE { update_content(array_entry.as_node().unwrap(), transform); } } @@ -27,7 +28,7 @@ where F: Fn(&str) -> String, { for array in node.children_with_tokens() { - if array.kind() == SyntaxKind::ARRAY { + if array.kind() == ARRAY { let array_node = array.as_node().unwrap(); let mut value_set = Vec::>::new(); let entry_set = RefCell::new(Vec::::new()); @@ -53,13 +54,13 @@ where if previous_is_value { // make sure ends with trailing comma previous_is_value = false; - if entry.kind() != SyntaxKind::COMMA { + if entry.kind() != COMMA { entry_set.borrow_mut().push(make_comma()); } } if previous_is_bracket_open { // make sure ends with trailing comma - if entry.kind() == SyntaxKind::NEWLINE || entry.kind() == SyntaxKind::WHITESPACE { + if entry.kind() == NEWLINE || entry.kind() == WHITESPACE { continue; } previous_is_bracket_open = false; @@ -78,7 +79,7 @@ where } entries.push(entry); } - SyntaxKind::VALUE => { + VALUE => { if has_value { entry_set.borrow_mut().push(make_newline()); add_to_value_set(entry_value.clone()); @@ -88,9 +89,8 @@ where let mut found_string = false; for child in value_node.children_with_tokens() { let kind = child.kind(); - if kind == SyntaxKind::STRING { - entry_value = - transform(load_text(child.as_token().unwrap().text(), SyntaxKind::STRING).as_str()); + if kind == STRING { + entry_value = transform(load_text(child.as_token().unwrap().text(), STRING).as_str()); found_string = true; break; } @@ -102,7 +102,7 @@ where entry_set.borrow_mut().push(entry); previous_is_value = true; } - SyntaxKind::NEWLINE => { + NEWLINE => { entry_set.borrow_mut().push(entry); if has_value { add_to_value_set(entry_value.clone()); @@ -133,7 +133,7 @@ mod tests { use rstest::rstest; use taplo::formatter::{format_syntax, Options}; use taplo::parser::parse; - use taplo::syntax::SyntaxKind; + use taplo::syntax::SyntaxKind::{ENTRY, VALUE}; use crate::helpers::array::{sort, transform}; use crate::helpers::pep508::format_requirement; @@ -193,9 +193,9 @@ mod tests { fn test_normalize_requirement(#[case] start: &str, #[case] expected: &str, #[case] keep_full_version: bool) { let root_ast = parse(start).into_syntax().clone_for_update(); for children in root_ast.children_with_tokens() { - if children.kind() == SyntaxKind::ENTRY { + if children.kind() == ENTRY { for entry in children.as_node().unwrap().children_with_tokens() { - if entry.kind() == SyntaxKind::VALUE { + if entry.kind() == VALUE { transform(entry.as_node().unwrap(), &|s| format_requirement(s, keep_full_version)); } } @@ -275,9 +275,9 @@ mod tests { fn test_order_array(#[case] start: &str, #[case] expected: &str) { let root_ast = parse(start).into_syntax().clone_for_update(); for children in root_ast.children_with_tokens() { - if children.kind() == SyntaxKind::ENTRY { + if children.kind() == ENTRY { for entry in children.as_node().unwrap().children_with_tokens() { - if entry.kind() == SyntaxKind::VALUE { + if entry.kind() == VALUE { sort(entry.as_node().unwrap(), str::to_lowercase); } } diff --git a/rust/src/helpers/create.rs b/rust/src/helpers/create.rs index 6cc282d..7edb24e 100644 --- a/rust/src/helpers/create.rs +++ b/rust/src/helpers/create.rs @@ -1,5 +1,6 @@ use taplo::parser::parse; -use taplo::syntax::{SyntaxElement, SyntaxKind}; +use taplo::syntax::SyntaxElement; +use taplo::syntax::SyntaxKind::{ARRAY, COMMA, ENTRY, KEY, NEWLINE, STRING, VALUE}; pub fn make_string_node(text: &str) -> SyntaxElement { let expr = &format!("a = \"{}\"", text.replace('"', "\\\"")); @@ -10,9 +11,9 @@ pub fn make_string_node(text: &str) -> SyntaxElement { .unwrap() .children_with_tokens() { - if root.kind() == SyntaxKind::VALUE { + if root.kind() == VALUE { for entries in root.as_node().unwrap().children_with_tokens() { - if entries.kind() == SyntaxKind::STRING { + if entries.kind() == STRING { return entries; } } @@ -23,7 +24,7 @@ pub fn make_string_node(text: &str) -> SyntaxElement { pub fn make_empty_newline() -> SyntaxElement { for root in parse("\n\n").into_syntax().clone_for_update().children_with_tokens() { - if root.kind() == SyntaxKind::NEWLINE { + if root.kind() == NEWLINE { return root; } } @@ -32,7 +33,7 @@ pub fn make_empty_newline() -> SyntaxElement { pub fn make_newline() -> SyntaxElement { for root in parse("\n").into_syntax().clone_for_update().children_with_tokens() { - if root.kind() == SyntaxKind::NEWLINE { + if root.kind() == NEWLINE { return root; } } @@ -41,13 +42,13 @@ pub fn make_newline() -> SyntaxElement { pub fn make_comma() -> SyntaxElement { for root in parse("a=[1,2]").into_syntax().clone_for_update().children_with_tokens() { - if root.kind() == SyntaxKind::ENTRY { + if root.kind() == ENTRY { for value in root.as_node().unwrap().children_with_tokens() { - if value.kind() == SyntaxKind::VALUE { + if value.kind() == VALUE { for array in value.as_node().unwrap().children_with_tokens() { - if array.kind() == SyntaxKind::ARRAY { + if array.kind() == ARRAY { for e in array.as_node().unwrap().children_with_tokens() { - if e.kind() == SyntaxKind::COMMA { + if e.kind() == COMMA { return e; } } @@ -66,9 +67,9 @@ pub fn make_key(text: &str) -> SyntaxElement { .clone_for_update() .children_with_tokens() { - if root.kind() == SyntaxKind::ENTRY { + if root.kind() == ENTRY { for value in root.as_node().unwrap().children_with_tokens() { - if value.kind() == SyntaxKind::KEY { + if value.kind() == KEY { return value; } } @@ -84,7 +85,7 @@ pub fn make_array(key: &str) -> SyntaxElement { .clone_for_update() .children_with_tokens() { - if root.kind() == SyntaxKind::ENTRY { + if root.kind() == ENTRY { return root; } } @@ -98,13 +99,13 @@ pub fn make_array_entry(key: &str) -> SyntaxElement { .clone_for_update() .children_with_tokens() { - if root.kind() == SyntaxKind::ENTRY { + if root.kind() == ENTRY { for value in root.as_node().unwrap().children_with_tokens() { - if value.kind() == SyntaxKind::VALUE { + if value.kind() == VALUE { for array in value.as_node().unwrap().children_with_tokens() { - if array.kind() == SyntaxKind::ARRAY { + if array.kind() == ARRAY { for e in array.as_node().unwrap().children_with_tokens() { - if e.kind() == SyntaxKind::VALUE { + if e.kind() == VALUE { return e; } } @@ -124,7 +125,7 @@ pub fn make_entry_of_string(key: &String, value: &String) -> SyntaxElement { .clone_for_update() .children_with_tokens() { - if root.kind() == SyntaxKind::ENTRY { + if root.kind() == ENTRY { return root; } } diff --git a/rust/src/helpers/string.rs b/rust/src/helpers/string.rs index bbe402e..3790bd2 100644 --- a/rust/src/helpers/string.rs +++ b/rust/src/helpers/string.rs @@ -1,12 +1,13 @@ +use taplo::syntax::SyntaxKind::{IDENT, MULTI_LINE_STRING, MULTI_LINE_STRING_LITERAL, STRING, STRING_LITERAL}; use taplo::syntax::{SyntaxElement, SyntaxKind, SyntaxNode}; use crate::helpers::create::make_string_node; pub fn load_text(value: &str, kind: SyntaxKind) -> String { let mut chars = value.chars(); - let offset = if [SyntaxKind::STRING, SyntaxKind::STRING_LITERAL].contains(&kind) { + let offset = if [STRING, STRING_LITERAL].contains(&kind) { 1 - } else if kind == SyntaxKind::IDENT { + } else if kind == IDENT { 0 } else { 3 @@ -18,7 +19,7 @@ pub fn load_text(value: &str, kind: SyntaxKind) -> String { chars.next_back(); } let mut res = chars.as_str().to_string(); - if kind == SyntaxKind::STRING { + if kind == STRING { res = res.replace("\\\"", "\""); } res @@ -33,18 +34,11 @@ where for mut child in entry.children_with_tokens() { count += 1; let kind = child.kind(); - if [ - SyntaxKind::STRING, - SyntaxKind::STRING_LITERAL, - SyntaxKind::MULTI_LINE_STRING, - SyntaxKind::MULTI_LINE_STRING_LITERAL, - ] - .contains(&kind) - { + if [STRING, STRING_LITERAL, MULTI_LINE_STRING, MULTI_LINE_STRING_LITERAL].contains(&kind) { let found_str_value = load_text(child.as_token().unwrap().text(), kind); let output = transform(found_str_value.as_str()); - changed = output != found_str_value || kind != SyntaxKind::STRING; + changed = output != found_str_value || kind != STRING; if changed { child = make_string_node(output.as_str()); } diff --git a/rust/src/helpers/table.rs b/rust/src/helpers/table.rs index a43a28e..d54c6e8 100644 --- a/rust/src/helpers/table.rs +++ b/rust/src/helpers/table.rs @@ -3,8 +3,8 @@ use std::collections::HashMap; use std::iter::zip; use std::ops::Index; -use taplo::syntax::SyntaxKind::{TABLE_ARRAY_HEADER, TABLE_HEADER}; -use taplo::syntax::{SyntaxElement, SyntaxKind, SyntaxNode}; +use taplo::syntax::SyntaxKind::{ENTRY, IDENT, KEY, NEWLINE, TABLE_ARRAY_HEADER, TABLE_HEADER, VALUE}; +use taplo::syntax::{SyntaxElement, SyntaxNode}; use taplo::HashSet; use crate::helpers::create::{make_empty_newline, make_key, make_newline, make_table_entry}; @@ -46,11 +46,17 @@ impl Tables { // join tables let pos = indexes.first().unwrap(); let mut res = table_set.index(*pos).borrow_mut(); - for element in entry_set_borrow.clone() { - if element.kind() != TABLE_HEADER { - res.push(element); - } + let mut new = entry_set_borrow.clone(); + if let Some(last_non_trailing_newline_index) = new.iter().rposition(|x| x.kind() != NEWLINE) { + new.truncate(last_non_trailing_newline_index + 1); + } + if res.last().unwrap().kind() != NEWLINE { + res.push(make_newline()); } + res.extend( + new.into_iter() + .skip_while(|x| [NEWLINE, TABLE_HEADER].contains(&x.kind())), + ); } entry_set_borrow.clear(); } @@ -84,12 +90,12 @@ impl Tables { if !got.is_empty() { entry_count += got.len(); let last = got.last().unwrap(); - if name.is_empty() && last.kind() == SyntaxKind::NEWLINE && got.len() == 1 { + if name.is_empty() && last.kind() == NEWLINE && got.len() == 1 { continue; } let mut add = got.clone(); if get_key(name) != get_key(next_name) { - if last.kind() == SyntaxKind::NEWLINE { + if last.kind() == NEWLINE { // replace existing newline to ensure single newline add.pop(); } @@ -102,7 +108,6 @@ impl Tables { root_ast.splice_children(0..entry_count, to_insert); } } - fn calculate_order( header_to_pos: &HashMap>, table_set: &[RefCell>], @@ -196,26 +201,38 @@ fn load_keys(table: &RefMut>) -> (HashMap, Vec } }; let mut key = String::new(); - for c in table.iter() { - if c.kind() == SyntaxKind::ENTRY { - add_to_key_set(key.clone()); - for e in c.as_node().unwrap().children_with_tokens() { - if e.kind() == SyntaxKind::KEY { + let mut cutoff = false; + for element in table.iter() { + let kind = element.kind(); + if kind == ENTRY { + if cutoff { + add_to_key_set(key.clone()); + cutoff = false; + } + for e in element.as_node().unwrap().children_with_tokens() { + if e.kind() == KEY { key = e.as_node().unwrap().text().to_string().trim().to_string(); break; } } } - entry_set.borrow_mut().push(c.clone()); + if [ENTRY, TABLE_HEADER, TABLE_ARRAY_HEADER].contains(&kind) { + cutoff = true; + } + entry_set.borrow_mut().push(element.clone()); + if cutoff && kind == NEWLINE { + add_to_key_set(key.clone()); + cutoff = false; + } } add_to_key_set(key); (key_to_pos, key_set) } pub fn get_table_name(entry: &SyntaxElement) -> String { - if [SyntaxKind::TABLE_HEADER, SyntaxKind::TABLE_ARRAY_HEADER].contains(&entry.kind()) { + if [TABLE_HEADER, TABLE_ARRAY_HEADER].contains(&entry.kind()) { for child in entry.as_node().unwrap().children_with_tokens() { - if child.kind() == SyntaxKind::KEY { + if child.kind() == KEY { return child.as_node().unwrap().text().to_string().trim().to_string(); } } @@ -229,11 +246,11 @@ where { let mut key = String::new(); for table_entry in table.iter() { - if table_entry.kind() == SyntaxKind::ENTRY { + if table_entry.kind() == ENTRY { for entry in table_entry.as_node().unwrap().children_with_tokens() { - if entry.kind() == SyntaxKind::KEY { + if entry.kind() == KEY { key = entry.as_node().unwrap().text().to_string().trim().to_string(); - } else if entry.kind() == SyntaxKind::VALUE { + } else if entry.kind() == VALUE { f(key.clone(), entry.as_node().unwrap()); } } @@ -269,21 +286,21 @@ pub fn collapse_sub_tables(tables: &mut Tables, name: &str) { let mut header = false; for child in sub.iter() { let kind = child.kind(); - if kind == SyntaxKind::TABLE_HEADER { + if kind == TABLE_HEADER { header = true; continue; } - if header && kind == SyntaxKind::NEWLINE { + if header && kind == NEWLINE { continue; } - if kind == SyntaxKind::ENTRY { + if kind == ENTRY { let mut to_insert = Vec::::new(); let child_node = child.as_node().unwrap(); for mut entry in child_node.children_with_tokens() { - if entry.kind() == SyntaxKind::KEY { + if entry.kind() == KEY { for array_entry_value in entry.as_node().unwrap().children_with_tokens() { - if array_entry_value.kind() == SyntaxKind::IDENT { - let txt = load_text(array_entry_value.as_token().unwrap().text(), SyntaxKind::IDENT); + if array_entry_value.kind() == IDENT { + let txt = load_text(array_entry_value.as_token().unwrap().text(), IDENT); entry = make_key(format!("{sub_name}.{txt}").as_str()); break; } @@ -293,7 +310,7 @@ pub fn collapse_sub_tables(tables: &mut Tables, name: &str) { } child_node.splice_children(0..to_insert.len(), to_insert); } - if main.last().unwrap().kind() != SyntaxKind::NEWLINE { + if main.last().unwrap().kind() != NEWLINE { main.push(make_newline()); } main.push(child.clone()); diff --git a/rust/src/project.rs b/rust/src/project.rs index 91ff10e..0adaead 100644 --- a/rust/src/project.rs +++ b/rust/src/project.rs @@ -1,7 +1,10 @@ use std::cell::RefMut; use regex::Regex; -use taplo::syntax::{SyntaxElement, SyntaxKind, SyntaxNode}; +use taplo::syntax::SyntaxKind::{ + ARRAY, BRACKET_END, BRACKET_START, COMMA, ENTRY, IDENT, INLINE_TABLE, KEY, NEWLINE, STRING, VALUE, +}; +use taplo::syntax::{SyntaxElement, SyntaxNode}; use taplo::util::StrExt; use taplo::HashSet; @@ -102,38 +105,33 @@ fn expand_entry_points_inline_tables(table: &mut RefMut>) { let (mut to_insert, mut count, mut key) = (Vec::::new(), 0, String::new()); for s_table_entry in table.iter() { count += 1; - if s_table_entry.kind() == SyntaxKind::ENTRY { + if s_table_entry.kind() == ENTRY { let mut has_inline_table = false; for s_in_table in s_table_entry.as_node().unwrap().children_with_tokens() { - if s_in_table.kind() == SyntaxKind::KEY { + if s_in_table.kind() == KEY { key = s_in_table.as_node().unwrap().text().to_string().trim().to_string(); - } else if key.starts_with("entry-points.") && s_in_table.kind() == SyntaxKind::VALUE { + } else if key.starts_with("entry-points.") && s_in_table.kind() == VALUE { for s_in_value in s_in_table.as_node().unwrap().children_with_tokens() { - if s_in_value.kind() == SyntaxKind::INLINE_TABLE { + if s_in_value.kind() == INLINE_TABLE { has_inline_table = true; for s_in_inline_table in s_in_value.as_node().unwrap().children_with_tokens() { - if s_in_inline_table.kind() == SyntaxKind::ENTRY { + if s_in_inline_table.kind() == ENTRY { let mut with_key = String::new(); for s_in_entry in s_in_inline_table.as_node().unwrap().children_with_tokens() { - if s_in_entry.kind() == SyntaxKind::KEY { + if s_in_entry.kind() == KEY { for s_in_key in s_in_entry.as_node().unwrap().children_with_tokens() { - if s_in_key.kind() == SyntaxKind::IDENT { - with_key = load_text( - s_in_key.as_token().unwrap().text(), - SyntaxKind::IDENT, - ); + if s_in_key.kind() == IDENT { + with_key = load_text(s_in_key.as_token().unwrap().text(), IDENT); with_key = String::from(with_key.strip_quotes()); break; } } - } else if s_in_entry.kind() == SyntaxKind::VALUE { + } else if s_in_entry.kind() == VALUE { for s_in_b_value in s_in_entry.as_node().unwrap().children_with_tokens() { - if s_in_b_value.kind() == SyntaxKind::STRING { - let value = load_text( - s_in_b_value.as_token().unwrap().text(), - SyntaxKind::STRING, - ); - if to_insert.last().unwrap().kind() != SyntaxKind::NEWLINE { + if s_in_b_value.kind() == STRING { + let value = + load_text(s_in_b_value.as_token().unwrap().text(), STRING); + if to_insert.last().unwrap().kind() != NEWLINE { to_insert.push(make_newline()); } let new_key = format!("{key}.{with_key}"); @@ -176,11 +174,11 @@ fn generate_classifiers( Some(c) => { let mut key_value = String::new(); for table_row in table.iter() { - if table_row.kind() == SyntaxKind::ENTRY { + if table_row.kind() == ENTRY { for entry in table_row.as_node().unwrap().children_with_tokens() { - if entry.kind() == SyntaxKind::KEY { + if entry.kind() == KEY { key_value = entry.as_node().unwrap().text().to_string().trim().to_string(); - } else if entry.kind() == SyntaxKind::VALUE && key_value == "classifiers" { + } else if entry.kind() == VALUE && key_value == "classifiers" { generate_classifiers_to_entry(table_row.as_node().unwrap(), min, max, &omit, &c); } } @@ -198,9 +196,9 @@ fn generate_classifiers_to_entry( existing: &HashSet, ) { for array in node.children_with_tokens() { - if array.kind() == SyntaxKind::VALUE { + if array.kind() == VALUE { for root_value in array.as_node().unwrap().children_with_tokens() { - if root_value.kind() == SyntaxKind::ARRAY { + if root_value.kind() == ARRAY { let mut must_have: HashSet = HashSet::new(); must_have.insert(String::from("Programming Language :: Python :: 3 :: Only")); must_have.extend( @@ -219,25 +217,24 @@ fn generate_classifiers_to_entry( for array_entry in root_value.as_node().unwrap().children_with_tokens() { count += 1; let kind = array_entry.kind(); - if delete_mode & [SyntaxKind::NEWLINE, SyntaxKind::BRACKET_END].contains(&kind) { + if delete_mode & [NEWLINE, BRACKET_END].contains(&kind) { delete_mode = false; - if kind == SyntaxKind::NEWLINE { + if kind == NEWLINE { continue; } - } else if kind == SyntaxKind::VALUE { + } else if kind == VALUE { for array_entry_value in array_entry.as_node().unwrap().children_with_tokens() { - if array_entry_value.kind() == SyntaxKind::STRING { - let txt = - load_text(array_entry_value.as_token().unwrap().text(), SyntaxKind::STRING); + if array_entry_value.kind() == STRING { + let txt = load_text(array_entry_value.as_token().unwrap().text(), STRING); delete_mode = delete.contains(&txt); if delete_mode { // delete from previous comma/start until next newline let mut remove_count = to_insert.len(); for (at, v) in to_insert.iter().rev().enumerate() { - if [SyntaxKind::COMMA, SyntaxKind::BRACKET_START].contains(&v.kind()) { + if [COMMA, BRACKET_START].contains(&v.kind()) { remove_count = at; for (i, e) in to_insert.iter().enumerate().skip(to_insert.len() - at) { - if e.kind() == SyntaxKind::NEWLINE { + if e.kind() == NEWLINE { remove_count = i + 1; break; } @@ -261,17 +258,17 @@ fn generate_classifiers_to_entry( let mut trail_at = 0; for (at, v) in to_insert.iter().rev().enumerate() { trail_at = to_insert.len() - at; - if v.kind() == SyntaxKind::COMMA { + if v.kind() == COMMA { for (i, e) in to_insert.iter().enumerate().skip(trail_at) { - if e.kind() == SyntaxKind::NEWLINE || e.kind() == SyntaxKind::BRACKET_END { + if e.kind() == NEWLINE || e.kind() == BRACKET_END { trail_at = i; break; } } break; - } else if v.kind() == SyntaxKind::BRACKET_START { + } else if v.kind() == BRACKET_START { break; - } else if v.kind() == SyntaxKind::VALUE { + } else if v.kind() == VALUE { to_insert.insert(trail_at, make_comma()); trail_at += 1; break; @@ -308,8 +305,8 @@ fn get_python_requires_with_classifier( for_entries(table, &mut |key, entry| { if key == "requires-python" { for child in entry.children_with_tokens() { - if child.kind() == SyntaxKind::STRING { - let found_str_value = load_text(child.as_token().unwrap().text(), SyntaxKind::STRING); + if child.kind() == STRING { + let found_str_value = load_text(child.as_token().unwrap().text(), STRING); let re = Regex::new(r"^(?<|<=|==|!=|>=|>)3[.](?\d+)").unwrap(); for part in found_str_value.split(',') { let capture = re.captures(part); @@ -344,12 +341,12 @@ fn get_python_requires_with_classifier( } } else if key == "classifiers" { for child in entry.children_with_tokens() { - if child.kind() == SyntaxKind::ARRAY { + if child.kind() == ARRAY { let mut found_elements = HashSet::::new(); for array in child.as_node().unwrap().children_with_tokens() { - if array.kind() == SyntaxKind::VALUE { + if array.kind() == VALUE { for value in array.as_node().unwrap().children_with_tokens() { - if value.kind() == SyntaxKind::STRING { + if value.kind() == STRING { let found = value.as_token().unwrap().text(); let found_str_value: String = String::from(&found[1..found.len() - 1]); found_elements.insert(found_str_value); diff --git a/rust/src/ruff.rs b/rust/src/ruff.rs index 29f5005..7ea4b11 100644 --- a/rust/src/ruff.rs +++ b/rust/src/ruff.rs @@ -142,6 +142,7 @@ pub fn fix(tables: &mut Tables) { "format", "lint.select", "lint.extend-select", + "lint.ignore", "lint.explicit-preview-rules", "lint.exclude", "lint.extend-ignore", @@ -232,4 +233,12 @@ mod tests { let expected = read_to_string(data.join("ruff-order.expected.toml")).unwrap(); assert_eq!(got, expected); } + + #[rstest] + fn test_ruff_comment_21(data: PathBuf) { + let start = read_to_string(data.join("ruff-21.start.toml")).unwrap(); + let got = evaluate(start.as_str()); + let expected = read_to_string(data.join("ruff-21.expected.toml")).unwrap(); + assert_eq!(got, expected); + } }