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

refactor(formatter_test): refactor TestFormatLanguage trait #3395

Merged
merged 4 commits into from
Jul 9, 2024

Conversation

ah-yu
Copy link
Contributor

@ah-yu ah-yu commented Jul 9, 2024

Summary

Part of #3334

The current TestFormatLanguage trait does not adapt to the new js formatter api, because we need to pass in other language formatters, and we also need to read other language settings. We can use the abstraction provided by the biome_formatter::format_node function to simplify the TestFormatLanguage trait to meet our needs.

pub trait TestFormatLanguage {
    type ServiceLanguage: ServiceLanguage + 'static;
    type Context: CstFormatContext<
        Options = <Self::ServiceLanguage as ServiceLanguage>::FormatOptions,
    >;
    type FormatLanguage: FormatLanguage<Context = Self::Context, SyntaxLanguage = Self::ServiceLanguage>
        + 'static
        + Clone;

    fn parse(&self, text: &str) -> AnyParse;

    fn format_node(
        &self,
        language: Self::FormatLanguage,
        node: &SyntaxNode<Self::ServiceLanguage>,
    ) -> FormatResult<Formatted<Self::Context>> {
        biome_formatter::format_node(node, language)
    }

    fn format_range(
        &self,
        language: Self::FormatLanguage,
        node: &SyntaxNode<Self::ServiceLanguage>,
        range: TextRange,
    ) -> FormatResult<Printed> {
        biome_formatter::format_range(node, range, language)
    }

    fn to_format_language(
        &self,
        settings: &Settings,
        file_source: &DocumentFileSource,
    ) -> Self::FormatLanguage;
}

Test Plan

CI should pass

@github-actions github-actions bot added A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages L-CSS Language: CSS L-JSON Language: JSON and super languages labels Jul 9, 2024
Copy link

codspeed-hq bot commented Jul 9, 2024

CodSpeed Performance Report

Merging #3395 will not alter performance

Comparing ah-yu:refactor/fmt-test-infra (19a4f25) with main (a285781)

Summary

✅ 108 untouched benchmarks

@ah-yu ah-yu merged commit 29280e3 into biomejs:main Jul 9, 2024
12 checks passed
@ah-yu ah-yu deleted the refactor/fmt-test-infra branch July 9, 2024 07:20
@Conaclos Conaclos added the A-Changelog Area: changelog label Sep 10, 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-Formatter Area: formatter L-CSS Language: CSS L-JavaScript Language: JavaScript and super languages L-JSON Language: JSON and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants