fix: respect beautify ignore tags during range formatting#246
Open
maruthang wants to merge 1 commit into
Open
Conversation
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.
Summary
Fixes #215
Bug:
<!-- beautify ignore:start -->/<!-- beautify ignore:end -->directives were silently ignored by the formatter, causing content within ignore blocks to be reformatted.Root Cause: Two issues: (1) When range-formatting inside an ignore block, the selected range did not include the ignore boundary comments, so js-beautify never saw them. (2) The directive regex in the bundled js-beautify required exact single spaces, rejecting comments with extra whitespace.
Fix: Added
expandRangeToIgnoreBlockinhtmlFormatter.tsto detect when a formatting range falls inside an ignore block and expand it to include the boundary comments. Relaxed the directive regex in bothbeautify-html.jsandbeautify-css.jsto allow flexible whitespace.Changes
src/services/htmlFormatter.ts: AddedexpandRangeToIgnoreBlock()function that detects when a range falls within an ignore block and expands it to include the<!-- beautify ignore:start/end -->boundaries so js-beautify can recognise and skip the content.src/beautify/beautify-html.js: Relaxed__directives_block_patternregex from requiring exact single spaces to allowing flexible whitespace (\s*/\s+).src/beautify/beautify-css.js: Same regex fix asbeautify-html.js.src/test/formatter.test.ts: Added 4 regression tests covering full-document ignore blocks, range formatting inside ignore blocks, extra whitespace in ignore comments, and Go template syntax preservation.Testing
src/test/formatter.test.tsthat verify ignore blocks are respected during both full-document and range formatting