Skip to content

Guard getErrorMessage suggestions by binding - #54343

Merged
pelikhan merged 2 commits into
mainfrom
copilot/fix-eslint-factory-prefer-get-error-message
Aug 20, 2026
Merged

Guard getErrorMessage suggestions by binding#54343
pelikhan merged 2 commits into
mainfrom
copilot/fix-eslint-factory-prefer-get-error-message

Conversation

Copilot AI commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

prefer-get-error-message could suggest getErrorMessage(err) where the helper was unavailable. Its sibling rule already avoids this through scope-aware binding resolution.

  • Rule behavior

    • Port the sibling rule’s resolvability check.
    • Report only when getErrorMessage is imported, function-declared, or otherwise defined before the matched ternary.
  • Coverage

    • Add a no-binding case that produces no report.
    • Retain suggestion coverage for prior CommonJS and ESM bindings.
const { getErrorMessage } = require("./error_helpers.cjs");
const message = err instanceof Error ? err.message : String(err);
// suggestion: getErrorMessage(err)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix prefer-get-error-message rule to include resolvability check Guard getErrorMessage suggestions by binding Aug 20, 2026
Copilot AI requested a review from pelikhan August 20, 2026 20:30
@pelikhan
pelikhan marked this pull request as ready for review August 20, 2026 20:52
Copilot AI balanced review requested due to automatic review settings August 20, 2026 20:52
@pelikhan
pelikhan merged commit 6a72c98 into main Aug 20, 2026
@pelikhan
pelikhan deleted the copilot/fix-eslint-factory-prefer-get-error-message branch August 20, 2026 20:52

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 binding-aware safeguards to prevent unsafe getErrorMessage suggestions.

Changes:

  • Checks whether getErrorMessage is available before reporting.
  • Adds negative and positive binding tests.
Show a summary per file
File Description
prefer-get-error-message.ts Adds scope-aware binding resolution.
prefer-get-error-message.test.ts Covers missing, CommonJS, and ESM bindings.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines +40 to +45
const variable = scope.set.get(name);
if (variable && variable.defs.some(def => isDefinitionAvailableAtNode(def, node))) {
return true;
}
scope = scope.upper;
}
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.87.2

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eslint-factory: prefer-get-error-message lacks getErrorMessage resolvability check (sibling rule already has it)

3 participants