Skip to content

build: migrate custom ESLint rules to modern APIs (gh54 part I)#10950

Merged
kgryte merged 5 commits intodevelopfrom
philipp/gh54-modernize-custom-rule-apis
Mar 22, 2026
Merged

build: migrate custom ESLint rules to modern APIs (gh54 part I)#10950
kgryte merged 5 commits intodevelopfrom
philipp/gh54-modernize-custom-rule-apis

Conversation

@Planeshifter
Copy link
Copy Markdown
Member

@Planeshifter Planeshifter commented Mar 15, 2026

Progresses stdlib-js/metr-issue-tracker#54.

Description

What is the purpose of this pull request?

This pull request:

  • Replaces deprecated ESLint rule APIs with their modern equivalents to prepare for the ESLint v9 migration
  • Migrates context.getSourceCode()context.sourceCode across 100 rule files and 1 utility example (deprecated in ESLint v8.40.0).
  • Migrates context.getScope()sourceCode.getScope(node) in 4 rules (no-builtin-big-int, no-redeclare, capitalized-comments, require-globals) (deprecated in ESLint v8.38.0).

To ensure passing tests and linting (all issues below were verified to be present before the changes of this PR)

  • Moves pure helper functions (copyLocationInfo, locationInfo, checkComment, extractPackagePath, getAlias, sortExpressions) from nested closures to module scope.
  • Replaces String.prototype.toUpperCase/toLowerCase/trim with @stdlib/string/base/* equivalents.
  • Fixes variable declaration ordering (stdlib/vars-order).
  • Audits and confirms all 35 rules with context.options already define meta.schema.
  • Confirms no usage of other deprecated APIs (context.getAncestors, context.getDeclaredVariables, context.markVariableAsUsed, deprecated comment/token access patterns).
  • Fixes 9 pre-existing test failures across custom ESLint rules so all 123 rule tests pass cleanly on ESLint v8:
    • doctest-marker: replaces acorn-walk with ESLint sourceCode APIs to avoid deprecated node.start/node.end access
    • jsdoc-require-throws-tags: replaces node.start/node.end with node.range[0]/node.range[1]
    • jsdoc-no-space-aligned-asterisks: fixes autofix regex that incorrectly turned trailing whitespace into asterisks
    • Test fixture fixes for no-redeclare, namespace-index-order, require-last-path-relative, jsdoc-ordered-list-marker-value, jsdoc-doctest-marker, doctest-marker, and jsdoc-no-blockquote-without-marker

To confirm that all tests pass:

npx tape 'lib/node_modules/@stdlib/_tools/eslint/rules/*/test/test.js'

(the make recipes cause trouble with _tools, I think)

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

References:

For no-builtin-big-int, the scope acquisition was moved from the create function (which previously captured the global scope once) into the CallExpression visitor, and isImportedBigInt was updated to walk up the scope chain to find BigInt declarations in outer scopes.

For doctest-marker, acorn-walk.findNodeAt was replaced with sourceCode.getTokenBefore + sourceCode.getNodeByRangeIndex + a findStatement helper to walk up to the nearest statement ancestor, plus a line-proximity check for orphaned annotation detection.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

Implementation plan was written in tandem with Claude Code and ChatGPT under my review and refinement.
This PR was written primarily by Claude Code. The mechanical API replacements were applied via scripted bulk edits, and the scope-related changes and test fixes were authored with manual review.


@stdlib-js/reviewers

@stdlib-bot stdlib-bot added the Tools Issue or pull request related to project tooling. label Mar 15, 2026
Replace deprecated ESLint rule APIs with their modern equivalents
to prepare for the ESLint v9 migration (see [1][2]):

- `context.getSourceCode()` → `context.sourceCode` (100 files)
- `context.getScope()` → `sourceCode.getScope(node)` (4 files)

The `context.getSourceCode()` method was deprecated in ESLint v8.40.0
in favor of the `context.sourceCode` property. The `context.getScope()`
method was deprecated in ESLint v8.38.0 in favor of
`sourceCode.getScope(node)`, which takes an explicit node argument
rather than relying on implicit traversal state.

For `no-builtin-big-int`, the scope acquisition was moved from the
`create` function (which previously captured the global scope once)
into the `CallExpression` visitor, and `isImportedBigInt` was updated
to walk up the scope chain to find `BigInt` declarations in outer
scopes.

Also fixes pre-existing lint violations in touched files:
- Move `copyLocationInfo`, `locationInfo`, `checkComment`,
  `extractPackagePath`, `getAlias`, and `sortExpressions` from nested
  functions to module scope
- Replace `.toUpperCase()`, `.toLowerCase()`, `.trim()` with stdlib
  equivalents
- Fix variable declaration ordering

No other deprecated APIs (`context.getAncestors`,
`context.getDeclaredVariables`, `context.markVariableAsUsed`,
deprecated comment/token access patterns) were found in the codebase.
All rules with `context.options` already have proper `meta.schema`.

[1]: https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/
[2]: https://eslint.org/docs/latest/use/migrate-to-9.0.0

Ref: stdlib-js/metr-issue-tracker#54

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@Planeshifter Planeshifter force-pushed the philipp/gh54-modernize-custom-rule-apis branch from 56f2f39 to 485bf9b Compare March 15, 2026 05:06
@stdlib-js stdlib-js deleted a comment from stdlib-bot Mar 15, 2026
@Planeshifter Planeshifter changed the title refactor: migrate custom ESLint rules to modern APIs bench: migrate custom ESLint rules to modern APIs Mar 15, 2026
Fix 9 pre-existing test failures across custom ESLint rules to ensure
all 123 rule tests pass cleanly on ESLint v8:

Rule fixes:
- `doctest-marker`: replace `acorn-walk` with ESLint `sourceCode` APIs
  (`getTokenBefore`, `getNodeByRangeIndex`) to avoid deprecated
  `node.start`/`node.end` property access; add line-proximity check
  for orphaned annotation detection
- `jsdoc-require-throws-tags`: replace `node.start`/`node.end` with
  `node.range[0]`/`node.range[1]`
- `jsdoc-no-space-aligned-asterisks`: fix autofix regex replacement
  that incorrectly turned trailing whitespace into asterisks (use
  `$1` back-reference instead of literal `*`)

Test fixture fixes:
- `no-redeclare`: add `ecmaVersion: 2015` for `sourceType: 'module'`
  test case
- `namespace-index-order`: reorder fixture entries to match
  alphabetical package path order
- `require-last-path-relative`: match error message backtick quoting
- `jsdoc-ordered-list-marker-value`: expect 4 errors (not 3) for
  newer `remark-lint-ordered-list-marker-value`
- `jsdoc-doctest-marker`: remove undefined `stdlib/require-globals`
  from `eslint-disable-line` comments
- `doctest-marker`: remove undefined `stdlib/no-builtin-math` from
  `eslint-disable-line` comments
- `jsdoc-no-blockquote-without-marker`: use lazy continuation
  pattern and update error message for `remark-lint` v2

Ref: stdlib-js/metr-issue-tracker#54

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@Planeshifter Planeshifter changed the title bench: migrate custom ESLint rules to modern APIs build: migrate custom ESLint rules to modern APIs Mar 15, 2026
@Planeshifter Planeshifter changed the title build: migrate custom ESLint rules to modern APIs build: migrate custom ESLint rules to modern APIs (gh54 part I) Mar 15, 2026
@Planeshifter Planeshifter added the METR Pull request associated with the METR project. label Mar 18, 2026
Comment thread lib/node_modules/@stdlib/_tools/eslint/rules/doctest-marker/lib/main.js Outdated
Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>
@Planeshifter Planeshifter marked this pull request as ready for review March 19, 2026 04:29
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Mar 19, 2026
@Planeshifter Planeshifter requested a review from kgryte March 19, 2026 04:30
@kgryte
Copy link
Copy Markdown
Member

kgryte commented Mar 22, 2026

/stdlib merge

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label Mar 22, 2026
@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label Mar 22, 2026
@kgryte
Copy link
Copy Markdown
Member

kgryte commented Mar 22, 2026

the make recipes cause trouble with _tools, I think

This is incorrect. You need to run make tools-test.

@github-actions github-actions Bot mentioned this pull request Mar 22, 2026
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@kgryte kgryte removed the Needs Review A pull request which needs code review. label Mar 22, 2026
Copy link
Copy Markdown
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

LGTM

@kgryte
Copy link
Copy Markdown
Member

kgryte commented Mar 22, 2026

For METR,

review_time: 45 mins

@kgryte
Copy link
Copy Markdown
Member

kgryte commented Mar 22, 2026

This is incorrect. You need to run make tools-test.

And because I know you'll ask "why do we have a separate make command for running tests in the tools directory?"...

Three reasons: 1) Historical reasons stemming from when JavaScript tools packages were not in lib/node_modules. 2) It was not migrated to make test because "tools" have different test requirements from normal package tests (e.g., Node.js version support). 3) Tools are not subject to the same test coverage requirements as end-user packages, so we did not want them being counted against the total project coverage. make test only corresponds to end-user packages.

@kgryte
Copy link
Copy Markdown
Member

kgryte commented Mar 22, 2026

cc @batpigandme For the rationale for having a separate test command for running tools tests. Reasons (2) and (3) are the primary things we could considering adding to docs somewhere.

@kgryte kgryte merged commit 2731872 into develop Mar 22, 2026
11 checks passed
@kgryte kgryte deleted the philipp/gh54-modernize-custom-rule-apis branch March 22, 2026 06:59
@kgryte kgryte restored the philipp/gh54-modernize-custom-rule-apis branch March 22, 2026 07:01
@batpigandme
Copy link
Copy Markdown
Member

cc @batpigandme For the rationale for having a separate test command for running tools tests. Reasons (2) and (3) are the primary things we could considering adding to docs somewhere.

Will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

METR Pull request associated with the METR project. Tools Issue or pull request related to project tooling.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants