diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 072a570..4cfb366 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.28.3 + rev: 0.28.4 hooks: - id: check-github-workflows args: [ "--verbose" ] @@ -20,7 +20,7 @@ repos: - id: tox-ini-fmt args: [ "-p", "fix" ] - repo: https://github.com/tox-dev/pyproject-fmt - rev: "2.1.1" + rev: "2.1.2" hooks: - id: pyproject-fmt - repo: https://github.com/astral-sh/ruff-pre-commit diff --git a/Cargo.lock b/Cargo.lock index 3b53491..d725cfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -520,7 +520,7 @@ dependencies = [ [[package]] name = "pyproject-fmt-rust" -version = "1.1.1" +version = "1.1.3" dependencies = [ "indoc", "lexical-sort", diff --git a/Cargo.toml b/Cargo.toml index 9145285..d3f5233 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyproject-fmt-rust" -version = "1.1.2" +version = "1.1.3" description = "Format pyproject.toml files" repository = "https://github.com/tox-dev/pyproject-fmt" readme = "README.md" diff --git a/pyproject.toml b/pyproject.toml index 85d1837..92065cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,11 +64,20 @@ target-version = "py38" line-length = 120 format.preview = true format.docstring-code-line-length = 100 - format.docstring-code-format = true lint.select = [ "ALL", ] +lint.ignore = [ + "ANN101", # no type annotation for self + "ANN401", # allow Any as type annotation + "COM812", # Conflict with formatter + "CPY", # No copyright statements + "D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible + "D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible + "ISC001", # Conflict with formatter + "S104", # Possible binding to all interface +] lint.per-file-ignores."tests/**/*.py" = [ "D", # don"t care about documentation in tests "FBT", # don"t care about booleans as positional arguments in tests @@ -85,16 +94,6 @@ lint.isort = { known-first-party = [ ], required-imports = [ "from __future__ import annotations", ] } -lint.ignore = [ - "ANN101", # no type annotation for self - "ANN401", # allow Any as type annotation - "COM812", # Conflict with formatter - "CPY", # No copyright statements - "D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible - "D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible - "ISC001", # Conflict with formatter - "S104", # Possible binding to all interface -] lint.preview = true [tool.codespell] diff --git a/rust/src/helpers/table.rs b/rust/src/helpers/table.rs index d54c6e8..edfc830 100644 --- a/rust/src/helpers/table.rs +++ b/rust/src/helpers/table.rs @@ -77,7 +77,6 @@ impl Tables { pub fn reorder(&mut self, root_ast: &SyntaxNode, order: &[&str]) { let mut to_insert = Vec::::new(); - let mut entry_count: usize = 0; let order = calculate_order(&self.header_to_pos, &self.table_set, order); let mut next = order.clone(); if !next.is_empty() { @@ -88,7 +87,6 @@ impl Tables { for entries in self.get(name).unwrap() { let got = entries.borrow_mut(); if !got.is_empty() { - entry_count += got.len(); let last = got.last().unwrap(); if name.is_empty() && last.kind() == NEWLINE && got.len() == 1 { continue; @@ -105,7 +103,7 @@ impl Tables { } } } - root_ast.splice_children(0..entry_count, to_insert); + root_ast.splice_children(0..root_ast.children_with_tokens().count(), to_insert); } } fn calculate_order( diff --git a/rust/src/main.rs b/rust/src/main.rs index c3e3ed7..1920e95 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -100,8 +100,11 @@ pub fn _lib(m: &Bound<'_, PyModule>) -> PyResult<()> { #[cfg(test)] mod tests { + use std::fs::read_to_string; + use std::path::{Path, PathBuf}; + use indoc::indoc; - use rstest::rstest; + use rstest::{fixture, rstest}; use crate::{format_toml, Settings}; @@ -288,4 +291,29 @@ mod tests { let second = format_toml(got.as_str(), &settings); assert_eq!(second, got); } + + #[fixture] + fn data() -> PathBuf { + Path::new(env!("CARGO_MANIFEST_DIR")) + .join("rust") + .join("src") + .join("data") + } + + #[rstest] + fn test_issue_24(data: PathBuf) { + let start = read_to_string(data.join("ruff-order.start.toml")).unwrap(); + let settings = Settings { + column_width: 1, + indent: 2, + keep_full_version: false, + max_supported_python: (3, 8), + min_supported_python: (3, 8), + }; + let got = format_toml(start.as_str(), &settings); + let expected = read_to_string(data.join("ruff-order.expected.toml")).unwrap(); + assert_eq!(got, expected); + let second = format_toml(got.as_str(), &settings); + assert_eq!(second, got); + } }