Is there a way to exclude some lines of code from sonarqube analysis without excluding the whole source code file? Maybe with an annotation or something like this?
I'll give you an concrete example, where i need to exclude a certain code smell for an unused function parameter:
I implemented a validation method like this:
public function validateTruth(string $attribute, $value) : bool
{
$acceptable = [
'0',
0,
'false',
false,
'1',
1,
'true',
true,
'no',
'yes',
];
return in_array($value, $acceptable, true);
}
in order to extended the \Illuminate\Contracts\Validation\Factory with the extend method:
$validationFactory->extend(
'truth',
Validator::class . @validateTruth',
'The :attribute field must be some kind of truth value.'
);
My implementation doesn't uses all the required parameters, but i cannot just leave out the first parameter. The extend wouldn't work with a callback method without the $attribute parameter. So the extend method clearly requires a callback with a certain set of parameters, but it doesn't provide an interface or something like this, so the missing parameter would be excluded automatically from sonarqube.
Is there a way to exclude only this code smell, without excluding the whole function or file from sonarqube analysis? I would prefer a solution within the source code, because we use different instances of sonarqube in our development lifecycle, so flagging such code smells in the webfrontend would be harder to maintain.