Block suppression of individual rules

Using SonarQube Server v2026.1.1 on some Azure VM.

I am looking to add block exclusions of a particular rule, like this example, where I am writing a u32 to a buffer in big Endian byte order.

buffer [ii]   = (uint8_t) ((value_u32 & 0xFF000000u) >> 24u);
buffer [ii+1] = (uint8_t) ((value_u32 &   0xFF0000u) >> 16u);
buffer [ii+2] = (uint8_t) ((value_u32 &     0xFF00u) >>  8u);
buffer [ii+3] = (uint8_t) ((value_u32 &       0xFFu));

Rule c:S109 says:

Magic numbers should not be used.

This is a good rule, but it would be counter productive to have to have a preprocessor constant for all these numbers, especially the buffer indices!

buffer [ii]         = (uint8_t) ((value_u32 & THIRD_BYTE)  >> BITS_IN_3B);
buffer [ii + ONE]   = (uint8_t) ((value_u32 & SECOND_BYTE) >> BITS_IN_2B);
buffer [ii + TWO]   = (uint8_t) ((value_u32 & FIRST_BYTE)  >> BITS_IN_1B);
buffer [ii + THREE] = (uint8_t) ((value_u32 & ZEROETH_BYTE));

I want to exclude the code from this rule and, preferably, have the violations raised in the exclusion block be noted by SonarQube with the given reason.

// NOSONAR_BEGIN c:S109 "Magic number use is clear from context."
buffer [ii]   = (uint8_t) ((value_u32 & 0xFF000000u) >> 24u);
buffer [ii+1] = (uint8_t) ((value_u32 &   0xFF0000u) >> 16u);
buffer [ii+2] = (uint8_t) ((value_u32 &     0xFF00u) >>  8u);
buffer [ii+3] = (uint8_t) ((value_u32 &       0xFFu));
// NOSONAR_END

I asked about this two or three years ago and the guy from Sonar who responded was quite contrite. Has this been fixed yet?

Hi,

You have the ability to exclude a rule from a specific file or set of files, but not at the block level.

 
HTH,
Ann