Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

chore: bump rust version and fix lints #47

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 116 additions & 109 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ all = "warn"
pedantic = "warn"
nursery = "warn"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin_include)'] }

[dev-dependencies]
rstest = { version = "0.19.0" } # parametrized tests
indoc = { version = "2.0.5" } # dedented test cases for literal strings
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.77"
channel = "1.81"
6 changes: 3 additions & 3 deletions rust/src/build_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::helpers::array::{sort, transform};
use crate::helpers::pep508::{format_requirement, get_canonic_requirement_name};
use crate::helpers::table::{for_entries, reorder_table_keys, Tables};

pub fn fix(tables: &mut Tables, keep_full_version: bool) {
pub fn fix(tables: &Tables, keep_full_version: bool) {
let table_element = tables.get("build-system");
if table_element.is_none() {
return;
Expand Down Expand Up @@ -35,8 +35,8 @@ mod tests {
fn evaluate(start: &str, keep_full_version: bool) -> String {
let root_ast = parse(start).into_syntax().clone_for_update();
let count = root_ast.children_with_tokens().count();
let mut tables = Tables::from_ast(&root_ast);
fix(&mut tables, keep_full_version);
let tables = Tables::from_ast(&root_ast);
fix(&tables, keep_full_version);
let entries = tables
.table_set
.iter()
Expand Down
6 changes: 3 additions & 3 deletions rust/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use taplo::syntax::Lang;

use crate::helpers::table::Tables;

pub fn reorder_tables(root_ast: &SyntaxNode<Lang>, tables: &mut Tables) {
pub fn reorder_tables(root_ast: &SyntaxNode<Lang>, tables: &Tables) {
tables.reorder(
root_ast,
&[
Expand Down Expand Up @@ -161,8 +161,8 @@ mod tests {
)]
fn test_reorder_table(#[case] start: &str, #[case] expected: &str) {
let root_ast = parse(start).into_syntax().clone_for_update();
let mut tables = Tables::from_ast(&root_ast);
reorder_tables(&root_ast, &mut tables);
let tables = Tables::from_ast(&root_ast);
reorder_tables(&root_ast, &tables);
let opt = Options {
column_width: 1,
..Options::default()
Expand Down
3 changes: 1 addition & 2 deletions rust/src/helpers/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ where
== Some(COMMA);
let multiline = array_node
.children_with_tokens()
.find(|e| e.kind() == NEWLINE)
.is_some();
.any(|e| e.kind() == NEWLINE);
let mut value_set = Vec::<Vec<SyntaxElement>>::new();
let entry_set = RefCell::new(Vec::<SyntaxElement>::new());
let mut key_to_pos = HashMap::<String, usize>::new();
Expand Down
4 changes: 2 additions & 2 deletions rust/src/helpers/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Tables {
}

impl Tables {
pub(crate) fn get(&mut self, key: &str) -> Option<Vec<&RefCell<Vec<SyntaxElement>>>> {
pub(crate) fn get(&self, key: &str) -> Option<Vec<&RefCell<Vec<SyntaxElement>>>> {
if self.header_to_pos.contains_key(key) {
let mut res = Vec::<&RefCell<Vec<SyntaxElement>>>::new();
for pos in &self.header_to_pos[key] {
Expand Down Expand Up @@ -75,7 +75,7 @@ impl Tables {
}
}

pub fn reorder(&mut self, root_ast: &SyntaxNode, order: &[&str]) {
pub fn reorder(&self, root_ast: &SyntaxNode, order: &[&str]) {
let mut to_insert = Vec::<SyntaxElement>::new();
let order = calculate_order(&self.header_to_pos, &self.table_set, order);
let mut next = order.clone();
Expand Down
4 changes: 2 additions & 2 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ pub fn format_toml(content: &str, opt: &Settings) -> String {
let root_ast = parse(content).into_syntax().clone_for_update();
let mut tables = Tables::from_ast(&root_ast);

build_system::fix(&mut tables, opt.keep_full_version);
build_system::fix(&tables, opt.keep_full_version);
project::fix(
&mut tables,
opt.keep_full_version,
opt.max_supported_python,
opt.min_supported_python,
);
ruff::fix(&mut tables);
reorder_tables(&root_ast, &mut tables);
reorder_tables(&root_ast, &tables);

let options = Options {
align_entries: false, // do not align by =
Expand Down
Loading