JetBrains Rider
 
Get JetBrains Rider
Get your hands on the new features ahead of the release by joining the Early Access Program for Rider 2025.1! Learn more

Remove code redundancies

Last modified: 11 February 2024

On the Editor | Inspection Severity page of JetBrains Rider settings CtrlAlt0S, in the Redundancies in Code categories of different languages, JetBrains Rider lists a lot of code redundancies that have associated code inspections. For most of these redundancies, JetBrains Rider provides quick-fixes. Some code redundancies cannot be fixed automatically, and quick-fixes for them are performed in the interactive mode, requiring the user input. But the majority of the redundancies can be fixed without user interaction, using either fix in scope or code cleanup.

From any code redundancy highlighted by the design-time code inspection, you can invoke the 'Remove redundant code' quick-fix that will remove the current redundancy as well as all redundant code in the file, project or solution:

Remove redundant code quick-fix

Another option to remove code redundancies in a bulk mode is code cleanup. You can either run code cleanup with the Built-in: Full Cleanup profile or create and run a custom profile solely targeted at your specific task as described below.

If you want to remove code redundancies without opening the Reformat and Cleanup Code dialog to choose a profile, you can bind the created profile to the silent cleanup and run it by pressing Ctrl0E,0F. You can also create a custom cleanup profile that would combine removing code redundancies with other code style tasks.

You can remove code redundancies in code that you have recently modified and are going to commit to Git. JetBrains Rider will run the selected cleanup profile before committing.

You can remove code redundancies every time you save changes in a file to make sure that your edits always comply with your code style. Note that this will only happen when you save changes explicitly with Ctrl0S or CtrlShift0S and will not be triggered by auto-saving. However, all auto-saved files are placed to the 'reformat and cleanup' queue and will be processed on the next explicit save.