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(codegen,css_formatter): autogenerate property formattting boilerplate #1452

Merged
merged 1 commit into from
Jan 7, 2024

Conversation

faultyserver
Copy link
Contributor

Summary

As we start to implement exact parsing for all of the properties, we're going to start having formatter files for each one (multiple actually. an any, a property, and at least one property_value file to cover each added node.

Each of the overall Property nodes will have exactly the same structure and get formatted exactly the same way:

use crate::prelude::*;
use biome_css_syntax::{CssBorderProperty, CssBorderPropertyFields};
use biome_formatter::write;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssBorderProperty;
impl FormatNodeRule<CssBorderProperty> for FormatCssBorderProperty {
    fn fmt_fields(&self, node: &CssBorderProperty, f: &mut CssFormatter) -> FormatResult<()> {
        let CssBorderPropertyFields {
            name,
            colon_token,
            value,
        } = node.as_fields();
        write!(
            f,
            [name.format(), colon_token.format(), space(), value.format()]
        )
    }
}

It simply destructures the name, colon_token, and value fields, then formats them with a space between the colon and the value. Every property value will do this exactly. So why not put it in the code generation by default!

We can detect that a property node is being generated by checking the language, node concept, and name, and then use this template rather than the format_verbatim_node one. This way adding a new property should only require devs to implement the value formatting. That could also be autogenerated most of the time, but I think it's best left as-is.

If we decide to implement the general CssKeyword node for values, that'll also make it quite a bit easier to manage since most of the time there will only be one node type to format.

Test Plan

I deleted one of the existing property formatter files, ran the codegen, and got the exact same output, so it works!

Copy link

netlify bot commented Jan 7, 2024

Deploy Preview for biomejs canceled.

Name Link
🔨 Latest commit ace6968
🔍 Latest deploy log https://app.netlify.com/sites/biomejs/deploys/659a205a9e3e92000829c22a

@github-actions github-actions bot added the A-Tooling Area: internal tools label Jan 7, 2024
Comment on lines -645 to -646
/// Convert an AstNode name to a path / Rust module name
fn name_to_module(kind: &NodeKind, in_name: &str, language: LanguageKind) -> NodeModuleInformation {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This didn't actually change, the function just moved below the new get_node_concept function.

Copy link
Contributor

github-actions bot commented Jan 7, 2024

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 49701 49701 0
Passed 48721 48721 0
Failed 980 980 0
Panics 0 0 0
Coverage 98.03% 98.03% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 40 40 0
Passed 37 37 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.50% 92.50% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 6322 6322 0
Passed 2036 2036 0
Failed 4286 4286 0
Panics 0 0 0
Coverage 32.20% 32.20% 0.00%

ts/babel

Test result main count This PR count Difference
Total 662 662 0
Passed 592 592 0
Failed 70 70 0
Panics 0 0 0
Coverage 89.43% 89.43% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 17646 17646 0
Passed 13452 13452 0
Failed 4192 4192 0
Panics 2 2 0
Coverage 76.23% 76.23% 0.00%

@faultyserver faultyserver merged commit b16b630 into main Jan 7, 2024
17 checks passed
@faultyserver faultyserver deleted the faulty/codegen-property-format branch January 7, 2024 04:11
@Conaclos Conaclos added the A-Changelog Area: changelog label Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-Tooling Area: internal tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants