Feat: Add Quick Fix for catch_parameter_names rule
#497
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces an automated Quick Fix for the existing
catch_parameter_nameslint rule.Previously, the linter would warn if catch parameters (exception or stack trace) did not match the configured standard (default
err,st), but users had to manually rename them. This update adds aDartFixthat automatically renames the parameter and all its usages within the catch block.Changes
New Fix Class (
RenameCatchParameter):CatchParameterNamesConfig.RecursiveAstVisitor(_UsageFinder) to safely find all usages of that parameter within the catch block scope.catchclauses, function declarations, or function expressions) where the parameter name might be shadowed, ensuring safe refactoring.Updated
CatchParameterNamesRule:RenameCatchParameteringetFixes().Documentation:
README.mdto indicate thatcatch_parameter_namesnow supports a Quick Fix.Example
Configuration:
Input (Before Fix):
Output (After Fix):
Implementation Details
The fix logic is sturdy against scope shadowing. For example, in the following case, the inner
eis not renamed when fixing the outer catch block:Checklist
README.mdupdated.