unplugin-auto-import icon indicating copy to clipboard operation
unplugin-auto-import copied to clipboard

Fix Biome Ignore Magic Comments

Open nikolas-sturm opened this issue 4 months ago • 4 comments

Description

Fixes the single line only magic comments to instead suppress biome across the whole file as expected.

Before:

> biome check

src/auto-imports.d.ts:6:1 suppressions/unused

  ⚠ Suppression comment has no effect. Remove the suppression or make sure you are suppressing the correct rule.
  
    4 │ // noinspection JSUnusedGlobalSymbols
    5 │ // Generated by unplugin-auto-import
  > 6 │ // biome-ignore lint: disable
      │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    7 │ export {}
    8 │ declare global {
  

Checked 73 files in 15ms. Fixed 1 file.
Found 1 warning.

After:

> biome check

Checked 73 files in 18ms. No fixes applied.

nikolas-sturm avatar Aug 03 '25 20:08 nikolas-sturm

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Tested working in version 2.1.3, but it seems unable to prevent formatting

ilyaliao avatar Aug 03 '25 23:08 ilyaliao

Ok. I've decided to rewrite the whole biomejs integration to also prevent formatting of the file. As of right now, biomejs unfortunately does not provide a magic comment to disable formatting. According to their docs, the intended solution is to use the negated matcher in the files.includes array in the biome.{json,jsonc} config. I have written a small function using the jsonc-parser that allows automatically updating this and is strictly opt-in. I have also added a separate test to make sure this works as intended. It also auto-detects the indentation style the user has in their biome.json file and uses that. Additionally, I removed the biomelintrc related functionality as it seems to be deprecated and does not exist anymore. In my testing, biome correctly reads from the generated .d.ts file and parses the globals.

nikolas-sturm avatar Aug 04 '25 09:08 nikolas-sturm

I am not so sure about the complexity introduced here to support a simple ignore feature - shouldn't the Biome side provides better DX on this?

antfu avatar Nov 27 '25 02:11 antfu