fix: use suffix matching for formatter file extensions#14537
Open
kevinWangSheng wants to merge 1 commit intoanomalyco:devfrom
Open
fix: use suffix matching for formatter file extensions#14537kevinWangSheng wants to merge 1 commit intoanomalyco:devfrom
kevinWangSheng wants to merge 1 commit intoanomalyco:devfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #3431
Type of change
What does this PR do?
path.extname()only returns the last segment of a file extension — for example,path.extname("template.blade.php")returns.phpinstead of.blade.php. This means formatters configured with compound extensions like.blade.phpor.html.erbcan never match.I replaced
path.extname()+Array.includes()withString.endsWith()matching against the full file path. This way"template.blade.php".endsWith(".blade.php")correctly returnstrue.This also fixes a latent bug with the built-in
htmlbeautifierformatter, which already declares.html.erbin its extensions array but could never actually match because of the samepath.extname()limitation.How did you verify your code works?
path.extname("x.blade.php")returns.php(confirming the bug)"x.blade.php".endsWith(".blade.php")returnstrue(confirming the fix)getFormatteris only called internally withinformat/index.ts, so no other callers are affected.go,.py, etc.) still work correctly withendsWithScreenshots / recordings
Not a UI change.
Checklist