Skip to content

Commit 3ef1c2e

Browse files
Add rome_formatter fork as ruff_formatter (astral-sh#2872)
The Ruff autoformatter is going to be based on an intermediate representation (IR) formatted via [Wadler's algorithm](https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf). This is architecturally similar to [Rome](https://github.com/rome/tools), Prettier, [Skip](https://github.com/skiplang/skip/blob/master/src/tools/printer/printer.sk), and others. This PR adds a fork of the `rome_formatter` crate from [Rome](https://github.com/rome/tools), renamed here to `ruff_formatter`, which provides generic definitions for a formatter IR as well as a generic IR printer. (We've also pulled in `rome_rowan`, `rome_text_size`, and `rome_text_edit`, though some of these will be removed in future PRs.) Why fork? `rome_formatter` contains code that's specific to Rome's AST representation (e.g., it relies on a fork of rust-analyzer's `rowan`), and we'll likely want to support different abstractions and formatting capabilities (there are already a few changes coming in future PRs). Once we've dropped `ruff_rowan` and trimmed down `ruff_formatter` to the code we currently need, it's also not a huge surface area to maintain and update.
1 parent ac028cd commit 3ef1c2e

83 files changed

Lines changed: 27547 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 135 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,3 +1062,109 @@ are:
10621062
"""
10631063

10641064
- flake8-django, licensed under the GPL license.
1065+
1066+
- rust-analyzer/rowan, licensed under the MIT license:
1067+
"""
1068+
Permission is hereby granted, free of charge, to any
1069+
person obtaining a copy of this software and associated
1070+
documentation files (the "Software"), to deal in the
1071+
Software without restriction, including without
1072+
limitation the rights to use, copy, modify, merge,
1073+
publish, distribute, sublicense, and/or sell copies of
1074+
the Software, and to permit persons to whom the Software
1075+
is furnished to do so, subject to the following
1076+
conditions:
1077+
1078+
The above copyright notice and this permission notice
1079+
shall be included in all copies or substantial portions
1080+
of the Software.
1081+
1082+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
1083+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
1084+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
1085+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
1086+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
1087+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1088+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
1089+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1090+
DEALINGS IN THE SOFTWARE.
1091+
"""
1092+
1093+
- rust-analyzer/text-size, licensed under the MIT license:
1094+
"""
1095+
Permission is hereby granted, free of charge, to any
1096+
person obtaining a copy of this software and associated
1097+
documentation files (the "Software"), to deal in the
1098+
Software without restriction, including without
1099+
limitation the rights to use, copy, modify, merge,
1100+
publish, distribute, sublicense, and/or sell copies of
1101+
the Software, and to permit persons to whom the Software
1102+
is furnished to do so, subject to the following
1103+
conditions:
1104+
1105+
The above copyright notice and this permission notice
1106+
shall be included in all copies or substantial portions
1107+
of the Software.
1108+
1109+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
1110+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
1111+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
1112+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
1113+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
1114+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1115+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
1116+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1117+
DEALINGS IN THE SOFTWARE.
1118+
"""
1119+
1120+
- rust-analyzer/text-edit, licensed under the MIT license:
1121+
"""
1122+
Permission is hereby granted, free of charge, to any
1123+
person obtaining a copy of this software and associated
1124+
documentation files (the "Software"), to deal in the
1125+
Software without restriction, including without
1126+
limitation the rights to use, copy, modify, merge,
1127+
publish, distribute, sublicense, and/or sell copies of
1128+
the Software, and to permit persons to whom the Software
1129+
is furnished to do so, subject to the following
1130+
conditions:
1131+
1132+
The above copyright notice and this permission notice
1133+
shall be included in all copies or substantial portions
1134+
of the Software.
1135+
1136+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
1137+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
1138+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
1139+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
1140+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
1141+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1142+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
1143+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1144+
DEALINGS IN THE SOFTWARE.
1145+
"""
1146+
1147+
- rome/tools, licensed under the MIT license:
1148+
"""
1149+
MIT License
1150+
1151+
Copyright (c) Rome Tools, Inc. and its affiliates.
1152+
1153+
Permission is hereby granted, free of charge, to any person obtaining a copy
1154+
of this software and associated documentation files (the "Software"), to deal
1155+
in the Software without restriction, including without limitation the rights
1156+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1157+
copies of the Software, and to permit persons to whom the Software is
1158+
furnished to do so, subject to the following conditions:
1159+
1160+
The above copyright notice and this permission notice shall be included in all
1161+
copies or substantial portions of the Software.
1162+
1163+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1164+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1165+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1166+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1167+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1168+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1169+
SOFTWARE.
1170+
"""

_typos.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
[files]
22
extend-exclude = ["snapshots"]
3+
4+
[default.extend-words]
5+
trivias = "trivias"
6+
hel = "hel"

crates/ruff_formatter/Cargo.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
name = "ruff_formatter"
3+
version = "0.0.0"
4+
publish = false
5+
edition = "2021"
6+
7+
[dependencies]
8+
cfg-if = { version = "1.0.0" }
9+
countme = { version = "3.0.1" }
10+
drop_bomb = { version = "0.1.5" }
11+
indexmap = { version = "1.9.1" }
12+
ruff_rowan = { path = "../ruff_rowan" }
13+
rustc-hash = { workspace = true }
14+
schemars = { version = "0.8.10", optional = true }
15+
serde = { version = "1.0.136", features = ["derive"], optional = true }
16+
tracing = { version = "0.1.31", default-features = false, features = ["std"] }
17+
unicode-width = { version = "0.1.9" }
18+
19+
[dev-dependencies]
20+
insta = { version = "1.19.0" }
21+
22+
[features]
23+
serde = ["dep:serde", "schemars", "ruff_rowan/serde"]

0 commit comments

Comments
 (0)