Skip to content

Fix incorrect indentation after comment line in JS/TS#309259

Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/js-indentation-after-comment-299080
Open

Fix incorrect indentation after comment line in JS/TS#309259
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/js-indentation-after-comment-299080

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

Summary

  • Fixes JS: Incorrect indentation after comment line #299080
  • Adds a negative lookahead (?!\s*\/\/) to increaseIndentPattern and indentNextLinePattern in the JavaScript and TypeScript language configuration files so that single-line comment lines (starting with //) are excluded from indentation pattern matching
  • Also updates the test language configuration to stay in sync

Problem

Typing or pasting a commented-out line like // const test = () => { and pressing Enter causes VS Code to incorrectly increase the indentation on the next line. This happens because the increaseIndentPattern sees the unmatched { at the end of the line without recognizing that the entire line is a comment.

The same issue applies to indentNextLinePattern -- a commented line like // if (true) would incorrectly trigger next-line indentation.

Fix

A negative lookahead (?!\s*\/\/) is prepended to both increaseIndentPattern and indentNextLinePattern. This causes lines that begin with // (with optional leading whitespace) to be excluded from matching, while lines with trailing comments like if (true) { // comment continue to work correctly.

Test plan

  • Open a new JS or TS file
  • Type // const test = () => { and press Enter -- cursor should stay at the same indentation level (no extra indent)
  • Type // if (true) and press Enter -- cursor should stay at the same indentation level
  • Type const test = () => { and press Enter -- cursor should be indented (existing behavior preserved)
  • Type if (true) { // comment and press Enter -- cursor should be indented (existing behavior preserved)

…ft#299080)

Add a negative lookahead (?!\s*\/\/) to increaseIndentPattern and
indentNextLinePattern so that lines beginning with // are not treated
as containing unmatched brackets or control-flow keywords.
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: Incorrect indentation after comment line

2 participants