cpp-import-mining
Read-only mining codemod that surfaces #import preprocessor directives in
C/C++/Objective-C++ source. Sonar rule cpp:S3805
flags #import because it is an Objective-C variant of #include that requires
callers to know a header should only be included once. Compliant code uses
#include with include guards (or #pragma once) in the header itself.
No source edits are produced; the codemod emits one metric row per #import
site so you can quantify violations before applying a fix codemod or manual
remediation.
Detected pattern
| Noncompliant | Compliant |
|---|---|
#import "foo.h" | #include "foo.h" |
#import <stdio.h> | #include <stdio.h> |
#include directives are ignored. Other preprocessor directives (#define,
#if, etc.) are not reported.
Metric: cpp_import_directive
| field | description |
|---|---|
rule_id | Always cpp:S3805 |
file_path | Relative path of the scanned file |
line | 1-based line number of the #import |
header_path | Imported header path without quotes or angle brackets |
import_style | quoted, angled, or unknown |
severity | Always major (Sonar classification) |
remediation | Suggested fix summary |
Run locally
bash
Development
bash
License
MIT