Skip to content

feat(linter/no-unused-vars): add param rename suggestion#22285

Merged
camc314 merged 4 commits into
oxc-project:mainfrom
deltama37:fix/no-unused-vars-param-rename-suggestion
May 11, 2026
Merged

feat(linter/no-unused-vars): add param rename suggestion#22285
camc314 merged 4 commits into
oxc-project:mainfrom
deltama37:fix/no-unused-vars-param-rename-suggestion

Conversation

@deltama37

@deltama37 deltama37 commented May 9, 2026

Copy link
Copy Markdown
Contributor

Part of #16832.

This PR adds a dangerous suggestion for unused function parameters in no-unused-vars, renaming them to the ignored _name form.

For example, with args: "all" and argsIgnorePattern: "^_":

function f(unused) {}

can be fixed with --fix-dangerously to:

function f(_unused) {}

It intentionally only covers simple function parameters. Catch bindings are already handled by #17567, and the remaining fixer categories from #16832 are left for follow-up PRs.

This PR does not cover default parameters, destructuring parameters, rest bindings, type parameters, or multi-declarator cleanup.

Manual verification

I also verified the change against the actual oxlint CLI.

Input:

function decl(unused, used) { console.log(used); }
const expr = function(unused) { return 1; };
const arrow = (unused) => 1;
const obj = { method(unused) { return 1; } };
function conflict(unused, _unused) { console.log(_unused); }

After running oxlint --fix-dangerously with no-unused-vars configured as { "args": "all", "argsIgnorePattern": "^_" }:

function decl(_unused, used) { console.log(used); }
const expr = function(_unused) { return 1; };
const arrow = (_unused) => 1;
const obj = { method(_unused) { return 1; } };
function conflict(_unused0, _unused) { console.log(_unused); }

I also verified that --fix-suggestions does not apply this dangerous suggestion, and that default/destructuring parameters are left unchanged.

Reviewer note

The existing diagnostic help for unused parameters still says:

Consider removing this parameter.

This PR keeps that wording unchanged and only adds the dangerous rename suggestion. I can adjust the help text in a follow-up if maintainers prefer.

AI usage

AI assistance was used for implementation support, code navigation, test planning, manual verification, and self-review. I reviewed, tested, and take responsibility for the submitted changes.

Original prompt / instructions given to AI were in Japanese. The English version below is an LLM translation for reviewer convenience.

Original Japanese prompt

no_unused_vars の unused function parameter fixer だけを小さなスコープで実装する。
function f(unused) {} のような未使用の関数パラメータに対して、削除ではなく _unused 形式へ rename する dangerous suggestion を追加する。
catch bindings、multi-declarator cleanup、type parameters、rest bindings、destructuring parameters などは今回の PR では扱わない。
既存の fixer 実装とテスト構造に合わせ、rename conflict は既存の _x, _x0, _x1 のような handling に乗せる。
function declaration、function expression、arrow function、method parameter のテストを追加する。

English translation by LLM

Implement only the unused function parameter fixer for no_unused_vars in a small scope.
Add a dangerous suggestion for unused function parameters such as function f(unused) {}, renaming them to the ignored _unused form instead of deleting them.
Do not cover catch bindings, multi-declarator cleanup, type parameters, rest bindings, destructuring parameters, or other fixer categories in this PR.
Follow the existing fixer implementation and test structure, and reuse the existing rename conflict handling such as _x, _x0, _x1.
Add tests for function declarations, function expressions, arrow functions, and method parameters.

Checks

  • cargo test -p oxc_linter no_unused_vars::tests
  • cargo build -p oxfmt --no-default-features
  • PATH="$PWD/target/debug:$PATH" just fmt
  • env -u NO_COLOR PATH="$PWD/target/debug:$PATH" just ready

@deltama37 deltama37 marked this pull request as ready for review May 9, 2026 23:52
@deltama37 deltama37 requested a review from camc314 as a code owner May 9, 2026 23:52
@camc314 camc314 changed the title Fix/no unused vars param rename suggestion feat(linter/no-unused-vars): add param rename suggestion May 10, 2026
@camc314 camc314 self-assigned this May 10, 2026
@camc314 camc314 added the A-linter Area - Linter label May 10, 2026

@camc314 camc314 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.

thanks!

@camc314 camc314 merged commit fa0232b into oxc-project:main May 11, 2026
27 checks passed
@codspeed-hq

codspeed-hq Bot commented May 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 4 untouched benchmarks
⏩ 47 skipped benchmarks1


Comparing deltama37:fix/no-unused-vars-param-rename-suggestion (26cc253) with main (a7c3e22)

Open in CodSpeed

Footnotes

  1. 47 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 added a commit that referenced this pull request May 11, 2026
# Oxlint
### 💥 BREAKING CHANGES

- 00ce512 oxlint/lsp: [**BREAKING**] Don't fix suggestions on fixAll
code actions & command (#22195) (Sysix)

### 🚀 Features

- 0eeceaf linter/no-unused-vars: Rename parameter with initializer
(#22308) (camc314)
- fa0232b linter/no-unused-vars: Add param rename suggestion (#22285)
(Ryota Misumi)
- ae59305 linter/promise/no-promise-in-callback: Add
`exemptDeclarations` option (#22275) (Mikhail Baev)
- 60bed4a linter: Extends `no-redundant-roles` and
`prefer-tag-over-role` support roles (#22069) (mehm8128)
- 545c80f linter/eslint: Implement `prefer-regex-literals` rule (#22192)
(Mikhail Baev)
- cf86d7a linter: Bulk suppression (#19328) (Said Atrahouch)
- 23abd22 linter/jsx-a11y: Implement
no-noninteractive-element-to-interactive-role (#21264) (Pedro Tainha)
- fbb8f22 linter: Support `ignores` in overrides (#22148) (camc314)
- 5a4414d oxlint/lsp: Support `rulesCustomization` lsp option (#21858)
(Sysix)

### 🐛 Bug Fixes

- 610f4c7 linter/no-unused-vars: Avoid renaming captured vars (#22310)
(camc314)
- 6b50f23 oxlint/cli: Load root config by searching up parent
directories (#22272) (Sysix)
- 31a5de7 linter: Rename override `ignores` to `excludeFiles` (#22283)
(camc314)
- 26d5d7b linter: Add missing vitest/valid-describe-callback
functionality (#22279) (camchenry)
- 784530f linter: `valid-title`: detect `String.raw` strings (#22271)
(Sysix)
- 080d90e linter: Move `no-debugger` fix to suggestion (#22256) (Sysix)
- 25b7017 linter: Undocument override `ignores` option (#22213)
(camc314)
- 7bb00dd linter: Fix role-has-required-aria-props (#22097) (mehm8128)
- d25279e linter/disable-directives: Improve parsing of names,
descriptions (#22184) (camc314)
- a59e447 linter/disable-directives: Ignore invalid enable suffixes
(#22179) (camc314)
- aafef0f ci: Disable bulk supression test on big endian (#22175)
(camc314)
- 281daec linter/vue/define-props-destructuring: Add
`only-when-assigned` config opt (#22142) (camc314)
- 46ab679 linter/plugins: Trim leading newline for partial sources
(#20928) (bab)
- 29ff6d9 linter: Update docs for no_alias_methods rule to be
Vitest-specific and add toThrowError alias (#22129) (camchenry)

### ⚡ Performance

- 9414bee linter/role-has-required-aria-props: Avoid intermediate vec
(#22212) (camc314)
- 3883ea3 linter/no-useless-escape: Drop unnecessary Vec collect
(#22171) (connorshea)
- 42c3029 linter/check-property-names: Replace split-collect-pop-join
with rfind (#22172) (connorshea)
- 9551d53 linter: Remove unnecessary Vec collect in CFG edge traversal
(#22167) (connorshea)
- 26fa2fc linter/aria-role: Remove unnecessary string allocations in run
method (#22168) (connorshea)
- c9ce045 linter/getter-return: Remove unnecessary Vec collect in CFG
edge traversal (#22166) (connorshea)
- 72bd846 linter/no-this-in-sfc: Reorder cheap name check, avoid String
allocation (#22164) (connorshea)

### 📚 Documentation

- 4da212a linter/no-unused-vars: Add docs to
`rename_unused_function_parameter` (#22311) (camc314)
- 27c4628 linter/forbid-dom-props: Escape jsx examples in lint rule docs
(#22254) (4MBL)
- 3f81147 linter: Improve the `react/jsx-key` rule docs. (#22162)
(connorshea)
- 07f03cc linter/consistent-return: Add note about `noImplicitReturns`
coverage (#22156) (camc314)
- 7c1e049 oxlint/lsp: Improve autogenerated lsp docs (#22154) (Sysix)
- 87b3e38 linter: Update docs to be vitest-specific for
consistent-test-it (#22128) (camchenry)
# Oxfmt
### 💥 BREAKING CHANGES

- 5c6c390 oxfmt: [**BREAKING**] Respect more git ignore options, align
with Oxlint (#22210) (leaysgur)

### 🚀 Features

- 6e8e818 oxfmt: Experimental .svelte support (#21700) (leaysgur)

### 🐛 Bug Fixes

- e2a20b6 formatter: Add space after commas in import attributes
(#22274) (Leonabcd123)

### ⚡ Performance

- b756682 oxfmt: Optimize nested config prescan (#22232) (Jovi De
Croock)
- f14e81e formatter/sort_imports: Skip sort for single import runs
(#22204) (leaysgur)
- 32255b1 formatter: Process `ImportDeclaration`s in a run (#22079)
(overlookmotel)

### 📚 Documentation

- 4da6f4c formatter: Correct comment (#22217) (overlookmotel)
- ef3507d formatter/sort_imports: Refresh docs (#22203) (leaysgur)

Co-authored-by: Cameron <cameron.clark@hey.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants