Skip to content

Commit

Permalink
Fixing formatting of long unsplittable words.
Browse files Browse the repository at this point in the history
Closes #5905
  • Loading branch information
orizi committed Jun 26, 2024
1 parent cdaceb9 commit 20b7901
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion crates/cairo-lang-formatter/src/formatter_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,9 @@ fn format_leading_comment(content: &str, cur_indent: usize, max_line_width: usiz
};
last_line_broken = false;
for word in orig_comment_line.content.split(' ') {
if current_line.content.len() + word.len() <= max_comment_width {
if current_line.content.is_empty()
|| current_line.content.len() + word.len() <= max_comment_width
{
current_line.content.push_str(word);
current_line.content.push(' ');
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,5 @@ fn function_for_a_comment() {
let x = 1;
}





// leading words long_single_word_that_should_not_be_broken_not_creating_addional_empty_lines_padding_padding_padding_padding

Check warning on line 47 in crates/cairo-lang-formatter/test_data/cairo_files/linebreaking.cairo

View workflow job for this annotation

GitHub Actions / typos

"addional" should be "additional".
fn function_for_a_comment() {}
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,6 @@ fn function_for_a_comment() {
let x = 1;
}

// leading words
// long_single_word_that_should_not_be_broken_not_creating_addional_empty_lines_padding_padding_padding_padding

Check warning on line 206 in crates/cairo-lang-formatter/test_data/expected_results/linebreaking.cairo

View workflow job for this annotation

GitHub Actions / typos

"addional" should be "additional".
fn function_for_a_comment() {}

0 comments on commit 20b7901

Please sign in to comment.