Skip to content

fix(lines-around-comment): allow comments at the start of namespace blocks - #31

Merged
d3lm merged 1 commit into
mainfrom
chris/lines-around-comment-module-block-5d4a
Nov 12, 2026
Merged

d3lm merged 1 commit into
mainfrom
chris/lines-around-comment-module-block-5d4a

Conversation

@sheepsteak

Copy link
Copy Markdown
Member

Closes #28.

@blitz/lines-around-comment requires a blank line before a comment at the start of a namespace/module block, and prettier/prettier deletes that blank line, so code like this can't pass both rules:

declare namespace something {
  /** JSDoc describing this */
  export const entry: 1;
}

The @blitz rule only handles comments at the start/end of enums, switches, arrays, objects, and type literals itself (START_END_NODES). Comments in a TSModuleBlock fall through to the wrapped @stylistic/ts/lines-around-comment rule, which already supports allowModuleStart. The recommended config never enabled it, so this PR sets allowModuleStart: true next to the other allow*Start options. TypeScript files get the same options through tsRules(). Comments elsewhere in a namespace still need a blank line before them.

Alternatives considered:

  • Adding TSModuleBlock to START_END_NODES. The rule's isStartAllowed/isEndAllowed checks are an OR across every allow*Start/allow*End option, so unrelated options such as allowArrayStart would also exempt namespaces.
  • Also setting allowModuleEnd. It has no effect, because the config doesn't enable afterBlockComment/afterLineComment.

Tests

  • New spec cases for allowModuleStart cover declare namespace, namespace, declare module 'foo', and the fixer output when the option is off.
  • Two cases run the rule with the options from the shipped jsRules. One checks that the issue's snippet is valid, and one checks that a comment in the middle of a namespace still errors. Reverting the config line makes the first one fail.
  • I also ran the issue's snippets through the full recommended() config, including prettier/prettier. The snippet without a blank line is now clean for both rules. Comments at the start of namespace A.B and declare module 'foo' blocks are clean too.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation if applicable (n/a: allowModuleStart is a base rule option, already covered by the linked @stylistic/ts docs)
  • I have added tests for this change

…locks

The rule required a blank line before a comment at the start of a `namespace`/`module` block, which `prettier/prettier` removes, so both rules could not pass at once. Enable the base rule's `allowModuleStart` option in the recommended config.

Closes #28
@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@sheepsteak
sheepsteak marked this pull request as ready for review November 11, 2026 16:15
@sheepsteak sheepsteak mentioned this pull request Nov 11, 2026
4 of 5 tasks
@d3lm
d3lm merged commit c4a2800 into main Nov 12, 2026
2 checks passed
@d3lm
d3lm deleted the chris/lines-around-comment-module-block-5d4a branch November 12, 2026 09:23
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.

@blitz/lines-around-comment conflicts with prettier/prettier

2 participants