-
-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting keys
with reorder_keys = true
does not sort when the last key has a trailing comment
#464
Labels
Comments
Thanks for the bug report! I was able to reproduce, but I don't have time to debug and fix. Feel free to open a PR with a fix. |
clarkf
added a commit
to clarkf/taplo
that referenced
this issue
Jan 2, 2024
Fixes tamasfe#464 When using taplo rules to limit configuration to specific portions of a document, trailing comments would break formatting. `Node#text_ranges`, when considering tables, was returning ranges for each interior element and the table header, which excluded trailing comments. When the formatter walks the code and is trying to determine which rules apply to a table, it checks whether the table is a subset of the rule "span". When there is a trailing comment, this check fails, and the rule will never apply. Since the dom `Node` for tables contains only a reference to the table header, we can get the text range of the entire table, including trailing or interior comments, by traversing up to the parent and taking its text range. If this is unavailable, the previous behavior is used. Note that this modifies the behavior of `crate::dom::Node::text_ranges`, which is part of the public API. Signed-off-by: Clark Fischer <clark.fischer@gmail.com>
clarkf
added a commit
to clarkf/taplo
that referenced
this issue
Jan 2, 2024
Fixes tamasfe#464 When using taplo rules to limit configuration to specific portions of a document, trailing comments would break formatting. `Node#text_ranges`, when considering tables, was returning ranges for each interior element and the table header, which excluded trailing comments. When the formatter walks the code and is trying to determine which rules apply to a table, it checks whether the table is a subset of the rule "span". When there is a trailing comment, this check fails, and the rule will never apply. Since the dom `Node` for tables contains only a reference to the table header, we can get the text range of the entire table, including trailing or interior comments, by traversing up to the parent and taking its text range. If this is unavailable, the previous behavior is used. Note that this modifies the behavior of `crate::dom::Node::text_ranges`, which is part of the public API. Signed-off-by: Clark Fischer <clark.fischer@gmail.com>
clarkf
added a commit
to clarkf/taplo
that referenced
this issue
Jan 3, 2024
Fixes tamasfe#464 When using taplo rules to limit configuration to specific portions of a document, trailing comments would break formatting. `Node#text_ranges`, when considering tables, was returning ranges for each interior element and the table header, which excluded trailing comments. When the formatter walks the code and is trying to determine which rules apply to a table, it checks whether the table is a subset of the rule "span". When there is a trailing comment, this check fails, and the rule will never apply. Since the dom `Node` for tables contains only a reference to the table header, we can get the text range of the entire table, including trailing or interior comments, by traversing up to the parent and taking its text range. If this is unavailable, the previous behavior is used. Note that this modifies the behavior of `crate::dom::Node::text_ranges`, which is part of the public API. Signed-off-by: Clark Fischer <clark.fischer@gmail.com>
clarkf
added a commit
to clarkf/taplo
that referenced
this issue
Jan 3, 2024
Fixes tamasfe#464 When using taplo rules to limit configuration to specific portions of a document, trailing comments would break formatting. `Node#text_ranges`, when considering tables, was returning ranges excluding trailing comments. When the formatter walks the code and is trying to determine which rules apply to a table, it checks whether the table is a subset of the rule "span". When there is a trailing comment, this check fails, and the rule will never apply. Since the dom `Node` for tables contains only a reference to the table header, we can get the text range of the entire table, including trailing or interior comments, by traversing up to the parent and taking its text range. If this is unavailable, the previous behavior is used. Note that this modifies the behavior of `crate::dom::Node::text_ranges`, which is part of the public API. Signed-off-by: Clark Fischer <clark.fischer@gmail.com>
clarkf
added a commit
to clarkf/taplo
that referenced
this issue
Jan 3, 2024
Fixes tamasfe#464 When using taplo rules to limit configuration to specific portions of a document, trailing comments would break formatting. `Node#text_ranges`, when considering tables, was returning ranges excluding trailing comments. When the formatter walks the code and is trying to determine which rules apply to a table, it checks whether the table is a subset of the rule "span". When there is a trailing comment, this check fails, and the rule will never apply. Since the dom `Node` for tables contains only a reference to the table header, we can get the text range of the entire table, including trailing or interior comments, by traversing up to the parent and taking its text range. If this is unavailable, the previous behavior is used. Note that this modifies the behavior of `crate::dom::Node::text_ranges`, which is part of the public API. Signed-off-by: Clark Fischer <clark.fischer@gmail.com>
panekj
added a commit
that referenced
this issue
Jul 27, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using
260bcf5b219e
:taplo.toml
:file.toml
:Run:
cargo run --bin taplo format file.toml
mytable
won't sort unless the trailing comment on the last key is removed. Or if you removekeys
, it works with trailing comment.The text was updated successfully, but these errors were encountered: