Skip to content
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

feat(format): respect max line width #242

Merged
merged 47 commits into from
Jan 15, 2025
Merged
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e27f90c
[WIP] match current tests while using a buffer
a-frantz Oct 20, 2024
f74d717
[WIP]
a-frantz Oct 22, 2024
164261a
Update builder.rs
a-frantz Oct 22, 2024
0f691d7
feat: config max line length
a-frantz Oct 22, 2024
c364a45
Update max_line_length.rs
a-frantz Oct 22, 2024
2852d28
revise: indentation config
a-frantz Oct 22, 2024
165603a
Update post.rs
a-frantz Oct 23, 2024
f1f4dec
Merge branch 'main' into feat/line-width
a-frantz Oct 30, 2024
f2d6448
Merge branch 'main' into feat/line-width
a-frantz Oct 31, 2024
ccc1104
WIP
a-frantz Oct 31, 2024
e1898e5
Merge branch 'main' into feat/line-width
a-frantz Jan 2, 2025
af36d91
WIP
a-frantz Jan 2, 2025
ce3a454
revise: use constants for min and max max line len
a-frantz Jan 2, 2025
3278597
revise: use a constant for max space indent
a-frantz Jan 2, 2025
95d649c
revise: hardcode tabs and spaces in fewer places
a-frantz Jan 2, 2025
163237e
chore: code clean up
a-frantz Jan 6, 2025
283ae6a
WIP
a-frantz Jan 6, 2025
df6f7a2
WIP
a-frantz Jan 6, 2025
a238b95
WIP
a-frantz Jan 6, 2025
a574f09
chore: consistency
a-frantz Jan 13, 2025
bc9f288
Merge branch 'main' into feat/line-width
a-frantz Jan 13, 2025
caa29c8
chore: code cleanup
a-frantz Jan 13, 2025
7509e66
revise: new PostToken (TempIndent)
a-frantz Jan 13, 2025
3dc09c6
fix: handle edge case where stream is empty
a-frantz Jan 13, 2025
7c0e191
WIP
a-frantz Jan 13, 2025
259ea59
perf: use Rc for temp_indent
a-frantz Jan 13, 2025
a34c9e0
WIP
a-frantz Jan 13, 2025
7199199
chore: fmt
a-frantz Jan 13, 2025
2e77ba3
WIP
a-frantz Jan 14, 2025
8f51518
WIP
a-frantz Jan 14, 2025
6126627
chore: code clean up
a-frantz Jan 14, 2025
28643d2
fix: special handling for no line breaks
a-frantz Jan 14, 2025
f195a78
fix: reset indent level
a-frantz Jan 14, 2025
6bf613f
fix: simplify `IfExpr` formatting
a-frantz Jan 14, 2025
9fb4691
feat: can_be_line_broken is exhaustive
a-frantz Jan 15, 2025
51473d5
Merge branch 'main' into feat/line-width
a-frantz Jan 15, 2025
6049417
chore: code cleanup
a-frantz Jan 15, 2025
d2c683e
Merge branch 'feat/line-width' of https://github.com/stjude-rust-labs…
a-frantz Jan 15, 2025
d16da2a
Update CHANGELOG.md
a-frantz Jan 15, 2025
b4d1020
fix: rework Config Builder
a-frantz Jan 15, 2025
f55d392
Update builder.rs
a-frantz Jan 15, 2025
52a9984
chore: review feedback
a-frantz Jan 15, 2025
5a42020
Update wdl-format/src/token.rs
a-frantz Jan 15, 2025
c0e446d
revise: more specific name for line spacing policy
a-frantz Jan 15, 2025
b3a2631
chore: review feedback
a-frantz Jan 15, 2025
c62b9c1
chore: review feedback
a-frantz Jan 15, 2025
1c2b6c7
chore: review feedback
a-frantz Jan 15, 2025
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
Prev Previous commit
Next Next commit
Update builder.rs
  • Loading branch information
a-frantz committed Oct 22, 2024
commit 164261a2f4aaec26b77677f6126a1afe0fcc2706
25 changes: 21 additions & 4 deletions wdl-format/src/config/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ pub struct Builder {

impl Builder {
/// Creates a new builder with default values.
pub fn new() -> Self {
Default::default()
pub fn new(
indent: Option<Indent>,
max_line_length: Option<usize>,
) -> Self {
Self {
indent,
max_line_length,
}
}

/// Sets the indentation level.
Expand All @@ -54,10 +60,21 @@ impl Builder {
self
}

/// Sets the maximum line length.
///
/// # Notes
///
/// This silently overwrites any previously provided value for the maximum
/// line length.
pub fn max_line_length(mut self, max_line_length: usize) -> Self {
self.max_line_length = Some(max_line_length);
self
}

/// Consumes `self` and attempts to build a [`Config`].
pub fn try_build(self) -> Result<Config> {
let indent = self.indent.ok_or(Error::Missing("indent"))?;
let max_line_length = self.max_line_length.unwrap_or(DEFAULT_MAX_LINE_LENGTH);
let max_line_length = self.max_line_length.ok_or(Error::Missing("max_line_length"))?;

Ok(Config {
indent,
Expand All @@ -70,7 +87,7 @@ impl Default for Builder {
fn default() -> Self {
Self {
indent: Some(Default::default()),
max_line_length: Some(90),
max_line_length: Some(DEFAULT_MAX_LINE_LENGTH),
}
}
}