Eclipse 2025-09 (4.37.0) :: SonarLint for Eclipse 11.16.0.83074
I want to disable the warnings for “Avoid constant literals” (in C), but I cannot find any listing in the Rules Configuration list in Eclipse which seems to correlate to this, and there’s no “Disable this rule” option available when hovering over the annotation. I’ve tried filtering for “constant” and “literal” and even “avoid,” but I’m not seeing a match.
Before anyone wants to lecture about how this is a bad idea (like I would likely be inclined to do myself), our code is very good at avoiding magic numbers, but this is a case where there’s a lot of well known and recognizable engineering formulas and constants in play, and creating a semantic label for every one of the numbers would make the code much more difficult to read.
The frequency of this rule flagging all over these particular files is distracting, and could lead to ignoring all flags including where there’s a useful one.
Anyway, if someone can point me to the a rule I can disable, I’d appreciate it.
is your project connected to a SonarQube Server or Cloud? In that case the rule can only be deactivated on the Quality Profile in the server.
When not in Connected Mode, rules can normally be disabled from the SonarQube On-The-Fly view by right-clicking on them and selecting the option.
If the issues is not shown in that view, then the annotation you see in the editor is not coming from the IDE plug-in but maybe from the CDT-analysis that is builtin the IDE.
Could you provide a screenshot of the warning? I searched our codebase for the phrase “avoid constant literals” but didn’t find any results—we typically refer to this as “No magic numbers.” I want to verify that this warning is actually from SonarQube in the IDE!
Oh! Indeed, maybe this is something straight from Eclipse. Don’t recall running into it before (or any code style hinting from Eclipse), but since I’ve been using Sonar lately, I jumped straight to thinking that’s where it was from.
Hmm. The light bulb icon is suspicious — that’s not a typical annotation I see from Sonar.
We have a rule (c:S109 / cpp:S109) against using magic numbers, but it’s not enabled by default. Additionally, our issue message is more descriptive: ‘Assign this magic number __ to a well-named variable, and use the variable instead.’
Yeah, found the Code Analysis configs for CDT. I had forgotten that system was even there. Apparently it’s very rare I get messages from it. I found the “Avoid Magic Numbers” option, and was able to change for the specific project.
(BTW that wiki link not working fo me (503). Might be temporary.)
Heh. Well, I’m C “functional,” but I wouldn’t say I’m much more than that. More of an application-focused coder, and haven’t ever dug deep into the details of the compiler. It was probably a naive attempt to avoid a calculation. So, yeah if the compiler pre-calcs that, then I agree it’s better to leave the formula in full (as was my stated purpose for the magic numbers in the first place).