Aalexbit-codemod

cpp-import-mining

Mine #import preprocessor directives in C/C++ source (Sonar cpp:S3805); read-only metrics for review and remediation

miningmetricscppc++preprocessorimportincludesonarcpp:S3805
Public
1 executions

Run locally

npx codemod cpp-import-mining

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

NoncompliantCompliant
#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

fielddescription
rule_idAlways cpp:S3805
file_pathRelative path of the scanned file
line1-based line number of the #import
header_pathImported header path without quotes or angle brackets
import_stylequoted, angled, or unknown
severityAlways major (Sonar classification)
remediationSuggested fix summary

Run locally

bash

Development

bash

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.