fix: prevent doctest false-positive on function declarations; remove stale ESLint disable#11928
Draft
Planeshifter wants to merge 2 commits intodevelopfrom
Draft
fix: prevent doctest false-positive on function declarations; remove stale ESLint disable#11928Planeshifter wants to merge 2 commits intodevelopfrom
Planeshifter wants to merge 2 commits intodevelopfrom
Conversation
…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.
Contributor
Coverage Report
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.
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.
Summary
Fixes two persistent CI lint failures related to
@stdlib/utils/constructor-nameexamples.Root cause (doctest false-positive): The
RE_ANNOTATIONregex in@stdlib/_tools/eslint/rules/doctestused[^;]*which could span across afunction noop() { // Do nothing... }declaration (no semicolon in body). The regex then greedily matched the firstconsole.log(...);\n// =>annotation, capturingfunctionas group 1. Sincescope['function']isundefined, 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)? ?inRE_ANNOTATION. This prevents the regex from starting a match at a barefunctionkeyword while leaving identifiers that merely begin withfunction(e.g.functionName) unaffected —\brequires a word boundary that is absent when the next character is a word character.Root cause (stale directive):
// eslint-disable-line no-buffer-constructoron thenew Buffer(...)line was permanently unused becauseno-buffer-constructoris 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-constructorfromutils/constructor-name/examples/index.js.Files changed
lib/node_modules/@stdlib/_tools/eslint/rules/doctest/lib/main.js— add(?!function\b)lookahead toRE_ANNOTATIONlib/node_modules/@stdlib/utils/constructor-name/examples/index.js— remove staleno-buffer-constructordisable directiveTest plan
utils/constructor-name/examples/index.js— verifystdlib/doctestno longer firesutils/constructor-name/examples/index.js— verify nono-useless-disablewarninglib/node_modules/@stdlib/_tools/eslint/rules/doctest/test/)