Skip to content

feat(eslint-factory): add Object.assign suggestion to no-throw-plain-object rule#45299

Merged
pelikhan merged 5 commits into
mainfrom
copilot/fix-eslint-no-throw-plain-object-suggestions
Jul 14, 2026
Merged

feat(eslint-factory): add Object.assign suggestion to no-throw-plain-object rule#45299
pelikhan merged 5 commits into
mainfrom
copilot/fix-eslint-no-throw-plain-object-suggestions

Conversation

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

no-throw-plain-object correctly flags throw { ... } but provided no fixer, leaving 22 production sites (JSON-RPC error objects in mcp_server_core.cjs and safe_outputs_handlers.cjs) with manual remediation only.

Changes

  • no-throw-plain-object.ts — adds hasSuggestions: true and a manual suggestion (not auto-fix) that rewrites plain object throws to Error-compatible forms:

    // throw { code: -32602, message: "Invalid params", data: { field: "name" } }
    // →
    throw Object.assign(new Error("Invalid params"), { code: -32602, data: { field: "name" } });
    
    // throw { message: "not found" }  →  throw new Error("not found")
    // throw {}                        →  throw new Error()
    // throw { code: -32602 }          →  throw Object.assign(new Error(), { code: -32602 })

    Suggestion is skipped (report-only) for objects with computed keys, spread elements, methods, or getters/setters to avoid emitting syntactically invalid rewrites.

  • no-throw-plain-object.test.ts — updates all existing invalid cases with suggestions assertions; adds new cases covering: without-message, JSON-RPC { code, message, data } shape, computed-key skip, spread skip.

A suggestion rather than auto-fix is intentional: catch/serialize sites may JSON.stringify the thrown value, where the non-enumerable Error.message would be dropped — a human should confirm the catch side per call site.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Hey @app/copilot-swe-agent 👋 — great work tackling the no-throw-plain-object ESLint rule improvement!

This PR is in early WIP stages with no diff yet. Once the implementation lands, these will be important:

  • Add unit tests — the issue specifies several test cases: with-message, without-message, empty-object (throw {}), message-only, data-bearing JSON-RPC object, computed-key skip, and spread skip. These all need coverage.
  • Verify hasSuggestions: true is set in the rule metadata.
  • Check suggestion correctness against the live corpus sites in mcp_server_core.cjs and safe_outputs_handlers.cjs.

If you would like a hand, you can assign this prompt to your coding agent:

In eslint-factory/src/rules/no-throw-plain-object.ts:
1. Set meta.hasSuggestions: true.
2. Add a suggestion (not autofix) that rewrites `throw { message: x, ...rest }` → `throw Object.assign(new Error(x), { ...rest })`, handling: with-message, no-message, empty-object, message-only cases.
3. Skip the suggestion for computed keys, spread elements, or non-Literal message values.
4. Add unit tests covering all 7 cases described in the issue.
5. Verify the suggestion produces valid rewrites for the JSON-RPC shape in mcp_server_core.cjs.

Generated by ✅ Contribution Check · 93.5 AIC · ⌖ 10.7 AIC · ⊞ 6.2K ·

…object rule

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix eslint-factory rule to provide suggestion for no-throw-plain-object feat(eslint-factory): add Object.assign suggestion to no-throw-plain-object rule Jul 13, 2026
Copilot AI requested a review from pelikhan July 13, 2026 17:52
@github-actions

Copy link
Copy Markdown
Contributor

PR Triage (run 29275650494)\n\nCategory: feature | Risk: medium | Score: 58/100 | Action: fast_track\n\nScore: Impact 28/50 + Urgency 15/30 + Quality 15/20\n\nAdds Object.assign suggestion to no-throw-plain-object ESLint rule - addresses 22 production sites. Small change (3 files, +210/-10). DRAFT - undraft when ready.

Generated by 🔧 PR Triage Agent · 181.5 AIC · ⌖ 7.71 AIC · ⊞ 5.6K ·

@pelikhan pelikhan marked this pull request as ready for review July 13, 2026 21:22
Copilot AI review requested due to automatic review settings July 13, 2026 21:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds an ESLint suggestion (not an auto-fix) to help remediate throw { ... } sites flagged by no-throw-plain-object, and updates rule tests accordingly. The PR also includes unrelated changes to a generated workflow lock file that should be explicitly called out in the PR scope/description.

Changes:

  • Add meta.hasSuggestions and a suggestion that rewrites throw { ... } into new Error(...) / Object.assign(new Error(...), { ... }) when safe.
  • Update rule tests to assert suggestion outputs and add skip-coverage for unsafe object-literal shapes.
  • Update smoke-call-workflow.lock.yml (safe-outputs tool schema + caller permissions/secrets for a reusable workflow call).
Show a summary per file
File Description
eslint-factory/src/rules/no-throw-plain-object.ts Adds a suggestion fixer path to rewrite plain-object throws into Error-compatible throws when the object literal is safe to transform.
eslint-factory/src/rules/no-throw-plain-object.test.ts Adds/updates invalid cases to assert the new suggestion outputs and skip behavior.
.github/workflows/smoke-call-workflow.lock.yml Updates generated safe-outputs tool schema and reusable-workflow call wiring (inputs/permissions/secrets).

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Low

Comment thread eslint-factory/src/rules/no-throw-plain-object.ts
Comment thread eslint-factory/src/rules/no-throw-plain-object.test.ts Outdated
Comment on lines +1106 to +1124
@@ -1102,15 +1107,25 @@ jobs:
needs: safe_outputs
if: needs.safe_outputs.outputs.call_workflow_name == 'smoke-workflow-call'
# Imported from called workflow "smoke-workflow-call" because GitHub requires the caller job to grant permissions requested by reusable workflow jobs.
# Review the called workflow's frontmatter permissions in ./.github/workflows/smoke-workflow-call.md.
# Review the called workflow's job-level permissions in ./.github/workflows/smoke-workflow-call.lock.yml.
permissions:
actions: read
contents: read
pull-requests: read
issues: write
pull-requests: write
uses: ./.github/workflows/smoke-workflow-call.lock.yml
with:
aw_context: ${{ fromJSON(needs.safe_outputs.outputs.call_workflow_payload).aw_context }}
payload: ${{ needs.safe_outputs.outputs.call_workflow_payload }}
task-description: ${{ fromJSON(needs.safe_outputs.outputs.call_workflow_payload)['task-description'] }}
secrets: inherit
secrets:
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}
GH_AW_GITHUB_MCP_SERVER_TOKEN: ${{ secrets.GH_AW_GITHUB_MCP_SERVER_TOKEN }}
GH_AW_GITHUB_TOKEN: ${{ secrets.GH_AW_GITHUB_TOKEN }}
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

pr-sous-chef
@copilot please run the pr-finisher skill, address any remaining review feedback, and rerun checks once the branch is up to date.

Run: https://github.com/github/gh-aw/actions/runs/29286484887

Generated by 👨‍🍳 PR Sous Chef · 9.66 AIC · ⌖ 6.15 AIC · ⊞ 5.1K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

pr-sous-chef
@copilot please run the pr-finisher skill, address any remaining review feedback, and rerun checks once the branch is up to date.
...

Addressed remaining in-scope feedback in d33042c:

  • Added suggest: [] on unsafe-object reports in no-throw-plain-object.
  • Fixed the duplicated-word test title typo.

Re-ran local checks (make fmt, make lint, make test-unit, make test, make recompile) and make agent-report-progress passed.

I also reviewed the referenced workflow run; it completed successfully with no failed jobs.

Copilot AI requested a review from gh-aw-bot July 13, 2026 21:58
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

pr-sous-chef
@copilot please run the pr-finisher skill, address this remaining unresolved review comment, and rerun checks once the branch is up to date:

Run: https://github.com/github/gh-aw/actions/runs/29289965782

Generated by 👨‍🍳 PR Sous Chef · 10.9 AIC · ⌖ 3.94 AIC · ⊞ 7.5K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

pr-sous-chef
@copilot please run the pr-finisher skill, address this remaining unresolved review comment, and rerun checks once the branch is up to date:

  • copilot-pull-request-reviewer: https://g...

Addressed the remaining unresolved review feedback in 520a438 by removing the unrelated .github/workflows/smoke-call-workflow.lock.yml changes so this PR is ESLint-scoped only.

Re-ran checks locally after the update: make fmt, make lint, make test-unit, make test, and make recompile all passed (and make agent-report-progress passed before pushing).

Note: CI on this new head won’t auto-rerun from an agent push; a maintainer will need to re-trigger workflows.

@pelikhan pelikhan merged commit d0a8a71 into main Jul 14, 2026
6 checks passed
@pelikhan pelikhan deleted the copilot/fix-eslint-no-throw-plain-object-suggestions branch July 14, 2026 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eslint-factory: no-throw-plain-object should offer an Object.assign(new Error(...)) suggestion

4 participants