CodeCharter lets you deliberately exclude findings with suppression comments in
your code (three forms) for a single line or file, or switch whole rules and
paths off in .codecharter/config.yml.
1. Inline Suppression on the Next Line
// codecharter-disable-next-line datetime-direct-usage
var migrationTimestamp = DateTime.UtcNow;
The directive applies to the immediately following line. The rule slug is
required: a bare // codecharter-disable-next-line without a slug does not
suppress anything.
2. Suppression on the Same Line or the Line Above
var migrationTimestamp = DateTime.UtcNow; // codecharter-disable datetime-direct-usage
Or on the line above:
// codecharter-disable datetime-direct-usage
var migrationTimestamp = DateTime.UtcNow;
Both comment forms accept several rule slugs in one comment, separated by
spaces, for example // codecharter-disable datetime-direct-usage magic-number.
Slugs are matched case-sensitively against the rule id, which is the rule file
name without the .ccr extension.
A free-text reason may follow the rule slug(s), for example
// codecharter-disable magic-number migration constant. Extra tokens after the
slug are ignored, so suppressions can be self-documenting; this works in the
codecharter-disable-next-line form as well. Because every token is compared
against rule slugs, avoid reason words that are themselves slugs of other
rules, as those rules would be suppressed too.
3. File-Level Suppression
A // codecharter-disable comment that stands alone on its own line, with no
rule slug and nothing else on the line, suppresses all findings for the entire
file. It can appear anywhere in the file, but placed after code on the same
line it has no file-level effect. Useful for auto-generated code or legacy
files you don't want to touch right now.
// codecharter-disable
namespace Acme.Generated;
Not Supported
There is no // codecharter-enable comment, so a suppression cannot be switched
back on further down in the file, and there is no block or range form that
covers a region of code. The .NET [SuppressMessage] attribute is not
evaluated, and findings cannot be suppressed by rule category. For larger
regions, switch the rule off in .codecharter/config.yml with an ignore entry,
or exclude the paths with exclude (below).
Repository-Level Suppressions
To switch off a whole rule, or to drop entire paths from analysis, use
.codecharter/config.yml instead of inline comments. The ignore section turns
findings off (optionally limited to a namespace with in: or to matching
entity names with match:), and exclude removes paths from analysis:
version: 1
ignore:
- rule: namespace-distance
in: Acme.Generated
- rule: todo-comment
exclude:
- "**/tests/**"
- "**/obj/**"
To change a rule's severity instead of switching it off, use the overrides
section; see Findings. For the full set of
sections, scopes, and the machine-local overlay, see
Configuration file.