Skip to content

fix: respect beautify ignore tags during range formatting#246

Open
maruthang wants to merge 1 commit into
microsoft:mainfrom
maruthang:fix/issue-215-beautify-ignore-tags
Open

fix: respect beautify ignore tags during range formatting#246
maruthang wants to merge 1 commit into
microsoft:mainfrom
maruthang:fix/issue-215-beautify-ignore-tags

Conversation

@maruthang

Copy link
Copy Markdown
Contributor

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 expandRangeToIgnoreBlock in htmlFormatter.ts to detect when a formatting range falls inside an ignore block and expand it to include the boundary comments. Relaxed the directive regex in both beautify-html.js and beautify-css.js to allow flexible whitespace.

Changes

  • src/services/htmlFormatter.ts: Added expandRangeToIgnoreBlock() 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_pattern regex from requiring exact single spaces to allowing flexible whitespace (\s* / \s+).
  • src/beautify/beautify-css.js: Same regex fix as beautify-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

  • Added 4 regression tests in src/test/formatter.test.ts that verify ignore blocks are respected during both full-document and range formatting
  • All 157 existing tests pass

)

Range formatting now expands to include ignore block boundaries so
js-beautify can recognise and skip ignored content. Also relaxed the
directive regex in beautify-html.js and beautify-css.js to allow
flexible whitespace in ignore comments.
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.

js-beautify ignore tags are ignored

1 participant