Skip to content

fix(linter/no-invalid-fetch-options): false positive with member expression as method#16687

Merged
camc314 merged 6 commits intomainfrom
copilot/fix-eslint-plugin-unicorn-rule
Dec 10, 2025
Merged

fix(linter/no-invalid-fetch-options): false positive with member expression as method#16687
camc314 merged 6 commits intomainfrom
copilot/fix-eslint-plugin-unicorn-rule

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 10, 2025

  • Understand the issue: rule incorrectly reports error when method is accessed via member expression (e.g., options.method)
  • Identify root cause: StaticMemberExpression handler only handles enums, falls through for regular objects
  • Add test cases for the reported issue
  • Fix the logic to set method_name to UNKNOWN when handling non-enum StaticMemberExpression
  • Run tests to verify the fix
  • Ensure no regressions in existing tests
  • Address code review feedback to improve comment clarity
  • Add test cases for non-identifier objects in StaticMemberExpression (e.g., getOptions().method, (options).method)
Original prompt

This section details on the original issue you should resolve

<issue_title>linter: eslint-plugin-unicorn(no-invalid-fetch-options) rule missed the actual method variable</issue_title>
<issue_description>### What version of Oxlint are you using?

1.32.0

What command did you run?

pnpm oxlint --type-aware --max-warnings=0 --type-check

What does your .oxlintrc.json config file look like?

{
	"$schema": "./node_modules/oxlint/configuration_schema.json",
	// Enable TypeScript, Unicorn, and Oxc plugins
	"plugins": ["unicorn"],
	// Ignore patterns
	"ignorePatterns": ["dist", "node_modules", ".claude", "tmp", "*.log", "/nix/store/**"],
}

What happened?

{
	const method = 'POST' as const;
	await fetch(`some-url`, { method, body: '' }); // no error
}

{
	const options = {
		method: 'POST',
	} as const;

	await fetch(`some-url`, { method: options.method, body: '' }); // error happens
}
  ⚠ eslint-plugin-unicorn(no-invalid-fetch-options): "body" is not allowed when method is "GET"
    ╭─[index.ts:13:52]
 12 │
 13 │     await fetch(`some-url`, { method: options.method, body: '' });
    ·                                                       ────
 14 │ }
    ╰────
```</issue_description>

<agent_instructions>i think the soluttion here, is that if `method` is a member expression, we should default to unknown, and not report an error. That's my guess, make sure to do your own investigation</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@camc314 camc314 changed the title [WIP] Fix linter rule for actual method variable in fetch options fix(linter/no-invalid-fetch-options): false positive with member expression as method Dec 10, 2025
@github-actions github-actions bot added the A-linter Area - Linter label Dec 10, 2025
@github-actions github-actions bot added the C-bug Category - Bug label Dec 10, 2025
Copilot AI changed the title fix(linter/no-invalid-fetch-options): false positive with member expression as method Fix no-invalid-fetch-options false positive with member expressions Dec 10, 2025
Copilot AI requested a review from camc314 December 10, 2025 11:05
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Dec 10, 2025

CodSpeed Performance Report

Merging #16687 will not alter performance

Comparing copilot/fix-eslint-plugin-unicorn-rule (9b621b9) with main (2495a39)1

Summary

✅ 4 untouched
⏩ 41 skipped2

Footnotes

  1. No successful run was found on main (2b73b14) during the generation of this report, so 2495a39 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 41 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@camc314 camc314 marked this pull request as ready for review December 10, 2025 11:11
Copilot AI review requested due to automatic review settings December 10, 2025 11:11
Copilot AI requested a review from camc314 December 10, 2025 11:12
@camc314 camc314 changed the title Fix no-invalid-fetch-options false positive with member expressions fix(linter/no-invalid-fetch-options): false positive with member expression as method Dec 10, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a false positive in the no-invalid-fetch-options rule where member expressions (e.g., options.method) were incorrectly being treated as GET or HEAD methods, triggering spurious errors when body was present. The fix ensures that when the method is accessed via a member expression from a non-enum object, it is treated as unknown and no error is reported.

Key changes:

  • Added logic to set method_name to UNKNOWN when encountering non-identifier objects in StaticMemberExpression (e.g., getOptions().method)
  • Added else branch to handle non-enum identifier objects in StaticMemberExpression, setting method_name to UNKNOWN
  • Comprehensive test coverage for various member expression scenarios including regular objects, function calls, and parenthesized expressions

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

@camc314
Copy link
Copy Markdown
Contributor

camc314 commented Dec 10, 2025

@copilot run cargo clippy and fix the failures

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 10, 2025

@copilot run cargo clippy and fix the failures

Ran cargo clippy --workspace -- -D warnings - all checks pass with no warnings or errors. The code is already clippy-clean.

@camc314 camc314 force-pushed the copilot/fix-eslint-plugin-unicorn-rule branch from 97a7960 to 9b621b9 Compare December 10, 2025 11:27
@camc314 camc314 merged commit 3895d66 into main Dec 10, 2025
19 checks passed
@camc314 camc314 deleted the copilot/fix-eslint-plugin-unicorn-rule branch December 10, 2025 11:31
Copilot AI added a commit that referenced this pull request Dec 10, 2025
…ession as method (#16687)

- Fixes #16686

---------

Signed-off-by: Cameron <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: camc314 <[email protected]>
Co-authored-by: Cameron <[email protected]>
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
…ession as method (oxc-project#16687)

- Fixes oxc-project#16686

---------

Signed-off-by: Cameron <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: camc314 <[email protected]>
Co-authored-by: Cameron <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter: eslint-plugin-unicorn(no-invalid-fetch-options) rule missed the actual method variable in nested readonly object

3 participants