IntelliJ Idea: How to automatically remove commented out code?
Asked Answered
A

1

8

I've run SonarQube analysis on my Android/Java project and it resulted, among others, with issues:

Sections of code should not be "commented out"

If SonarQube is able to identify them, is it possible to automatically commented out code in Android Studio? I can't just remove all comments, because there are also some that are legit.

I have 500+ of them and don't want to do it manually. Any ideas?

Armenta answered 4/12, 2015 at 13:59 Comment(5)
So you're wanting to automatically remove some, but not all, commented code from your project?Disillusion
No, I'd like to remove all commented lines which are commented out executable code. I want to keep commented lines which are javadocs, notes, descriptions etc. SonarQube somehow can tell which is which.Armenta
Anyone has this problem before and came up with solution?Minium
Did you manage to find a way to delete commented code in Android Studio?Karyoplasm
Unfortunately, I haven't come up with any out-of-the-box solution.Armenta
P
1

There is no general solution for issues reported by SonarQube since SonarQube only finds problems, it doesn't offer a way to fix them.

In this particular case of commented out code, the same check is available directly in IntelliJ.

  • from the menu, select "Code | Analyze Code | Run Inspection by Name"
  • type "commented" to select the inspection about commented code
  • run it on the whole project

This inspection now lists the occurrences, and the Problems tool window offers you to fix all of them at once.

Paronomasia answered 10/5, 2022 at 7:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.