rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Create a search recipe for commented out code. `RSPEC-125`

Open yeikel opened this issue 2 years ago • 4 comments

Programmers should not comment out code as it bloats programs and reduces readability.

Unused code should be deleted and can be retrieved from source control history if required

https://rules.sonarsource.com/java/RSPEC-125

yeikel avatar Apr 16 '22 03:04 yeikel

OpenRewrite's motto is "do no harm" and while this is generally a good policy to not have commented-out code, auto-remediation of such situations is likely to remove things the user does not want removed. I could maybe see developing a search recipe for pattern that provides parity with the sonarqube rule.

tkvangorder avatar Apr 18 '22 15:04 tkvangorder

OpenRewrite's motto is "do no harm" and while this is generally a good policy to not have commented-out code, auto-remediation of such situations is likely to remove things the user does not want removed. I could maybe see developing a search recipe for pattern that provides parity with the sonarqube rule.

Would it be possible to develop a separate recipe that leverages the git history?

Example : deleted commented out code older than n time

In any case, this recipe is meant to be enabled and reviewed manually by the users. I don't see how it could cause harm

yeikel avatar Apr 18 '22 15:04 yeikel

In any case, this recipe is meant to be enabled and reviewed manually by the users. I don't see how it could cause harm

This is one use case, where you run a recipe once, and then forget about it.

The other use case where's it could cause harm, is when you want to keep a good state for new code, and setup your CI to check if configured recipes don't generate changes (you see that as a linter). You can achieve that with the dryrun-goal of maven plugin. In that case you don't want to have human intervention to validate if changes are good or bad.

murdos avatar May 01 '22 21:05 murdos

In any case, this recipe is meant to be enabled and reviewed manually by the users. I don't see how it could cause harm

This is one use case, where you run a recipe once, and then forget about it.

The other use case where's it could cause harm, is when you want to keep a good state for new code, and setup your CI to check if configured recipes don't generate changes (you see that as a linter). You can achieve that with the dryrun-goal of maven plugin. In that case you don't want to have human intervention to validate if changes are good or bad.

I think that this will happen with all the recipes

yeikel avatar May 01 '22 23:05 yeikel