Skip to content

Commit cc6152c

Browse files
committed
Initial commit: oxc-toml formatter library
A focused TOML v1.0.0 formatter library - formatter-only fork of Taplo. This fork extracts just the formatter from the original Taplo project: - Removed: CLI, LSP, WASM, DOM, JavaScript packages, editor integrations - Kept: Parser, Formatter, Syntax tree, Utilities - Single crate structure (no workspace) - ~70% codebase reduction (36,000+ lines removed) Original work by Ferenc Tamás (https://github.com/tamasfe/taplo) Fork maintained by oxc-project (https://github.com/oxc-project)
0 parents  commit cc6152c

103 files changed

Lines changed: 4368 additions & 0 deletions

File tree

Some content is hidden

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

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/

‎Cargo.lock‎

Lines changed: 198 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "oxc-toml"
3+
description = "A TOML formatter library"
4+
version = "0.14.1"
5+
categories = ["parser-implementations", "parsing"]
6+
keywords = ["toml", "formatter"]
7+
readme = "README.md"
8+
authors = ["Boshen"]
9+
edition = "2024"
10+
license = "MIT"
11+
homepage = "https://github.com/oxc-project/oxc-toml"
12+
repository = "https://github.com/oxc-project/oxc-toml"
13+
14+
[dependencies]
15+
rustc-hash = "2.1.0"
16+
itertools = "0.14.0"
17+
logos = "0.16.0"
18+
rowan = "0.16.1"

‎LICENSE‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Boshen (oxc-toml - Formatter-only fork)
4+
Copyright (c) 2020 Ferenc Tamás (Original Taplo project)
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

‎README.md‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# oxc-toml
2+
3+
A TOML v1.0.0 formatter library.
4+
5+
This library provides TOML formatting capabilities while preserving comments, whitespace, and the original document structure where appropriate.
6+
7+
## Features
8+
9+
- Format TOML documents according to configurable style options
10+
- Preserve comments and meaningful whitespace
11+
- Handle syntax errors gracefully
12+
- Fault-tolerant parsing using [Rowan](https://github.com/rust-analyzer/rowan) syntax trees
13+
14+
## Usage
15+
16+
```rust
17+
use oxc_toml::formatter::{format, Options};
18+
19+
const SOURCE: &str = "value=1\n[table]\nstring='some string'";
20+
21+
let formatted = format(SOURCE, Options::default());
22+
```
23+
24+
## Attribution
25+
26+
This project is a formatter-only fork of the excellent [Taplo](https://github.com/tamasfe/taplo) project, originally created by [Ferenc Tamás](https://github.com/tamasfe).
27+
28+
### What Changed
29+
30+
This fork strips away all non-formatter components from Taplo, including:
31+
- CLI tool
32+
- Language Server Protocol (LSP) implementation
33+
- WebAssembly bindings
34+
- DOM (Document Object Model) for TOML manipulation
35+
- JavaScript/TypeScript packages
36+
- Editor integrations
37+
38+
The result is a focused, lightweight library that does one thing well: format TOML documents.
39+
40+
### Original Taplo Project
41+
42+
Taplo is a comprehensive TOML toolkit that provides:
43+
- TOML v1.0.0 parser
44+
- Formatter (the foundation of this fork)
45+
- Language server for IDE integration
46+
- CLI tool for formatting and validation
47+
- WebAssembly bindings for browser/Node.js
48+
- Schema validation
49+
50+
If you need these features, please use the original [Taplo project](https://github.com/tamasfe/taplo).
51+
52+
### License
53+
54+
This project maintains the original MIT License from Taplo. See [LICENSE](LICENSE) for details.

‎rust-toolchain.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "1.92.0"
3+
profile = "default"

‎src/formatter/macros.rs‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
macro_rules! create_options {
2+
(
3+
$(#[$attr:meta])*
4+
pub struct Options {
5+
$(
6+
$(#[$field_attr:meta])*
7+
pub $name:ident: $ty:ty,
8+
)+
9+
}
10+
) => {
11+
$(#[$attr])*
12+
pub struct Options {
13+
$(
14+
$(#[$field_attr])*
15+
pub $name: $ty,
16+
)+
17+
}
18+
19+
impl Options {
20+
pub fn update(&mut self, incomplete: OptionsIncomplete) {
21+
$(
22+
if let Some(v) = incomplete.$name {
23+
self.$name = v;
24+
}
25+
)+
26+
}
27+
28+
pub fn update_from_str<S: AsRef<str>, I: Iterator<Item = (S, S)>>(
29+
&mut self,
30+
values: I,
31+
) -> Result<(), OptionParseError> {
32+
for (key, val) in values {
33+
34+
$(
35+
if key.as_ref() == stringify!($name) {
36+
self.$name =
37+
val.as_ref()
38+
.parse()
39+
.map_err(|error| OptionParseError::InvalidValue {
40+
key: key.as_ref().into(),
41+
error: Box::new(error),
42+
})?;
43+
44+
continue;
45+
}
46+
)+
47+
48+
return Err(OptionParseError::InvalidOption(key.as_ref().into()));
49+
}
50+
51+
Ok(())
52+
}
53+
}
54+
55+
$(#[$attr])*
56+
#[derive(Default)]
57+
pub struct OptionsIncomplete {
58+
$(
59+
$(#[$field_attr])*
60+
pub $name: Option<$ty>,
61+
)+
62+
}
63+
64+
impl OptionsIncomplete {
65+
pub fn from_options(opts: Options) -> Self {
66+
let mut o = Self::default();
67+
68+
$(
69+
o.$name = Some(opts.$name);
70+
)+
71+
72+
o
73+
}
74+
}
75+
};
76+
}

0 commit comments

Comments
 (0)