Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | 54x 54x 288x 288x 231x 57x | /**
* 2.2 Plan -- which generated `#include` carries a cppcheck suppression, and
* under which MISRA rule.
*
* The sibling of `ComplianceAnnotations`, and split from `MisraSuppressionUtils`
* for the same reason: the table decides WHAT is emitted, the render pass only
* decides how it reads. A suppression is not cosmetic -- drop this table and
* `#include <stdio.h>` in generated C is reported as a MISRA 21.6 violation
* against the certification artifact. That is a change to what is emitted, which
* is the discriminator `docs/architecture/module-destinations.md` gives for this
* boundary (#1450 box 4).
*
* Distinct from `ComplianceAnnotations` in what the comment is FOR -- a
* suppression tells a TOOL to stop reporting, an annotation tells a READER why
* the code looks like this -- but not in which pass owns it. Both own a rule
* citation; neither owns its spelling.
*
* Adding a banned header means adding a row.
*/
class MisraSuppressions {
/**
* Headers whose use generated C must suppress, mapped to the rule cited.
*
* MISRA Rule 21.6: the standard library input/output functions shall not be
* used. C-Next emits `<stdio.h>` only where a program asked for it.
*/
private static readonly BANNED_HEADERS: ReadonlyMap<string, string> = new Map(
[["stdio.h", "misra-c2012-21.6"]],
);
/**
* Header name out of an angle-bracket include.
*
* `[^<>]` cannot backtrack across a bracket, so this is linear on any input.
* A quoted include is a project header and is deliberately not matched: the
* banned set is about the standard library.
*/
private static readonly ANGLE_BRACKET_INCLUDE = /<([^<>]+)>/;
/**
* The MISRA rule an include must be suppressed under, or `null` when it needs
* no suppression.
*
* One entry point, not two. `needsMisraSuppression` used to answer the same
* question beside this one, each re-running the regex and re-reading the map
* -- one decision with two derivations, which is what CLAUDE.md's
* single-source-of-truth rule is about. It had no production caller at all;
* its six test callers hid that from knip (#1418).
*
* @param includeText - a full include directive, e.g. `#include <stdio.h>`
*/
static ruleFor(includeText: string): string | null {
const match = MisraSuppressions.ANGLE_BRACKET_INCLUDE.exec(includeText);
if (!match) {
return null;
}
return MisraSuppressions.BANNED_HEADERS.get(match[1]) ?? null;
}
}
export default MisraSuppressions;
|