Skip to content
This repository was archived by the owner on Oct 17, 2024. It is now read-only.
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
21 changes: 10 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
4 changes: 1 addition & 3 deletions rust/src/helpers/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ impl Tables {

pub fn reorder(&mut self, root_ast: &SyntaxNode, order: &[&str]) {
let mut to_insert = Vec::<SyntaxElement>::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() {
Expand All @@ -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;
Expand All @@ -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(
Expand Down
30 changes: 29 additions & 1 deletion rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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);
}
}