Skip to content

Comments

fix: use suffix matching for formatter file extensions#14537

Open
kevinWangSheng wants to merge 1 commit intoanomalyco:devfrom
kevinWangSheng:fix/formatter-compound-extensions
Open

fix: use suffix matching for formatter file extensions#14537
kevinWangSheng wants to merge 1 commit intoanomalyco:devfrom
kevinWangSheng:fix/formatter-compound-extensions

Conversation

@kevinWangSheng
Copy link

@kevinWangSheng kevinWangSheng commented Feb 21, 2026

Issue for this PR

Closes #3431

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

path.extname() only returns the last segment of a file extension — for example, path.extname("template.blade.php") returns .php instead of .blade.php. This means formatters configured with compound extensions like .blade.php or .html.erb can never match.

I replaced path.extname() + Array.includes() with String.endsWith() matching against the full file path. This way "template.blade.php".endsWith(".blade.php") correctly returns true.

This also fixes a latent bug with the built-in htmlbeautifier formatter, which already declares .html.erb in its extensions array but could never actually match because of the same path.extname() limitation.

How did you verify your code works?

  • Checked that path.extname("x.blade.php") returns .php (confirming the bug)
  • Checked that "x.blade.php".endsWith(".blade.php") returns true (confirming the fix)
  • Verified getFormatter is only called internally within format/index.ts, so no other callers are affected
  • Reviewed that single-segment extensions (.go, .py, etc.) still work correctly with endsWith

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

path.extname() only returns the last extension segment, so compound
extensions like .blade.php or .html.erb never matched their configured
formatters. Switch to endsWith-based matching against the full file
path so multi-part extensions work correctly.

Fixes anomalyco#3431
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.

[FEATURE]: Formatter enhanced file extension matching

1 participant