Skip to content

fix: prevent doctest false-positive on function declarations; remove stale ESLint disable#11928

Draft
Planeshifter wants to merge 2 commits intodevelopfrom
philipp/ci-fix-lint-constructor-name-2026-05-04
Draft

fix: prevent doctest false-positive on function declarations; remove stale ESLint disable#11928
Planeshifter wants to merge 2 commits intodevelopfrom
philipp/ci-fix-lint-constructor-name-2026-05-04

Conversation

@Planeshifter
Copy link
Copy Markdown
Member

@Planeshifter Planeshifter commented May 4, 2026

Summary

Fixes two persistent CI lint failures related to @stdlib/utils/constructor-name examples.

Root cause (doctest false-positive): The RE_ANNOTATION regex in @stdlib/_tools/eslint/rules/doctest used [^;]* which could span across a function noop() { // Do nothing... } declaration (no semicolon in body). The regex then greedily matched the first console.log(...);\n// => annotation, capturing function as group 1. Since scope['function'] is undefined, the rule incorrectly reported a value mismatch for every annotated expression in the file.

Fix (Change 1): Add (?!function\b) negative lookahead after (?:var|let|const)? ? in RE_ANNOTATION. This prevents the regex from starting a match at a bare function keyword while leaving identifiers that merely begin with function (e.g. functionName) unaffected — \b requires a word boundary that is absent when the next character is a word character.

Root cause (stale directive): // eslint-disable-line no-buffer-constructor on the new Buffer(...) line was permanently unused because no-buffer-constructor is not configured anywhere in stdlib's ESLint setup. Unused disable directives trigger their own lint warning.

Fix (Change 2): Remove the stale // eslint-disable-line no-buffer-constructor from utils/constructor-name/examples/index.js.

Files changed

  • lib/node_modules/@stdlib/_tools/eslint/rules/doctest/lib/main.js — add (?!function\b) lookahead to RE_ANNOTATION
  • lib/node_modules/@stdlib/utils/constructor-name/examples/index.js — remove stale no-buffer-constructor disable directive

Test plan

  • Run ESLint on utils/constructor-name/examples/index.js — verify stdlib/doctest no longer fires
  • Run ESLint on utils/constructor-name/examples/index.js — verify no no-useless-disable warning
  • Verify existing doctest rule fixtures still pass (lib/node_modules/@stdlib/_tools/eslint/rules/doctest/test/)
  • Verify CI lint workflow passes on this branch

…ve stale ESLint disable directive

The `RE_ANNOTATION` regex in the doctest rule used `[^;]*` which could span
across `function noop() { // Do nothing... }` (no semicolon in body), then
greedily match the first `console.log(...);\n// =>` annotation, capturing
`function` as group 1. Since `scope['function']` is `undefined`, the rule
incorrectly reported a mismatch for every annotation in the file.

Adding `(?!function\b)` negative lookahead prevents the regex from starting
a match at a bare `function` keyword. Identifiers that merely begin with
`function` (e.g. `functionName`) are not affected because `\b` requires a
word boundary.

Also removes the stale `// eslint-disable-line no-buffer-constructor` in
`utils/constructor-name/examples/index.js` — the rule is not configured in
stdlib's ESLint setup and the directive triggers an unknown-rule warning.
@stdlib-bot
Copy link
Copy Markdown
Contributor

stdlib-bot commented May 4, 2026

Coverage Report

Package Statements Branches Functions Lines
utils/constructor-name $\color{green}126/126$
$\color{green}+100.00%$
$\color{green}12/12$
$\color{green}+100.00%$
$\color{green}1/1$
$\color{green}+100.00%$
$\color{green}126/126$
$\color{green}+100.00%$

The above coverage report was generated for the changes in this PR.

Forward slashes inside the regex literal must be escaped as \/ to avoid
prematurely terminating the regex delimiter. The prior push omitted the
backslashes, producing a syntax error that broke module loading.
@stdlib-js stdlib-js deleted a comment from stdlib-bot May 4, 2026
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.

2 participants