oxc/crates/oxc_prettier/src/lib.rs
Boshen 65be4acdd4
feat(prettier): init project and infrastructure (#1260)
> [!NOTE]  
> This is going to be a community project because I don't have the time
and energy to work on this alone.

# Prettier

Background: 22.5K USD bounty for prettier written in Rust?!

See https://console.algora.io/challenges/prettier

> [!WARNING]  
> ## Contribution Agreement
> 
> You hereby agree that you contribute for fun and for the purpose of
learning, not for the goal of winning the challenge.
> 
> In the unlikely event of winning the challenge, @boshen will
ultimately decide on how to spend the money.
>

> [!IMPORTANT]  
Please talk to me on [discord](https://discord.com/invite/9uXCAwqQZW)
and indicate that you are willing to contribute and agree to the
contribution agreement.

## Getting started

Create a `test.js` and run the example `just example prettier` from
`crates/oxc_prettier/examples/prettier.rs`, follow the code structure
and read the references documented at the top of the files.

# Tasks

- [x] Have the basic infrastructure ready for contribution
- [ ] Implement a test runner in Rust which extracts the snapshots and
do a comparison over it
- [ ] Establish a way to pass all the tests by manually porting code
- [ ] Pass as many tests as possible in
https://github.com/prettier/prettier/tree/main/tests/format/js
2023-11-13 14:34:20 +08:00

32 lines
644 B
Rust

//! Prettier
//!
//! A port of <https://github.com/prettier/prettier>
mod document;
mod format;
mod macros;
mod printer;
use oxc_allocator::Allocator;
use oxc_ast::ast::Program;
use crate::{format::Format, printer::Printer};
pub struct PrettierOptions;
pub struct Prettier<'a> {
allocator: &'a Allocator,
_options: PrettierOptions,
}
impl<'a> Prettier<'a> {
pub fn new(allocator: &'a Allocator, _options: PrettierOptions) -> Self {
Self { allocator, _options }
}
pub fn build(mut self, program: &Program<'a>) -> String {
let doc = program.format(&mut self);
Printer::new(doc).build()
}
}