Skip to content

Commit 9bbae72

Browse files
committed
[include-cleaner] return --remove and --insert to be in deprecation period
1 parent c476948 commit 9bbae72

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

clang-tools-extra/include-cleaner/test/tool.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ int x = foo();
1414
// REMOVE: - "foobar.h"
1515
// REMOVE-NOT: + "foo.h"
1616

17+
// RUN: clang-include-cleaner -remove=0 -print=changes %s -- -I%S/Inputs/ | FileCheck --check-prefix=INSERT %s
18+
// INSERT-NOT: - "foobar.h"
19+
// INSERT: + "foo.h"
20+
21+
// RUN: clang-include-cleaner -insert=0 -print=changes %s -- -I%S/Inputs/ | FileCheck --check-prefix=REMOVE %s
22+
// REMOVE: - "foobar.h"
23+
// REMOVE-NOT: + "foo.h"
24+
1725
// RUN: clang-include-cleaner -print=changes %s --ignore-headers="foobar\.h,foo\.h" -- -I%S/Inputs/ | FileCheck --match-full-lines --allow-empty --check-prefix=IGNORE %s
1826
// IGNORE-NOT: - "foobar.h"
1927
// IGNORE-NOT: + "foo.h"

clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,21 @@ cl::opt<bool> Edit{
9090
cl::desc("Apply edits to analyzed source files"),
9191
cl::cat(IncludeCleaner),
9292
};
93-
93+
cl::opt<bool> Insert{
94+
"insert",
95+
cl::desc("Allow header insertions"),
96+
cl::init(true),
97+
cl::cat(IncludeCleaner),
98+
};
99+
cl::opt<bool> Remove{
100+
"remove",
101+
cl::desc("Allow header removals"),
102+
cl::init(true),
103+
cl::cat(IncludeCleaner),
104+
};
94105
cl::opt<bool> DisableInsert{
95106
"disable-insert",
96-
cl::desc("DIsable header insertions"),
107+
cl::desc("Disable header insertions"),
97108
cl::init(false),
98109
cl::cat(IncludeCleaner),
99110
};
@@ -183,9 +194,9 @@ class Action : public clang::ASTFrontendAction {
183194
auto Results =
184195
analyze(AST.Roots, PP.MacroReferences, PP.Includes, &PI,
185196
getCompilerInstance().getPreprocessor(), HeaderFilter);
186-
if (DisableInsert)
197+
if (!Insert || DisableInsert)
187198
Results.Missing.clear();
188-
if (DisableRemove)
199+
if (!Remove || DisableRemove)
189200
Results.Unused.clear();
190201
std::string Final = fixIncludes(Results, AbsPath, Code, getStyle(AbsPath));
191202

0 commit comments

Comments
 (0)