Skip to content

feat: add jsdoc-example-eslint ESLint rule#11101

Draft
Planeshifter wants to merge 1 commit intodevelopfrom
philipp/jsdoc-example-eslint
Draft

feat: add jsdoc-example-eslint ESLint rule#11101
Planeshifter wants to merge 1 commit intodevelopfrom
philipp/jsdoc-example-eslint

Conversation

@Planeshifter
Copy link
Member

@Planeshifter Planeshifter commented Mar 23, 2026

Resolves stdlib-js/metr-issue-tracker#57.

Description

What is the purpose of this pull request?

This pull request:

  • Adds a new custom ESLint rule jsdoc-example-eslint that extracts JavaScript code from JSDoc @example blocks and lints it using ESLint's synchronous Linter API
  • Configures the rule in .eslintrc.overrides.js using the existing examples ESLint config, keeping JSDoc example linting rules in sync with standalone example file linting
  • Adds --external eslint to the Browserify build for the ESLint plugin to avoid bundling ESLint inside itself

Related Issues

Does this pull request have any 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.

The rule is a pure mechanism: it accepts a rules object and lints example code with those rules, reporting violations mapped back to the correct source file lines. It has no built-in opinions about which rules to apply.

The rule is configured in .eslintrc.overrides.js (rather than stdlib.js) to avoid a circular dependency: stdlib.js.eslintrc.examples.js.eslintrc.jsrules/index.jsstdlib.js. The overrides file loads after the base config resolves, so it can safely require the examples config.

Rules from the examples config are filtered to exclude plugin rules (which the internal Linter instance doesn't have registered) and rules incompatible with code snippets (no-undef, no-unused-vars, strict, no-var, eol-last, indent, no-restricted-syntax).

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

This PR was written primarily by Claude Code following my instructions.


@stdlib-js/reviewers

@socket-security
Copy link

socket-security bot commented Mar 23, 2026

No dependency changes detected. Learn more about Socket for GitHub.

👍 No dependency changes detected in pull request

@Planeshifter Planeshifter force-pushed the philipp/jsdoc-example-eslint branch 2 times, most recently from 8fce0dc to 33e0f6e Compare March 23, 2026 05:46
@Planeshifter Planeshifter added Feature Issue or pull request for adding a new feature. METR Pull request associated with the METR project. labels Mar 23, 2026
Add a new custom ESLint rule that extracts JavaScript code from
JSDoc `@example` blocks and lints it using ESLint's synchronous
`Linter` API. The rule is a pure mechanism: it accepts a `rules`
object and lints example code with those rules, reporting violations
mapped back to the correct source file lines.

The rule is configured in `.eslintrc.overrides.js`, where the
examples ESLint config is loaded (avoiding a circular dependency
with `stdlib.js`), filtered to exclude plugin rules and rules
incompatible with code snippets, and passed to the rule.

---
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: passed
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - 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 force-pushed the philipp/jsdoc-example-eslint branch from 33e0f6e to 9dbe8eb Compare March 23, 2026 06:03
@github-actions github-actions bot mentioned this pull request Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Issue or pull request for adding a new feature. METR Pull request associated with the METR project.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC]: Setup ESLint linting in JSDoc examples

1 participant