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/html): add multiline for multi attributes #4972

Closed
wants to merge 19 commits into from

Conversation

Geun-Oh
Copy link

@Geun-Oh Geun-Oh commented Jan 26, 2025

Summary

Close: #4828

Add break if elem has multi attributes (at multiline side).

Test Plan

Modified test case for element with single attribute.

@github-actions github-actions bot added A-Formatter Area: formatter L-HTML Language: HTML labels Jan 26, 2025
@Geun-Oh Geun-Oh changed the title feat(format/html): Add multiline for multi attributes feat(format/html): add multiline for multi attributes Jan 26, 2025
<div foo="bar" id="foo"></div>
<div foo="bar"></div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change intentional? Is there a reason?

Copy link
Author

@Geun-Oh Geun-Oh Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for single attribute element.

Or should I add new test case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add new tags/lines to test the different cases

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

Since the file is for 'no-break' cases, i'd suggesting adding <div foo="bar" id="foo"></div to break.html and
<div foo="bar"></div> to 'no-break.html`.

Copy link

codspeed-hq bot commented Jan 26, 2025

CodSpeed Performance Report

Merging #4972 will improve performances by 8.23%

Comparing Geun-Oh:multiline-in-multiattr (3f34c1d) with main (0bb86c7)

Summary

⚡ 1 improvements
✅ 94 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
react.production.min_3378072959512366797.js[cached] 2 ms 1.8 ms +8.23%

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test case has the setting set to auto. add new tests in a new folder with an options.json to set the attibute multiline setting to multiline. See #4968 for an example of how to do this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've added code lines to override options from options.json.

And also add tests & snapshots in new dir multiline.

crates/biome_html_formatter/tests/spec_tests.rs Outdated Show resolved Hide resolved
Comment on lines 43 to 69
let options_path = Path::new(test_directory).join("options.json");
if options_path.exists() {
let mut options_path = BiomePath::new(&options_path);

let mut settings = Settings::default();
let (test_options, diagnostics) = deserialize_from_str::<PartialConfiguration>(
options_path.get_buffer_from_file().as_str(),
)
.consume();

settings.merge_with_configuration(test_options.unwrap_or_default(), None, None, &[]).unwrap();

let settings = settings.formatter;

if let Some(attribute_position) = settings.attribute_position {
options = options.with_attribute_position(attribute_position);
}

if !diagnostics.is_empty() {
for diagnostic in diagnostics {
println!("{:?}", print_diagnostic_to_string(&diagnostic));
}

panic!("Configuration is invalid");
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic you added is already handled by SpecTestFile::test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

There was a missing configuration resolution logic in html.rs that caused attribute_position not to be overridden by test_options. So I added code about attribute_position in html.rs.

@github-actions github-actions bot added the A-Project Area: project label Jan 26, 2025
@ematipico ematipico requested a review from dyc3 January 26, 2025 20:47
@ematipico
Copy link
Member

ematipico commented Jan 27, 2025

@Geun-Oh can you please direct your PR against next? We added an important message in the readme https://github.com/biomejs/biome

We also updated our contribution guide regarding changelogs https://github.com/biomejs/biome/blob/next/CONTRIBUTING.md#changelog

@Geun-Oh Geun-Oh changed the base branch from main to next January 27, 2025 11:07
@Geun-Oh
Copy link
Author

Geun-Oh commented Jan 27, 2025

Oh..that's my mistake.
I'll check the conflicts.

@Geun-Oh Geun-Oh closed this Jan 27, 2025
@Geun-Oh Geun-Oh deleted the multiline-in-multiattr branch January 27, 2025 11:23
@Geun-Oh Geun-Oh restored the multiline-in-multiattr branch January 27, 2025 11:23
@Geun-Oh
Copy link
Author

Geun-Oh commented Jan 27, 2025

Opps, the branch was deleted temporary..
I'll reopen it when the rebase is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Formatter Area: formatter A-Project Area: project L-HTML Language: HTML
Projects
None yet
Development

Successfully merging this pull request may close these issues.

📎 HTML: Implement "Attribute Position" option
4 participants