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: provide Biome configuration #1717

Closed
wants to merge 1 commit into from
Closed

Conversation

fl0werpowers
Copy link

Biome is an increasingly popular piece of tooling that aims to replace formatters such as Prettier and linters such as ESLint. Written in Rust, it provides a solid performance gain over the tools it seeks to replace, and as such can be quite valuable for contributors who leverage it.

I already use Biome in my fork, both for formatting and linting, however, it seriously messed up my document formatting relative to upstream due to diverging from the defaults. Provided a clean slate, I made a conservative biome config that adheres to existing code style and should reduce friction for those seeking to leverage Biome in the codebase. Linting features are disabled, but could be leveraged in the future for code refactoring, as I find its advice to be generally quite sound.

As the project still treats Prettier as the default, Biome is not included in the dependencies (the config can still be leveraged via npx or through editor extensions). I think it should probably be mentioned somewhere that the code should still go through format command in case Biome's formatting diverges from Prettier's overall.

@fl0werpowers
Copy link
Author

fl0werpowers commented Jan 10, 2025

Formatting the entire project with Biome using npx @biomejs/biome format --write . provides almost no changes to the codebase. There are a couple of exceptions (6 files, including package.json), in most of which Biome's behavior seems to be more accurate than Prettier's given the same settings, particularly concerning "lineWidth": 100 ("printWidth": 100 in Prettier).

Example file: quartz/plugins/emitters/componentResources.ts

Code considered valid by Prettier (112 characters in a single line):

      posthog.init('${cfg.analytics.apiKey}',{api_host:'${cfg.analytics.host ?? "https://app.posthog.com"}'})\`

Code transformed by Biome (split into 3 lines, longest being 59 characters):

      posthog.init('${cfg.analytics.apiKey}',{api_host:'${
        cfg.analytics.host ?? "https://app.posthog.com"
      }'})\`

Rerunning npm run format afterwards produces two minor differences that Prettier and Biome seem to be in conflict with. In quartz/components/scripts/graph.inline.ts line 147 has parentheses removed in (data.get(url)?.title ?? url), which is reverted by Prettier:

    const text = url.startsWith("tags/") ? "#" + url.substring(5) : data.get(url)?.title ?? url

In package.json lines 26-33 get reformatted by Biome into a single line that respects the 100 character width, which also gets reverted by Prettier:

  "keywords": ["site generator", "ssg", "digital-garden", "markdown", "blog", "quartz"],

@aarnphm
Copy link
Collaborator

aarnphm commented Jan 11, 2025

This is cool, but if we start accepting all configurations for all the tools, that would be a can of worm we can't close :)

I think for ppl who wants to use this, could be a great entrypoint. For base Quartz, I think we should just keep it simple

@aarnphm aarnphm closed this Jan 11, 2025
@fl0werpowers
Copy link
Author

Fair point. I may actually replace it outright in my fork.

@aarnphm
Copy link
Collaborator

aarnphm commented Jan 11, 2025

feel free to. you own your quartz, https://quartz.jzhao.xyz/philosophy#a-garden-should-be-your-own

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants