fix: stop doctest regex overrun in constructor-name example#11906
Draft
Planeshifter wants to merge 1 commit intodevelopfrom
Draft
fix: stop doctest regex overrun in constructor-name example#11906Planeshifter wants to merge 1 commit intodevelopfrom
Planeshifter wants to merge 1 commit intodevelopfrom
Conversation
The CI JavaScript lint job on develop has been failing since 2026-05-01
with two errors in utils/constructor-name/examples/index.js:
39:1 error Displayed return value is `'String'`, but expected
`undefined` instead stdlib/doctest
151:57 error Unused eslint-disable directive (no problems were
reported from 'no-buffer-constructor')
Error 1: The stdlib/doctest rule's RE_ANNOTATION regex contains a
greedy [^;]* segment that matches newlines. Starting at `\nfunction
noop() {`, the regex spans across the comment-only body (no `;`) to
`console.log( constructorName( 'a' ) );`, falsely associating
`// => 'String'` with the function expression, which evaluates to
`undefined` in the VM sandbox. Adding `return void 0;` inside noop()
places a semicolon in the body, causing the greedy match to terminate
there. The following `\n}` does not match `\n//`, so the false
association attempt fails and the regex correctly matches the
console.log call on the next attempt.
Error 2: `no-buffer-constructor` is not configured in any of the
project's ESLint rule files; the inline disable directive was stale.
Failing run: https://github.com/stdlib-js/stdlib/actions/runs/25195861572
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
Member
|
@Planeshifter Seems like we need to make a more general fix here and not paper over by updating the example. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Failing run: https://github.com/stdlib-js/stdlib/actions/runs/25195861572 (issue #11867, 2026-05-01)
Symptom:
Root cause:
Error 1 (
stdlib/doctest): The rule'sRE_ANNOTATIONregex contains a greedy[^;]*segment that matches newlines. Before the fix,noop()had a comment-only body with no semicolons. The regex anchored at\nfunction noop() {, its[^;]*;segment spanned across the function body and the trailing blank line, terminating at the;ofconsole.log( constructorName( 'a' ) );. The subsequent\n//token then matched\n// => 'String', so the rule fed the combined span to its VM sandbox as a single expression. A function declaration evaluates toundefined, not'String', producing the observed mismatch.Error 2 (unused
eslint-disable):no-buffer-constructoris absent from all project ESLint rule files (etc/eslint/rules/). The inline disable directive on theBufferline was stale.Fix:
Two minimal edits to
lib/node_modules/@stdlib/utils/constructor-name/examples/index.js:Add
return void 0;insidenoop(). This places a;inside the function body. The greedy[^;]*now terminates atreturn void 0;; the following\n}does not match\n//, so the false-association attempt fails and the regex advances correctly toconsole.log( constructorName( 'a' ) );.Remove
// eslint-disable-line no-buffer-constructorfrom thenew Buffer(...)line. The rule is inactive; the directive serves no purpose.Neither change affects runtime behavior.
noopis passed toconstructorName(noop)only to demonstrate a'Function'result; its return value is never used. The test suite defines its own independentnoopand is unaffected.Validation:
RE_ESLINT_INLINEstrips theeslint-disable-linecomment beforeRE_ANNOTATIONruns, leavingreturn;→ the;survives and terminates the match inside the function body. (Note: cycle 1 proposedreturn;with a disable comment; cycle 2 revised toreturn void 0;—no-useless-returnonly flags barereturn;, notreturn expr;, so no suppression directive is needed.)no-voidis set to'off'inetc/eslint/rules/best_practices.js(line 1418);void 0is permitted.no-buffer-constructorabsent from alletc/eslint/rules/files.return;+ disable comment idiom objected to. Cycle 2: all three reviewers approved.Reviewer notes:
require('@stdlib/utils/noop')rather than a local declaration withreturn void 0;. This is non-blocking: the current fix is correct and minimal. A maintainer may choose to apply the idiomatic refactor separately.// eslint-disable-line no-buffer-constructordirectives exist elsewhere in the repo (e.g.,buffer/from-buffer,buffer/from-array). Those are out of scope for this PR but may warrant a follow-up sweep.Related: issue #11867 (cluster 1 of that issue —
symbol/async-iterator— is addressed separately in draft PR #11905)Contributing Guidelines
Generated by Claude Code