Skip to content

[eslint-miner] eslint-factory: add require-error-code-for-fetch-throw rule #63813

Description

@github-actions

Tip

Your pull request is ready to create! 🎉 ✅

Everything is OK—the changes have been pushed to a branch. Please review the protected files, then create the pull request when you are ready.

Create the pull request

The original pull request description is below.


Summary

Adds a new custom ESLint rule, require-error-code-for-fetch-throw, that flags throw new Error(...) following a bare fetch(...) call when the throw doesn't include a standardized error code (E###, ERR_*, SAFE_OUTPUT_E###) — even in files that have never imported error_codes.cjs.

Evidence

Two existing rules (require-error-code-in-thrown-error and require-error-code-for-github-api-throw) both gate on the file already importing ./error_codes.cjs — they never fire for files that haven't adopted the convention at all. This is a real, recurring gap:

Implementation

  • New rule: eslint-factory/src/rules/require-error-code-for-fetch-throw.ts
    • Modeled on the existing require-error-code-for-github-api-throw rule's architecture: map bare fetch(...) call positions per enclosing function, then flag same-function throw new Error(...) statements lacking a code.
    • Detects only bare fetch(...) identifier calls (deliberately excludes member-expression calls like octokit.request(...) or transport.fetch(...), which are covered by the sibling GitHub-API rule or are wrapper abstractions) to avoid overlap/false positives.
    • Does not gate on error_codes.cjs being imported — that's the entire point of the rule: catching files that haven't adopted the convention yet.
    • Reuses the shared ERROR_CODE_PATTERN and resolveWriteOnceInitializerChain helpers for consistency with the sibling rule.
  • Tests: eslint-factory/src/rules/require-error-code-for-fetch-throw.test.ts (6 cases): valid with error-code-suffixed message, valid with inline string-literal code, invalid throw after bare fetch with no code, valid throw with no preceding fetch, valid throw before the fetch call, valid member-expression fetch call not flagged, valid unrelated sibling-function fetch call not flagged.
  • Registered in eslint-factory/src/index.ts and enabled ("warn") in eslint-factory/eslint.config.cjs for the actions/setup/js lint target.
  • Documented in eslint-factory/README.md (TOC entry + detail section with flagged/safe examples).

Validation

  • cd eslint-factory && npm install — succeeds.
  • npm run build — passes, no type errors.
  • npm test — 687/687 tests pass (67 files), including the README/rule-registry parity check.
  • npm run lint:setup-js — exits 0 (all warnings, no errors); the new rule fires 22 times across exactly 3 real files (azure_devops_work_items.cjs, artifact_client.cjs, exchange_otlp_workload_identity.cjs), confirming it's high-signal and not noisy or duplicative of the two existing error-code rules.

Scope

Changes limited to eslint-factory/** (new rule + tests + registration + docs). No changes to actions/setup/js/** source files, Go code, or documentation outside eslint-factory.


Note

Protected files

This patch modifies protected files, which may affect project dependencies, CI/CD pipelines, or agent behaviour.

Protected files
  • README.md

To route changes like this to a review issue instead of blocking, configure protected-files: fallback-to-issue in your workflow configuration.

Generated by ESLint Miner · copilot · auto · 147.5 AIC · ⌖ 12.7 AIC · ⊞ 6.7K · ◷

  • expires on Oct 4, 2026, 1:01 AM UTC-08:00

Activity

  1. github-actions commented on Oct 4, 2026

    @github-actions
    ContributorAuthor

    This issue was automatically closed because it expired on 2026-10-04T09:01:15.935Z.

    Closed by Workflow

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions