Skip to content

Skip tab-indented block comment lines in NoMixedIndentation - #513

Open
dschach wants to merge 1 commit into
forcedotcom:devfrom
dschach:fix/mixed-indentation-block-comments
Open

dschach wants to merge 1 commit into
forcedotcom:devfrom
dschach:fix/mixed-indentation-block-comments

Conversation

@dschach

@dschach dschach commented Oct 28, 2026 •

Copy link
Copy Markdown

Fixes forcedotcom/code-analyzer#2012.

The problem

NoMixedIndentation reports every continuation line of a block comment in a file that is indented with tabs. In ApexDoc and Javadoc-style comments, each continuation line is the indentation of the comment, then one space, then an asterisk. The one space only aligns the asterisk under the asterisk of the opening /**. The line is not mixed indentation, but the rule sees a tab followed by a space and reports it. The same happens for plain /* ... */ block comments, and for block quotes written inside them.

In this class, → stands for one tab character and nothing else. Lines 3 to 6 start with a tab, then one space, then an asterisk. They are reported today:

public class SomeApexClass {
→/**
→ * @description A method-level ApexDoc comment
→ * @param bar Some input
→ * @return Some output
→ */
→public Object foo(Object bar) {
→→return null;
→}
}

Before:

  #   Severity       Rule                       Location                Message
  1   3 (Moderate)   regex:NoMixedIndentation   SomeApexClass.cls:3:1   Leading indentation contains mixed spaces and tabs. ...
  2   3 (Moderate)   regex:NoMixedIndentation   SomeApexClass.cls:4:1   Leading indentation contains mixed spaces and tabs. ...
  3   3 (Moderate)   regex:NoMixedIndentation   SomeApexClass.cls:5:1   Leading indentation contains mixed spaces and tabs. ...
  4   3 (Moderate)   regex:NoMixedIndentation   SomeApexClass.cls:6:1   Leading indentation contains mixed spaces and tabs. ...

After:

Found 0 violations.

The change

  • src/plugin.ts: the rule regex gets a negative lookahead, ^(?!\t+ \*). A line whose leading whitespace is one or more tabs, then exactly one space, then an asterisk is skipped. Every other case is still reported: tabs then two or more spaces, spaces then a tab, and tabs then one space then any character that is not an asterisk. The lookahead is anchored at the start of the line, so it costs one comparison per line.
  • src/messages.ts: the rule description names the exception.
  • package.json: the regex engine's version goes to 0.41.0-SNAPSHOT.
  • test/engine.test.ts and two new fixtures:
    • validIndentation_TabsWithBlockComments.cls has tab-indented ApexDoc comments, a plain block comment two tabs deep, and a block quote and a code block inside an ApexDoc comment. It must produce no violation. The current rule reports 15 lines in it.
    • mixedIndentation_BlockCommentLookalikes.cls has four lines that look like comment continuation lines but are mixed indentation: tabs then two spaces then an asterisk, a space then a tab then a space then an asterisk, tabs then one space then a letter, and tabs then two spaces then text. The test checks the exact four violations with their lines and columns.

The regex_ignore option cannot express this exception. It is tested against the matched text only, which is the leading whitespace, so it never sees the asterisk that follows.

Testing

With the change, the regex engine's build, lint, and tests pass locally (81 tests of 81, with plugin.ts and messages.ts at 100% coverage), and so do the snapshot version check and the package interdependency check. The six existing mixed indentation fixtures produce the same number of matches with the old regex and with the new one.

The title

I do not have a work item number, so the title has none and the title check will fail. Please rename the pull request as you need.

🤖 Generated with Claude Code

A line whose leading whitespace is one or more tabs, then exactly one space, then an asterisk is the continuation line of a tab-indented block comment, such as ApexDoc. The single space only aligns the asterisk under the opening slash-asterisk, so the line is no longer reported as mixed indentation. Every other mixed-indentation case is still reported.
@git2gus

git2gus Bot commented Oct 28, 2026

Copy link
Copy Markdown

Git2Gus App is installed but the .git2gus/config.json doesn't have right values. You should add the required configuration.

@dschach dschach changed the title Skip tab-indented block comment lines in NoMixedIndentation [BUG} Skip tab-indented block comment lines in NoMixedIndentation Oct 28, 2026
@dschach dschach changed the title [BUG} Skip tab-indented block comment lines in NoMixedIndentation [BUG] Skip tab-indented block comment lines in NoMixedIndentation Oct 28, 2026
@dschach dschach changed the title [BUG] Skip tab-indented block comment lines in NoMixedIndentation Skip tab-indented block comment lines in NoMixedIndentation Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][code-analyzer] regex:NoMixedIndentation: False positive on ApexDocs

1 participant