Skip to content

Conversation

@re-taro
Copy link
Contributor

@re-taro re-taro commented Dec 9, 2025

This PR adds unicorn/prefer-default-parameters rule, issue #684

rule doc
rule source

@re-taro re-taro requested a review from camc314 as a code owner December 9, 2025 01:54
Copilot AI review requested due to automatic review settings December 9, 2025 01:54
@github-actions github-actions bot added A-linter Area - Linter C-enhancement Category - New feature or request labels Dec 9, 2025
Copy link
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 implements the unicorn/prefer-default-parameters linter rule, which encourages using default parameter syntax instead of reassignment patterns like foo = foo || 'bar'. The rule detects cases where function parameters are reassigned using logical operators with literal values and suggests using default parameters instead.

Key Changes

  • Adds comprehensive logic to detect parameter reassignment patterns (foo = foo || 'bar' and const bar = foo || 'bar')
  • Validates that the reassignment is the first statement in the function body and the parameter is the last one
  • Includes extensive test coverage with 53 passing cases and 9 failing cases

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs Implements the complete rule logic with pattern detection, validation, and comprehensive tests
crates/oxc_linter/src/rules.rs Registers the new rule in the linter's rule registry
crates/oxc_linter/src/snapshots/unicorn_prefer_default_parameters.snap Adds snapshot test output for the rule's diagnostic messages
Comments suppressed due to low confidence (1)

crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs:1

  • The rule is inserted between prefer_bigint_literals and prefer_response_static_json, breaking the alphabetical ordering of the rules. It should be placed after prefer_date_now (line 474/1224) to maintain alphabetical order.
use oxc_ast::{

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

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 9, 2025

CodSpeed Performance Report

Merging #16620 will not alter performance

Comparing re-taro:feat/prefer-default-params (e6c87db) with main (ce57612)1

Summary

✅ 4 untouched
⏩ 41 skipped2

Footnotes

  1. No successful run was found on main (cb74fad) during the generation of this report, so ce57612 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.

@re-taro re-taro force-pushed the feat/prefer-default-params branch from 1ac2762 to 0321927 Compare December 9, 2025 02:08
@camc314 camc314 self-assigned this Dec 9, 2025
Copy link
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! Unfortunately, it looks like the rulegen infra failed to port across some test cases. I've done them manually and updated the PR, however some tests cases are failing

@re-taro re-taro force-pushed the feat/prefer-default-params branch from 914ef72 to b1b1d68 Compare December 9, 2025 15:20
@re-taro
Copy link
Contributor Author

re-taro commented Dec 9, 2025

Thanks for working on this! Unfortunately, it looks like the rulegen infra failed to port across some test cases. I've done them manually and updated the PR, however some tests cases are failing

I'm sorry! Thank you!

@re-taro re-taro requested a review from camc314 December 9, 2025 15:31
@re-taro re-taro requested a review from camc314 December 9, 2025 17:00
@re-taro re-taro force-pushed the feat/prefer-default-params branch from 3ce569c to 6ae0227 Compare December 9, 2025 17:09
Copy link
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

Thank you!

@camc314 camc314 force-pushed the feat/prefer-default-params branch from 80f7f99 to e6c87db Compare December 9, 2025 18:31
@camc314 camc314 merged commit 8550c0f into oxc-project:main Dec 9, 2025
20 checks passed
@re-taro re-taro deleted the feat/prefer-default-params branch December 10, 2025 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants