Skip to content

feat(lint): add the noNestedCommentsInHeader rule - #265

Merged
allanbowe merged 1 commit into
mainfrom
feat/no-nested-comments-in-header
Oct 27, 2026
Merged

allanbowe merged 1 commit into
mainfrom
feat/no-nested-comments-in-header

Conversation

@sasjs-dev

@sasjs-dev sasjs-dev Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Issue

sasjs/cli#1499 - a nested block comment inside a doxygen header truncates the header and the remainder is compiled as SAS. The compile-time fix is sasjs/utils#288; this is the author-time gate.

Intent

Report a block comment inside the doxygen header where the header is written, instead of leaving the author to bisect a build.

A doxygen header is a SAS block comment, and SAS block comments do not nest: the first close marker ends the comment. So a /* ... */ inside the header closes it early, and the rest - @param lines, code in a usage example - runs as live SAS. Header text holding /*/ ends the header the same way, with no comment involved: @details outputs land in src/*/file.sas is enough.

Implementation

src/rules/file/noNestedCommentsInHeader.ts, a file rule registered with the others:

  • On by default, severity WARNING, like the other header rules: sasjs lint keeps its return code on upgrade, and the build still fails at the same shape through the compile check. severityLevel: {"noNestedCommentsInHeader": "error"} makes it fatal for a project that wants that.
  • Reports at the close marker that ends the header early, whether it belongs to a nested comment, sits straight after an opener (a /*/), is bare text, or is an inner snippet closing with its own **/ - a distinct message for the first three.
  • The header's terminator has to stand alone on its line and arrive before another header opens. A **/ inside a statement is that statement's text, and one behind a later /** closes that header, so neither counts. A second plain comment inside the same header does not suppress the report - it is part of the text that leaked.
  • Silent in the states where nothing is truncated, so it agrees with the compile check rather than reporting files that build: a **/ that is the header's own terminator, and a header with no terminator of its own.
  • Only the header the file opens with is inspected, which is the header sasjs compile reads. A file that opens with code has no header to truncate, and hasDoxygenHeader covers that shape.

No fix: deleting the author's comment would rewrite their code, and the /*/ case has no mechanical repair.

Wiring follows the repo's own guards: src/rules/file/index.ts, the LintConfig registration, DefaultLintConfiguration, the README defaults block plus a section, and sasjslint-schema.json (default, property and severityLevel entry) - the specs that compare all of these fail if any one is missed.

The formatter guard

hasDoxygenHeader - the rule that already owns the header's form - now also reports a header that closes with a single asterisk, and its fix widens that marker to the double-asterisk form:

 /**
   @file
   @brief Example
 */

becomes

 /**
   @file
   @brief Example
 **/

That is what closes the blind spot below rather than only documenting it: two tools locate the header's end by its terminator, so a plain-*/ header is invisible to both, and the truncation check can only see a header once it is in the form. A header whose body holds a comment opener is left alone - the first close marker may belong to that comment, and that call belongs to the author.

Documentation moved with the behaviour: the closing style is described under hasDoxygenHeader (where the fix lives), and noNestedCommentsInHeader points at it rather than restating the constraint.

Upgrade notes

Two changes are visible to an existing project, both at WARNING severity, so sasjs lint keeps its return code and the commit stays a feat:

  • noNestedCommentsInHeader is on by default. It reports a doxygen header that SAS ends early - a nested comment, a /*/, a bare close marker, or an inner snippet closing with its own **/.
  • hasDoxygenHeader now also reports a header that closes with a single asterisk, where before it only checked the opener. sasjs format rewrites that close marker to the double-asterisk form.

A project that promotes warnings to errors (severityLevel) sees both on its next lint run; set "noNestedCommentsInHeader": false to silence the first, and run sasjs format for the second.

Checks

  • npm run lint - Prettier clean.
  • npx tsc --noEmit - clean.
  • npm test - 522 tests, 48 suites.
  • node scripts/mutation-gate.mjs pr - passed.

Mutation

Scoped to the new file, before the baseline entry was written:

All files                    |  96.00 | 96.00 | 92 killed | 4 timeout | 4 survived | 0 no cov | 0 errors
 noNestedCommentsInHeader.ts |  96.00 | 96.00 | 92 killed | 4 timeout | 4 survived | 0 no cov | 0 errors

The four survivors are the null/-1 guard families and index arithmetic where the characters at the offsets are /, * or whitespace, and the four timeouts are terminator-loop mutants that stop advancing the cursor - a hang is itself a detection for any input that reaches it.

The run reached this from 96.55% of a smaller module: the added branch for a bare close marker and the line-leading terminator check cost score but cover two more shapes, and the specs grew by five to kill what could be killed.

mutation-baseline.json gains an entry with those counts, so the ratchet starts from this PR rather than the 80% new-file floor.

Not in this PR

Once @sasjs/utils releases the getDoxygenHeader export from sasjs/utils#288, this rule can delegate the extent arithmetic to it instead of keeping its own copy. The semantics are deliberately identical today, and the specs pin the same shapes in both repos.

@sasjs-dev sasjs-dev Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full diff of #265 (rule, spec, schema, README, config wiring, mutation baseline).

  • src/rules/file/noNestedCommentsInHeader.ts:58 - the guard !value.slice(close + 2, terminator).includes('/') suppresses the case the rule exists for. A header whose truncated remainder holds a second comment (for example @details usage text with two / ... */ notes) goes silent, because the second opener is taken to mean another comment owns the terminator. Narrow the guard to a new header opener ('/**') inside that slice, which is what the later-header case actually turns on, and revisit the spec case that expects silence there: the first header's own plain close marker truncates it, so that shape is a true positive.

  • src/types/LintConfig.ts:162 and src/utils/getLintConfig.ts:38 - the rule ships enabled by default at Severity.Error (src/rules/file/noNestedCommentsInHeader.ts:40), so every consumer with a /* or /*/ in a doxygen header starts failing sasjs lint on upgrade while the commit type is feat: (minor release). Either mark it breaking (feat!: or a BREAKING CHANGE footer) or default it off, or to warn like the neighbouring header rules.

2 findings above for review.

@sasjs-dev
sasjs-dev Bot force-pushed the feat/no-nested-comments-in-header branch from cf61bdb to c020bd2 Compare October 27, 2026 01:56

@sasjs-dev sasjs-dev Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full base...head diff: new noNestedCommentsInHeader rule, its spec, and the config/schema/README/mutation-baseline wiring. All spec cases behave as asserted; two coverage gaps below.

  • src/rules/file/noNestedCommentsInHeader.ts:58 - !value.slice(close + 2, terminator).includes('/*') blocks the report whenever ANY opener appears between the first close marker and the **/ terminator, not just an opener that begins a later doxygen header. Consequence: a header holding two nested comments (@details /* a */ followed by /* b */) is reported clean, and so is a header that holds both /*/ text and a later /* ... */ - both truncate the header exactly as the single-comment case does. Narrow the guard to a later header only, e.g. /^\s*\/\*\*/m.test(value.slice(close + 2, terminator)), so a second plain comment inside the same header does not suppress the diagnostic.

  • src/rules/file/noNestedCommentsInHeader.ts:46 - !value.startsWith('/**', start) restricts the rule to a file whose first non-whitespace token is /**. A doxygen header that follows other code (a file opening with %put/%let, or a second header further down) is never inspected. If that is deliberate, say so in the README section, which currently reads as covering any header; otherwise scan from the leading /** onward rather than returning [] for the whole file.

No blocking issues; 2 findings above for review.

@sasjs-dev
sasjs-dev Bot force-pushed the feat/no-nested-comments-in-header branch from c020bd2 to d43e516 Compare October 27, 2026 02:25
@sasjs-dev

sasjs-dev Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

All four findings addressed in d43e516.

The /* guard (both reviews, same point - accepted). It was too broad: any opener between the close marker and the terminator suppressed the report, including a second comment in the same header, which is part of the text that leaked. It is now LATER_HEADER = /^[ \t]*\/\*\*/m against that slice, so only a later header owns the terminator. should report the first of two comments inside one header pins the case you named.

The terminator, one level down (same class as the guard). While fixing that I found the mirror-image hole: a **/ inside a statement - put 'a **/ marker'; - was being taken as the header's terminator, so a header holding a /* would report on valid SAS. The terminator now has to stand alone on its line, which is the house style and what every header in core, cli and utils already does. should ignore a terminator that is not alone on its line pins it.

Bare close marker. Widened to match the rule name: a header closed early by a */ in its text, with no opener involved, is now reported as Doxygen header contains a close marker as text. Three causes, three messages: nested comment, /*/, bare text.

Severity (accepted). Default is now WARNING rather than ERROR - the neighbouring header rules' level - so sasjs lint keeps its return code for every existing project and feat: stays honest. severityLevel: {"noNestedCommentsInHeader": "error"} makes it fatal where a team wants the build to stop. README and sasjslint-schema.json carry the new default, and the section now says so explicitly.

Scope (documented, not widened). Only the header a file opens with is inspected, because that is the header sasjs compile reads: a header after code is not the file header, and hasDoxygenHeader is the rule for that shape. The README section and the rule's own docs now say this in one line each, and the test for it is should return an empty array for a file opening with a plain comment plus the fixtures that put a header after code.

Mutation: 89.69% (87 killed, 10 survived, 0 uncovered), baseline entry refreshed to those counts. The survivors are the -1/null guard families and index arithmetic where the characters at the offsets are /, * or whitespace - listed in the PR body with the reason for each.

Also fixed the coverage gap that made the first push red: LintConfig's !== false branch had no test, which failed the src/types/ branch threshold. A spec now switches the rule off and asserts it is left out.

@sasjs-dev sasjs-dev Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full base...head diff: the new noNestedCommentsInHeader file rule, its spec, and the config/schema/README/mutation-baseline wiring.

  • src/rules/file/noNestedCommentsInHeader.ts:33 ownTerminator returns null unless the header's **/ terminator stands alone on its own line, so a header closed by a plain */ line - or one whose **/ shares its line with header text - is treated as having no terminator and a nested /* ... */ inside it is silently not reported. That is the truncation the rule exists to catch, and the shape the README section and the rule description claim to cover. Either fall back to the last close marker as the header terminator when no standalone **/ is found, or state the **/-only constraint in the README section and in the rule description so the blind spot is visible.

1 finding above for review.

@sasjs-dev
sasjs-dev Bot force-pushed the feat/no-nested-comments-in-header branch from d43e516 to 8ed4e96 Compare October 27, 2026 02:46

@sasjs-dev sasjs-dev Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full base...head diff: the rule, its spec, schema/README/config wiring, mutation baseline and the CI timeout change.

  • src/rules/file/noNestedCommentsInHeader.ts:33 (ownTerminator) searches for one terminator and stops there: it takes the first **/ at or after the close marker, and if (value.slice(lineStart, terminator).trim()) return null gives up entirely when that candidate is not alone on its line. A header that holds a mid-line **/ before its real terminator is therefore never reported, including the rule's own headline shape - header text with a bare close marker, followed later in the header text by an inline terminator in a usage example, never reaches a finding because the search bails on the inline one instead of moving on to the next candidate. Loop over successive indexOf(TERMINATOR, ...) hits, skipping the non-standalone ones and the ones that fall after a later /**, and take the first that survives.

  • src/rules/file/noNestedCommentsInHeader.ts:77: value[close - 1] === '*' treats any **-prefixed close as the well-formed header terminator, so a nested comment written with a **/ closer inside the header is skipped silently even though SAS cuts the header at that marker. If covering it is not worth the parsing, say so in the rule description so the gap is documented rather than implicit.

2 findings above for review.

@sasjs-dev
sasjs-dev Bot force-pushed the feat/no-nested-comments-in-header branch from 8ed4e96 to 1f35a8c Compare October 27, 2026 02:58
@sasjs-dev

sasjs-dev Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Both points handled in 1f35a8c - one as a code change, one as the documentation you offered as the alternative.

The missed inner snippet. Same class as a finding on the utils side: the early return value[close - 1] === '*' assumed a **/ close is always the header's own terminator, so @details a snippet: /** @file x **/ ended the header silently. The rule now returns only when the terminator is the close minus one, and the terminator search loops over candidates until one stands alone on its line. should report an inner snippet that closes with its own terminator pins it.

A header closed by a plain */ (documented, not widened). Falling back to the last close marker would report the shape you and I both know is not a truncation - /** ... use /* to open a comment ... */ where the /* is text and the */ is the real end - so the rule keeps the **/ requirement and now says so in two places. The README section states both boundaries explicitly (file-opened header only; **/ alone on its line identifies the end, so a plain-*/ header is not inspected), and the rule's description carries the same constraint, which puts it in the schema and in editor tooltips too.

Mutation after the change: 96.00% on the rule (92 killed, 4 survived, 4 timeouts), baseline entry refreshed. The four survivors are the null/-1 guard families and index arithmetic; the timeouts are terminator-loop mutants that stop advancing the cursor.

Also in this push: the mutation job's timeout-minutes went 20 -> 35 with a comment saying why. Registering a rule means the gate mutates LintConfig.ts too, and the previous run was cancelled at 20 minutes without finishing - the cap is there to stop a hung run, not a legitimate one.

@sasjs-dev sasjs-dev Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full base...head diff: rule implementation and spec, schema/README, LintConfig + getLintConfig wiring, mutation baseline, and the mutation-pr workflow timeout bump. Registration (default-on via !== false), severity plumbing, position reporting and the sibling-rule column convention all check out; two non-blocking notes.

  • src/rules/file/noNestedCommentsInHeader.ts:42 - the LATER_HEADER guard runs before the lineLeading check for every candidate and returns null outright, so a header that mentions a header shape in its own text (a line-leading /** before the terminator) suppresses the report entirely, even when a real /* ... */ precedes it. /** inside an open block comment opens nothing in SAS - it is header text - so the guard should only disqualify candidates that come after such an opener when the earlier comment was already closed, not swallow the first candidate. As written, the primary case the rule exists for goes unreported for any header that documents the header format.

  • src/rules/file/noNestedCommentsInHeader.ts:65 - the doc comment claims parity with sasjs/utils#288 in both directions ("and the other way round"), but this rule is deliberately silent on several truncation shapes: headers closed with a plain */, headers that are not the file's first, and truncated headers with no line-leading **/ terminator. Unless the compile-time check keys on exactly the same boundaries, a file this rule passes can still fail sasjs compile. Confirm the boundaries match utils and state it precisely, or drop the reciprocal claim here and at README.md:314.

2 findings above for review.

@sasjs-dev
sasjs-dev Bot force-pushed the feat/no-nested-comments-in-header branch from 1f35a8c to 316b258 Compare October 27, 2026 03:12
@sasjs-dev

sasjs-dev Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Both notes addressed in 316b258.

The LATER_HEADER guard (documented, not loosened). You are right that it swallows the first candidate, and I looked at whether it can be narrowed. It cannot do better than it does, because the two shapes are the same shape locally:

/**
  @details a nested /* comment */
  /** the header shape
**/

and

/**
  @file a
  @details a nested /* comment */
*/
%macro a; %mend;

/**
  @file b
**/

In both, a line-leading /** sits between the close marker and a later terminator. In the first, that /** is leaked text and the terminator is this header's. In the second it opens a real header and the terminator is that header's. Deciding which - without a parser over the leaked code - is not possible from the text alone, and guessing "mine" is the false positive the earlier round asked me to remove (attributing another header's terminator to this one). So the bound stays, and the blind spot is now written down in the function comment and in the README section, so it is visible rather than surprising.

The parity claim (fixed). The boundaries are in fact identical in both, which is why the claim was there - but "and the other way round" was the wrong way to say it. Both are silent on: a header that is not the file's first, a header closed with a plain */ (no terminator of its own), and a truncated header with no line-leading terminator. Both report the same four shapes: nested comment, /*/, bare close marker, inner snippet closing with **/. The doc comment now lists the three boundaries and says the two functions are line-for-line equivalents, rather than asserting parity in the abstract, and README.md:314 carries the same boundaries.

Also: the push before this one broke the build. I put **/ inside a block comment while documenting the parity, which terminated it, and jest reported it as a suite that failed to run. Fixed in 316b258 - npm test 518, prettier clean, tsc clean.

@sasjs-dev sasjs-dev Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full diff of #265: the new file rule noNestedCommentsInHeader and its spec, the config/schema/README wiring, and the mutation-runner timeout bump. Rule logic reads correctly against the documented boundaries (opening header only, line-leading **/ terminator, no later opener in between), including the /*/ text case and the bare */ text case.

  • src/rules/file/noNestedCommentsInHeader.ts:21 - positionOf re-implements index-to-line/column locally, while the rest of the repo routes this through src/utils/splitLines.ts (which documents why splitting is on /\r\n|\n/ and not the configured line ending) and src/utils/getColumnNumber.ts. Two conventions for one job is how they drift; put a getPosition(text, index) in src/utils and use it here rather than a rule-local helper.
  • src/rules/file/noNestedCommentsInHeader.ts:111 - endColumnNumber: columnNumber + 1 spans one character, but the markers reported (/*, */) are two characters, and the other file rules size the range to the token they name. Extend by the marker length so an editor highlight covers what the message reports.

2 findings above for review.

@sasjs-dev
sasjs-dev Bot force-pushed the feat/no-nested-comments-in-header branch from 316b258 to 58737a1 Compare October 27, 2026 03:44
@sasjs-dev

sasjs-dev Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Both taken in 58737a1 - the first one is the better catch, my helper duplicated a decision the repo had already made.

positionOf (accepted). It re-derived line and column from a \n split, which quietly assumes the file's endings and duplicates the reasoning src/utils/splitLines.ts documents. The rule now builds on splitLines, and the index-to-position maths is three lines that cannot drift from the repo's own split. I did not add a getPosition to src/utils: it has one caller, and splitLines already carries the semantics worth sharing. Say the word if you would rather see it promoted.

endColumnNumber (accepted). The range is now two characters wide, matching the marker the message names - endColumnNumber: columnNumber + 2. That is nine spec expectations updated, and the rule's reported range now covers /* rather than its first character.

Mutation after the change: 96.88% (89 killed, 4 survived, 4 timeouts), baseline entry refreshed, gate green locally. Dropping the hand-rolled arithmetic removed a mutant family, so the score went up while the code got smaller.

On the previous round's two notes, which are also answered: the LATER_HEADER bound stays and its blind spot is documented in the rule and the README, because a line-leading /** in leaked text is not distinguishable from a second header; and the parity claim now lists the three boundaries both sides use instead of asserting equivalence in the abstract.

@sasjs-dev sasjs-dev Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full base...head diff: the new file rule and its tests, registration in LintConfig and the file rule index, DefaultLintConfiguration, JSON schema, README, mutation baseline, and the mutation-pr workflow timeout change. Re-ran the rule's matching logic against the spec's boundary cases (well-formed header, plain-/ close, nested comment, // in text, bare close marker, later-header ownership) - behaviour matches the documented contract.

No blocking issues.

@sasjs-dev

sasjs-dev Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Two decisions from the maintainer, both keeping what is in this PR.

  • The mutation job's timeout-minutes: 20 -> 35 stays. Registering a rule makes the gate mutate LintConfig.ts, and that run legitimately needs longer than twenty minutes on a two-core runner; the cap is there for a hung run, not a busy one.
  • The formatter guard I floated as a possible follow-up is going into this PR rather than a separate one, because it closes the blind spot this PR documents. It reports and rewrites a header that closes with a single asterisk to the **/ form, so sasjs format leaves headers the truncation check can see. A header whose body already holds a comment opener is left alone - that shape is ambiguous and belongs to the author.

If you would rather review the guard as its own change, say so and I will split it out.

@sasjs-dev
sasjs-dev Bot force-pushed the feat/no-nested-comments-in-header branch from 58737a1 to 8428c28 Compare October 27, 2026 09:16
@sasjs-dev

sasjs-dev Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

The guard is in, in 8428c28, and to answer your question about where it belongs: hasDoxygenHeader, which already owns the header's form.

That rule already reported the opener half (/* where /** is wanted). It now reports the closer half as well - "close with double asterisks" - and its fix widens the marker, which is the piece that actually closes the blind spot rather than just documenting it: both this rule set and sasjs compile locate the header's end by its terminator, so a plain-*/ header is invisible to the truncation check until something rewrites it into the form. sasjs format now does.

The guard's own boundary, so it cannot make things worse: it only widens a close marker when the header's body holds no comment opener. A body with a /* in it is the ambiguous shape (the first close marker may belong to that comment rather than to the header), and widening there would paper over a genuine truncation by making the header look terminated. Those go to the author.

Documentation followed the behaviour rather than sitting on the rule that only observes it: the closing style and its consequence are described under hasDoxygenHeader, next to the fix, and noNestedCommentsInHeader now points at it in one sentence instead of restating the constraint. README and the rule descriptions both updated.

Numbers after the change: 522 tests, coverage thresholds met (the new branch needed two specs plus one for an unterminated header), and mutation 98.96% on hasDoxygenHeader, 96.88% on the new rule - both above the new-file floor, gate green locally.

One observation from the gate run that is worth your attention separately: it reports 246 static mutants, 57% of the total, estimated at 89% of the runtime. That is what pushes a three-file PR past twenty minutes - mostly mutated strings in DefaultLintConfiguration and the rule metadata. ignoreStatic: true would cut the run hard, but it is a change to what the gate measures, so I have not touched it.

@sasjs-dev sasjs-dev Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full diff: the new noNestedCommentsInHeader rule and its spec, the hasDoxygenHeader close-style check and fix, the LintConfig/schema/README wiring, and the mutation baseline and workflow timeout change.

  • src/rules/file/hasDoxygenHeader.ts:20 - const TERMINATOR = '**/' is declared but never referenced; the "already closed" test uses value[close - 1] === '*' instead. Dead constant - remove it, or use it in that comparison so the intent is in one place.
  • src/rules/file/hasDoxygenHeader.ts (test and fix) - this is a behaviour change, not just an addition: a header that closed with */ passed before and now warns by default, on top of a new default-on rule. Projects that treat warnings as failures start failing on upgrade with no migration note, while the repo releases from commit messages and the subject is feat(lint), which cuts a minor. Consider a BREAKING CHANGE: footer, or an explicit upgrade note in the README.
  • src/rules/file/hasDoxygenHeader.ts fix() - singleAsteriskClose(...) as number narrows away the null the helper returns. If that null ever reached the branch, value.slice(0, null) yields '' and the fix would silently replace the file's contents with a single asterisk. Re-check for null and return value unchanged rather than casting.
  • Pre-existing, not this diff: package.json declares @sasjs/utils as ^4.0.0 in dependencies - a floating range in a published runtime dependency. The rest of the manifest is exact-pinned, so this one stands out.

4 findings above for review.

@sasjs-dev
sasjs-dev Bot force-pushed the feat/no-nested-comments-in-header branch from 8428c28 to 41f929b Compare October 27, 2026 09:31
@sasjs-dev

sasjs-dev Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Three of the four taken in 41f929b; the fourth is pre-existing policy, which I would rather raise than change inside this PR.

Dead constant. Removed - TERMINATOR was left behind when the close test became value[close - 1] === '*'. The intent now lives in singleAsteriskClose, which is the only place that decides what counts as "already in the double-asterisk form".

The as number cast (good catch). You are right that a null reaching that branch would have produced '*' + value - the whole file replaced by its own contents behind an asterisk. I did not add the null guard, though, and the reason is worth stating: the message only comes from test, which locates the marker before returning it, so the branch is unreachable - and src/rules demands 100% statement coverage, so a guard there fails the build as dead code. What went in instead is branchless and cast-free: value.indexOf(CLOSE, ...) computed at the same position, with a comment saying the index is present by construction. If it were ever absent, the worst case is the string arithmetic on -1, not a silent wipe of the file - and the spec for the fix asserts the exact output, so it bites.

Upgrade visibility (accepted). The PR body now has an "Upgrade notes" section naming both visible changes - the new default-on rule and the hasDoxygenHeader close-style warning - what each means for a project, and the two ways to opt out ("noNestedCommentsInHeader": false, or sasjs format for the close style). The same note is in the commit body, which is what feeds the release notes on this repo. I kept it at feat rather than feat!: both changes report at WARNING, so no project's lint return code changes on upgrade, and the maintainer has stated that a minor is the right cut for this kind of guard.

@sasjs/utils: ^4.0.0 is deliberate policy on this org's manifests rather than drift - published @sasjs/* packages are taken on a caret so consumers pick up fixes, and third-party dependencies are pinned exactly. Everything else in the manifest follows that split. You are right that it stands out from the rest of the file; changing it belongs in its own PR with the rest of the dependency posture, not here.

@sasjs-dev sasjs-dev Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full diff: the new noNestedCommentsInHeader rule and its spec, the hasDoxygenHeader close check and fix, schema/defaults/docs, mutation baseline and the mutation-pr timeout.

  • src/rules/file/hasDoxygenHeader.ts:119-127 - fix() recomputes the close index with a weaker predicate than test() used (no double-asterisk guard, no comment-opener guard). The in-code claim that no input can reach a bad index only holds while the two predicates agree. Return the index from singleAsteriskClose and reuse it in the fix so the two cannot drift.
  • src/rules/file/hasDoxygenHeader.ts:41 and src/rules/file/noNestedCommentsInHeader.ts:26 - positionOf is duplicated verbatim; move it to src/utils beside splitLines.
  • Behaviour change - hasDoxygenHeader now warns on a header closed with a plain close marker, so codebases that were clean start reporting warnings, and with severityLevel hasDoxygenHeader=error a green pre-commit hook turns red. feat cuts a minor; say so in the release notes so the new warning is not a surprise.
  • package.json - dependencies holds @sasjs/utils as a caret range while .npmrc sets save-exact=true (pre-existing, not introduced here). Pin it.
  • README.md:516 - a blank line was inserted inside the machine-managed ALL-CONTRIBUTORS block, and the bullet and blank-line reformatting is unrelated to the rule. Leave the managed block as generated and keep the churn out of a rule PR.
  • .github/workflows/mutation-pr.yml:39 - the cap is widened for every run to cover one file's mutation cost; scoping the mutant set for src/types/LintConfig.ts would keep the 20-minute guard.

CI at this head is pending with no contexts yet - re-check before merge.

6 findings above for review.

A doxygen header is a SAS block comment, and SAS block comments do not nest:
the first close marker ends the comment. A `/* ... */` inside the header
therefore closes the header early, and the rest of it - `@param` lines, and any
code in a usage example - is compiled as live SAS. The same happens to header
text that holds `/*/`, such as a glob like `src/*/file.sas`.

`sasjs compile` now fails on that shape (sasjs/utils#288), which tells the
author several hundred lines away from the header. This rule reports it where
the header is edited: an error at the nested opener, or at the `/*/` when no
comment was involved.

The formatter guard lives in `hasDoxygenHeader`, the rule that already owns the
header's form: it reports a header that closes with a single asterisk, and its
fix widens that close marker to the double-asterisk form, which is what puts the
header back where the truncation rule can locate its end. A header whose body
holds a comment opener is left alone - the first close marker may belong to that
comment, and that call is the author's.

The rule is registered behind `noNestedCommentsInHeader !== false`, and a spec
pins that it is left out when the setting is false - without it the branch
coverage threshold for `src/types/` fails.

Upgrade note: `noNestedCommentsInHeader` is on by default, and `hasDoxygenHeader`
now also reports a header that closes with a single asterisk where it used to
check the opener only. Both report at WARNING, so `sasjs lint` keeps its return
code and this stays a minor.

The rule is on by default and reports at WARNING severity, like the other
header rules: `sasjs lint` keeps its return code, and the build still fails at
the same shape through the compile check. It covers a nested comment, a
literal sequence straight after an opener, and a bare close marker, and stays
silent in the three states where nothing is truncated - a `**/` that closes the
header first, a header with no terminator of its own, and a `**/` that belongs
to a later header.
@sasjs-dev
sasjs-dev Bot force-pushed the feat/no-nested-comments-in-header branch from 41f929b to d4ef50d Compare October 27, 2026 11:13
@sasjs-dev

sasjs-dev Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

All but two taken in d4ef50d. Both of the ones I did not change are decisions rather than code.

fix/test drift (accepted, and it removed a cast). test and fix now read one diagnose() that returns the diagnosis together with the close index it points at; test projects the five public fields, fix slices with the index. No second indexOf, no predicate to keep in step, and the -1 default for diagnoses that point at no marker is a plain number, so nothing to narrow.

Duplicated positionOf (accepted). Moved to src/utils/getPosition.ts beside splitLines, exported from the barrel, with its own spec covering LF, CRLF and index 0. That spec earned its keep immediately: index 0 crashed on lines[lines.length - 1].length, because splitLines('') is [] - a real bug the local copy had too, masked by every caller passing a non-zero index.

Release notes (done). The PR body has an "Upgrade notes" section naming both visible changes - the new default-on rule, and hasDoxygenHeader now warning on a plain closing marker - with the two opt-outs, and the same note is in the commit body, which is what this repo's release notes are generated from.

README churn (accepted - my damage). I had run prettier --write README.md, which rewrote *Note:* to _Note:_, collapsed double spaces in unrelated sections, added a blank line before a fenced block, and touched the managed contributors block. README is now rebuilt from origin/main with only the three intended edits; the whole diff against main is 18 lines.

@sasjs/utils caret (policy, not this PR). Published @sasjs/* packages are taken on a caret here while third-party dependencies are exact - the caret is what lets a consumer pick up a fix without a release of every package in the chain, and an exact pin in a published package nests duplicate copies in consumers. You are right that it reads as drift against .npmrc; changing it belongs in a dependency-posture PR, not in a rule addition.

Mutation timeout (maintainer decision). Widening to 35 minutes for every run is deliberate - they were asked directly and chose to keep it. Your alternative is the better long-term answer and I have passed it on: scoping the mutant set so src/types/LintConfig.ts does not dominate, or ignoreStatic, since the run reports 253 static mutants at 48% of the total and an estimated 81% of the runtime, almost all of them mutated strings in the defaults object and rule metadata.

CI on this head was green before your review landed (both build jobs), and the local gate is green on d4ef50d.

@sasjs-dev sasjs-dev Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full base...head diff: the new noNestedCommentsInHeader rule, the hasDoxygenHeader close-style change and its fix, the shared getPosition util, plus README, schema, LintConfig wiring, mutation baseline and the mutation-pr timeout change. Rule logic, boundary handling and the added spec coverage are sound; the new dependency-free util is covered for LF and CRLF.

  • CI has no check contexts yet (pending) at this head - confirm the workflow run is green before merge.

No blocking issues.

@sasjs-dev

sasjs-dev Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

CI is green on d4ef50d: build (22) and build (lts/*) both success, and the mutation job finished success after the 35-minute budget. The "no contexts yet" you saw was the first minute after the push.

Nothing else outstanding from your side; the last four findings (fix/test drift, the duplicated position helper, the README churn, the release note) are all in this head.

@allanbowe
allanbowe merged commit 7cb8cb6 into main Oct 27, 2026
5 checks passed
@allanbowe
allanbowe deleted the feat/no-nested-comments-in-header branch October 27, 2026 12:18
@sasjs-gha

sasjs-gha Bot commented Oct 27, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 4.4.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@sasjs-gha sasjs-gha Bot added the released label Oct 27, 2026
sasjs-dev Bot pushed a commit to sasjs/cli that referenced this pull request Oct 27, 2026
`@sasjs/lint` 4.4.0 carries the author-time half of this work
(sasjs/lint#265): the `noNestedCommentsInHeader` rule, and the
`hasDoxygenHeader` check and fix for a header that closes with a single
asterisk. Both report at WARNING, so a project's lint return code does not
change on upgrade.

`@sasjs/core` 6.1.1 is the `mx_execute` fix for the Viya outlogds step
(sasjs/core#477) - a patch with no API change.

The bumps ride in this PR because both touch `package.json` and
`package-lock.json`, which this branch already changes for `@sasjs/utils`
4.1.1; two PRs editing the same lockfile would only conflict.

Verified with `npm ci` against the new lockfile: lint 4.4.0, core 6.1.1 and
utils 4.1.1 resolve; `npm audit --production --audit-level=low` reports no
vulnerabilities.
sasjs-dev Bot pushed a commit to sasjs/cli that referenced this pull request Oct 27, 2026
The compile-time half of this (sasjs/utils#288) and the author-time half
(sasjs/lint#265) are released; this brings them to the CLI and names the file
in the error.

`removeHeader` takes the source path from `@sasjs/utils` 4.1.1, so both call
sites that read a file and strip its header pass it: the compile path for
`SASJsFileType.file`, and the build path that reads program files. A truncated
header used to report line numbers with no file name on those paths, which is
the failure the check exists to prevent.

Dependencies, all in this one commit because they share `package-lock.json`:

- `@sasjs/utils` ^4.1.0 -> ^4.1.1, the release carrying the path argument.
- `@sasjs/lint` ^4.3.2 -> ^4.4.0, carrying `noNestedCommentsInHeader` and the
  `hasDoxygenHeader` single-asterisk close check and fix. Both report at
  WARNING, so a project's lint return code does not change on upgrade.
- `@sasjs/core` ^6.0.0 -> ^6.1.1, the `mx_execute` Viya outlogds fix
  (sasjs/core#477) - a patch with no API change.

The `@sasjs/lint` devDependencies entry is gone: it is a runtime dependency of
`src/commands/lint/processLint.ts`, so the second declaration was dead weight.
Its peer range moves to ^4.4.0, since 4.4.0 is where the rule the CLI ships
comes from.

One unplanned effect of the lint bump: 4.3.2 pinned `@sasjs/utils` exactly and
nested a second copy at 4.0.0 under `node_modules/@sasjs/lint`. 4.4.0 ranges
it, so the tree carries a single utils at 4.1.1 and the lockfile loses 49
lines. That nesting is why these remain caret ranges rather than exact pins.

CI: `.github/workflows/run-tests.yml` gains `HTTP_PORT=5000` in the server
`.env`. `sasjs/server` 3.0.0 (released 2026-10-26 23:35) refuses to start with
no listener enabled, and the job downloads `releases/latest`, so the server
step failed before any test ran on every PR opened since. The wait step polls
port 5000, which is why that is the port.

Verified: `npm ci` on the new lockfile (one copy of each package), `npm audit
--production` clean, tsc and prettier clean, mocked suite 629 passed with only
the environmental `printVersion` failure that also fails on main in this
environment. The new spec fails with the path argument reverted.
sasjs-dev Bot pushed a commit to sasjs/cli that referenced this pull request Oct 27, 2026
The compile-time half of this (sasjs/utils#288) and the author-time half
(sasjs/lint#265) are released; this brings them to the CLI and names the file
in the error.

What changes for a project: a SAS file whose doxygen header is cut short by a
block comment inside it used to compile, and the header text after the cut was
handed to SAS as code. It now fails the compile with a message naming the file
and the lines involved. The input cannot compile - SAS block comments do not
nest, so the first `*/` ends the comment - and the old behaviour silently ran
whatever followed. This is the check from @sasjs/utils 4.1.1, which this
release adopts.

`removeHeader` takes the source path from @sasjs/utils 4.1.1, so both call
sites that read a file and strip its header pass it: the compile path for
`SASJsFileType.file`, and the build path that reads program files. Without it
the diagnostic reported line numbers with no file name on exactly the paths
where a user meets it.

Dependencies, all in this one commit because they share `package-lock.json`:

- `@sasjs/utils` ^4.1.0 -> ^4.1.1, the release carrying the path argument.
- `@sasjs/lint` ^4.3.2 -> ^4.4.0 in `devDependencies` and `peerDependencies`,
  carrying `noNestedCommentsInHeader` and the `hasDoxygenHeader`
  single-asterisk close check and fix. Both report at WARNING, so a project's
  lint return code does not change on upgrade. The declaration stays peer plus
  dev, as on main: lint is imported at runtime and npm 7+ installs a peer
  automatically, so it is not promoted to a hard dependency.
- `@sasjs/core` ^6.0.0 -> ^6.1.1, the `mx_execute` Viya outlogds fix
  (sasjs/core#477) - a patch with no API change.

One unplanned effect of the lint bump: 4.3.2 pinned `@sasjs/utils` exactly and
nested a second copy at 4.0.0 under `node_modules/@sasjs/lint`. 4.4.0 ranges
it, so the tree carries a single utils at 4.1.1 and the lockfile loses 49
lines. That nesting is why these remain caret ranges rather than exact pins.

CI: `.github/workflows/run-tests.yml` gains `HTTP_PORT=5000` in the server
`.env`. `sasjs/server` 3.0.0 (released 2026-10-26 23:35) refuses to start with
no listener enabled, and the job downloads `releases/latest`, so the server
step failed before any test ran on every PR opened since. The wait step polls
port 5000, which is why that is the port.

Verified: `npm ci` on the new lockfile (one copy of each package), `npm audit
--production` clean, tsc and prettier clean, mocked suite 629 passed with only
the environmental `printVersion` failure that also fails on main in this
environment. The spec that pins the file name fails when the path argument is
reverted, and asserts the diagnostic's shape rather than the library's wording.
sasjs-dev Bot pushed a commit to sasjs/cli that referenced this pull request Oct 27, 2026
The compile-time half of this (sasjs/utils#288) and the author-time half
(sasjs/lint#265) are released; this brings them to the CLI and names the file
in the error.

What changes for a project: a SAS file whose doxygen header is cut short by a
block comment inside it used to compile, and the header text after the cut was
handed to SAS as code. It now fails the compile with a message naming the file
and the lines involved. The input cannot compile - SAS block comments do not
nest, so the first `*/` ends the comment - and the old behaviour silently ran
whatever followed. This is the check from @sasjs/utils 4.1.1, which this
release adopts.

`removeHeader` takes the source path from @sasjs/utils 4.1.1, so both call
sites that read a file and strip its header pass it: the compile path for
`SASJsFileType.file`, and the build path that reads program files. Without it
the diagnostic reported line numbers with no file name on exactly the paths
where a user meets it.

Dependencies, all in this one commit because they share `package-lock.json`:

- `@sasjs/utils` ^4.1.0 -> ^4.1.1, the release carrying the path argument.
- `@sasjs/lint` ^4.3.2 -> ^4.4.0 in `devDependencies` and `peerDependencies`,
  carrying `noNestedCommentsInHeader` and the `hasDoxygenHeader`
  single-asterisk close check and fix. Both report at WARNING, so a project's
  lint return code does not change on upgrade. The declaration stays peer plus
  dev, as on main: lint is imported at runtime and npm 7+ installs a peer
  automatically, so it is not promoted to a hard dependency.
- `@sasjs/core` ^6.0.0 -> ^6.1.1, the `mx_execute` Viya outlogds fix
  (sasjs/core#477) - a patch with no API change.

One unplanned effect of the lint bump: 4.3.2 pinned `@sasjs/utils` exactly and
nested a second copy at 4.0.0 under `node_modules/@sasjs/lint`. 4.4.0 ranges
it, so the tree carries a single utils at 4.1.1 and the lockfile loses 49
lines. That nesting is why these remain caret ranges rather than exact pins.

CI: `.github/workflows/run-tests.yml` gains `HTTP_PORT=5000` in the server
`.env`. `sasjs/server` 3.0.0 (released 2026-10-26 23:35) refuses to start with
no listener enabled, and the job downloads `releases/latest`, so the server
step failed before any test ran on every PR opened since. The wait step polls
port 5000, which is why that is the port.

Verified: `npm ci` on the new lockfile (one copy of each package), `npm audit
--production` clean, tsc and prettier clean, mocked suite 629 passed with only
the environmental `printVersion` failure that also fails on main in this
environment. The spec that pins the file name fails when the path argument is
reverted, and asserts the diagnostic's shape rather than the library's wording.
sasjs-dev Bot pushed a commit to sasjs/cli that referenced this pull request Oct 27, 2026
The compile-time half of this (sasjs/utils#288) and the author-time half
(sasjs/lint#265) are released; this brings them to the CLI and names the file
in the error.

What changes for a project: a SAS file whose doxygen header is cut short by a
block comment inside it used to compile, and the header text after the cut was
handed to SAS as code. It now fails the compile with a message naming the file
and the lines involved. The input cannot compile - SAS block comments do not
nest, so the first `*/` ends the comment - and the old behaviour silently ran
whatever followed. This is the check from @sasjs/utils 4.1.1, which this
release adopts.

`removeHeader` takes the source path from @sasjs/utils 4.1.1, so both call
sites that read a file and strip its header pass it: the compile path for
`SASJsFileType.file`, and the build path that reads program files. Without it
the diagnostic reported line numbers with no file name on exactly the paths
where a user meets it.

Dependencies, all in this one commit because they share `package-lock.json`:

- `@sasjs/utils` ^4.1.0 -> ^4.1.1, the release carrying the path argument.
- `@sasjs/lint` ^4.3.2 -> ^4.4.0 in `devDependencies` and `peerDependencies`,
  carrying `noNestedCommentsInHeader` and the `hasDoxygenHeader`
  single-asterisk close check and fix. Both report at WARNING, so a project's
  lint return code does not change on upgrade. The declaration stays peer plus
  dev, as on main: lint is imported at runtime and npm 7+ installs a peer
  automatically, so it is not promoted to a hard dependency.
- `@sasjs/core` ^6.0.0 -> ^6.1.1, the `mx_execute` Viya outlogds fix
  (sasjs/core#477) - a patch with no API change.

One unplanned effect of the lint bump: 4.3.2 pinned `@sasjs/utils` exactly and
nested a second copy at 4.0.0 under `node_modules/@sasjs/lint`. 4.4.0 ranges
it, so the tree carries a single utils at 4.1.1 and the lockfile loses 49
lines. That nesting is why these remain caret ranges rather than exact pins.

CI: `.github/workflows/run-tests.yml` gains `HTTP_PORT=5000` in the server
`.env`. `sasjs/server` 3.0.0 (released 2026-10-26 23:35) refuses to start with
no listener enabled, and the job downloads `releases/latest`, so the server
step failed before any test ran on every PR opened since. The wait step polls
port 5000, which is why that is the port.

Verified: `npm ci` on the new lockfile (one copy of each package), `npm audit
--production` clean, tsc and prettier clean, mocked suite 629 passed with only
the environmental `printVersion` failure that also fails on main in this
environment. The spec that pins the file name fails when the path argument is
reverted, and asserts the diagnostic's shape rather than the library's wording.
allanbowe pushed a commit to sasjs/cli that referenced this pull request Oct 27, 2026
…1500)

The compile-time half of this (sasjs/utils#288) and the author-time half
(sasjs/lint#265) are released; this brings them to the CLI and names the file
in the error.

What changes for a project: a SAS file whose doxygen header is cut short by a
block comment inside it used to compile, and the header text after the cut was
handed to SAS as code. It now fails the compile with a message naming the file
and the lines involved. The input cannot compile - SAS block comments do not
nest, so the first `*/` ends the comment - and the old behaviour silently ran
whatever followed. This is the check from @sasjs/utils 4.1.1, which this
release adopts.

`removeHeader` takes the source path from @sasjs/utils 4.1.1, so both call
sites that read a file and strip its header pass it: the compile path for
`SASJsFileType.file`, and the build path that reads program files. Without it
the diagnostic reported line numbers with no file name on exactly the paths
where a user meets it.

Dependencies, all in this one commit because they share `package-lock.json`:

- `@sasjs/utils` ^4.1.0 -> ^4.1.1, the release carrying the path argument.
- `@sasjs/lint` ^4.3.2 -> ^4.4.0 in `devDependencies` and `peerDependencies`,
  carrying `noNestedCommentsInHeader` and the `hasDoxygenHeader`
  single-asterisk close check and fix. Both report at WARNING, so a project's
  lint return code does not change on upgrade. The declaration stays peer plus
  dev, as on main: lint is imported at runtime and npm 7+ installs a peer
  automatically, so it is not promoted to a hard dependency.
- `@sasjs/core` ^6.0.0 -> ^6.1.1, the `mx_execute` Viya outlogds fix
  (sasjs/core#477) - a patch with no API change.

One unplanned effect of the lint bump: 4.3.2 pinned `@sasjs/utils` exactly and
nested a second copy at 4.0.0 under `node_modules/@sasjs/lint`. 4.4.0 ranges
it, so the tree carries a single utils at 4.1.1 and the lockfile loses 49
lines. That nesting is why these remain caret ranges rather than exact pins.

CI: `.github/workflows/run-tests.yml` gains `HTTP_PORT=5000` in the server
`.env`. `sasjs/server` 3.0.0 (released 2026-10-26 23:35) refuses to start with
no listener enabled, and the job downloads `releases/latest`, so the server
step failed before any test ran on every PR opened since. The wait step polls
port 5000, which is why that is the port.

Verified: `npm ci` on the new lockfile (one copy of each package), `npm audit
--production` clean, tsc and prettier clean, mocked suite 629 passed with only
the environmental `printVersion` failure that also fails on main in this
environment. The spec that pins the file name fails when the path argument is
reverted, and asserts the diagnostic's shape rather than the library's wording.

Co-authored-by: [email protected] <[email protected]>
allanbowe pushed a commit to sasjs/core that referenced this pull request Oct 27, 2026
## What

`.sasjslint` promotes the two doxygen-header rules to `error`:

```json
"severityLevel": {
  "hasDoxygenHeader": "error",
  "noNestedCommentsInHeader": "error"
}
```

## Why

Both rules already report on this corpus; at their default severity they
report and nothing else. Promoted, a truncated header stops at the
commit rather than surviving to a build - which is what `sasjs/utils`
4.1.1 now catches at compile time and what the lint reports at author
time, released in `@sasjs/lint` 4.4.0 (sasjs/lint#265).

`hasDoxygenHeader` at `error` also makes its new check fatal: a header
closed with a single asterisk. SAS ends a block comment at the first
`*/`, so everything a `*/`-closed header appears to enclose is parsed as
code.

## Measurement, not assumption

Ran `@sasjs/lint` 4.4.0 over every folder in `sasjs/sasjsconfig.json`
(base, ddl, fcmp, lua, meta, metax, server, viya, xplatform, tests/*)
with the current config and with both rules at `error`: 232 findings
either way, all from other rules (line endings, indentation, undeclared
macros), none from these two. So this changes no macro and cannot redden
CI on today's corpus.

The severity override was validated separately - setting `lineEndings:
error` flips 78 findings from warning to error, so the override path is
live and the zero above is a real zero.

`sasjs lint` (CLI 6.2.4) against the project exits with warnings only,
and none of them are header findings.

## Also

`AGENTS.md` gains the header-shape line, so the rules a contributor
reads match what the lint enforces.

Co-authored-by: sasjs-dev[bot] <sasjs-dev[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant