- It's not a bug in the tool (because the warning is often useful).
- A mention in a commit message doesn't help when you run the tool in future and get false alarms (oh I'll just read all the historic commit messages to see if any say these should be ignored).
- If you find such a comment at peer review then that doesn't give you anything actionable to do if the comment is being used correctly in one of these casees.
The solution in these cases is not "a little discipline" but simply to use the disabling comment and accept that this is reasonable.
Only if the total number of warnings across your entire codebase is tiny - 10 is the [arbitrary] number I like to use. That is 10 warnings, it doesn't matter if you are writing 5 lines of hello world or a 100 million lines of a self driving car. When the number of ignored warnings get above that number people start to ignore the tool and then it becomes useless.
With 10000 warnings that means that people have gotten in the habit of disabling warnings, so how many of them are real. I've tracked production bugs to someone disabling a warning - we regularly disabled that warning for correct reasons, but in the one case it wasn't a false warning.
Thus your disabled warning levels need to be small. Small is somewhat arbitrary, but it needs to be small enough that when the tool says something is wrong you trust it.
- If the annotation is thought to be necessary because of a bug in the tool, add a link to the bug next to the disable comment. This makes it easy to get rid of the comment when being alerted that the bug is fixed.
- If you happen to disagree with the tool in a specific instance, and there's no way to override just that case, mention why in the commit message.
- Check for disable comments at peer review.