Skip to content

Commit aa6b48f

Browse files
committed
Code review
1 parent 69b7c43 commit aa6b48f

File tree

7 files changed

+38
-20
lines changed

7 files changed

+38
-20
lines changed

clang-tools-extra/clang-tidy/ClangTidyOptions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct ClangTidyOptions {
8585
/// main files will always be displayed.
8686
std::optional<std::string> HeaderFilterRegex;
8787

88-
/// \brief Exclude warnings from headers matching this filter, even if they
88+
/// Exclude warnings from headers matching this filter, even if they
8989
/// match \c HeaderFilterRegex.
9090
std::optional<std::string> ExcludeHeaderFilterRegex;
9191

@@ -112,9 +112,6 @@ struct ClangTidyOptions {
112112
/// comments in the relevant check.
113113
std::optional<std::string> User;
114114

115-
/// \brief Remove command line arguments sent to the compiler matching this.
116-
std::optional<std::vector<std::string>> RemovedArgs;
117-
118115
/// Helper structure for storing option value with priority of the value.
119116
struct ClangTidyValue {
120117
ClangTidyValue() = default;
@@ -154,6 +151,9 @@ struct ClangTidyOptions {
154151
/// Add extra compilation arguments to the start of the list.
155152
std::optional<ArgList> ExtraArgsBefore;
156153

154+
/// Remove command line arguments sent to the compiler matching this.
155+
std::optional<std::vector<std::string>> RemovedArgs;
156+
157157
/// Only used in the FileOptionsProvider and ConfigOptionsProvider. If true
158158
/// and using a FileOptionsProvider, it will take a configuration file in the
159159
/// parent directory (if any exists) and apply this config file on top of the

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Configuration files:
7878
(if any exists) will be taken and the current
7979
config file will be applied on top of the
8080
parent one.
81+
RemovedArgs - Same as '--removed-arg'.
8182
SystemHeaders - Same as '--system-headers'.
8283
UseColor - Same as '--use-color'.
8384
User - Specifies the name or e-mail of the user
@@ -358,12 +359,12 @@ see https://clang.llvm.org/extra/clang-tidy/QueryBasedCustomChecks.html.
358359

359360
static cl::list<std::string> RemovedArgs("removed-arg", desc(R"(
360361
List of arguments to remove from the command
361-
line sent to the compiler. Please note that
362-
removing arguments might change the semantic
363-
of the analzed code, possibly leading to
364-
compiler errors, false positives or
365-
false negatives. This option is applied
366-
before --extra-arg and --extra-arg-before)"),
362+
line sent to the compiler. Please note that
363+
removing arguments might change the semantic
364+
of the analzed code, possibly leading to
365+
compiler errors, false positives or
366+
false negatives. This option is applied
367+
before --extra-arg and --extra-arg-before)"),
367368
cl::cat(ClangTidyCategory));
368369

369370
namespace clang::tidy {

clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ def main():
228228
default=[],
229229
help="Additional argument to prepend to the compiler " "command line.",
230230
)
231+
parser.add_argument(
232+
"-removed-arg",
233+
dest="removed_arg",
234+
action="append",
235+
default=[],
236+
help="Arguments to remove from the compiler command line.",
237+
)
231238
parser.add_argument(
232239
"-quiet",
233240
action="store_true",
@@ -378,6 +385,8 @@ def main():
378385
common_clang_tidy_args.append("-extra-arg=%s" % arg)
379386
for arg in args.extra_arg_before:
380387
common_clang_tidy_args.append("-extra-arg-before=%s" % arg)
388+
for arg in args.removed_arg:
389+
common_clang_tidy_args.append("-removed-arg=%s" % arg)
381390
for plugin in args.plugins:
382391
common_clang_tidy_args.append("-load=%s" % plugin)
383392
if args.warnings_as_errors:

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def get_tidy_invocation(
9696
allow_enabling_alpha_checkers: bool,
9797
extra_arg: List[str],
9898
extra_arg_before: List[str],
99+
removed_arg: List[str],
99100
quiet: bool,
100101
config_file_path: str,
101102
config: str,
@@ -135,6 +136,8 @@ def get_tidy_invocation(
135136
start.append(f"-extra-arg={arg}")
136137
for arg in extra_arg_before:
137138
start.append(f"-extra-arg-before={arg}")
139+
for arg in removed_arg:
140+
start.append(f"-removed-arg={arg}")
138141
start.append(f"-p={build_path}")
139142
if quiet:
140143
start.append("-quiet")
@@ -377,6 +380,7 @@ async def run_tidy(
377380
args.allow_enabling_alpha_checkers,
378381
args.extra_arg,
379382
args.extra_arg_before,
383+
args.removed_arg,
380384
args.quiet,
381385
args.config_file,
382386
args.config,
@@ -551,6 +555,13 @@ async def main() -> None:
551555
default=[],
552556
help="Additional argument to prepend to the compiler command line.",
553557
)
558+
parser.add_argument(
559+
"-removed-arg",
560+
dest="removed_arg",
561+
action="append",
562+
default=[],
563+
help="Arguments to remove from the compiler command line.",
564+
)
554565
parser.add_argument(
555566
"-quiet", action="store_true", help="Run clang-tidy in quiet mode."
556567
)
@@ -638,6 +649,7 @@ async def main() -> None:
638649
args.allow_enabling_alpha_checkers,
639650
args.extra_arg,
640651
args.extra_arg_before,
652+
args.removed_arg,
641653
args.quiet,
642654
args.config_file,
643655
args.config,

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,10 @@ Improvements to clang-tidy
167167
scripts by adding the `-hide-progress` option to suppress progress and
168168
informational messages.
169169

170-
- Improved :program:`clang-tidy` by adding the option `RemovedArgs` to remove
171-
arguments sent to the compiler when invoking Clang-Tidy.
170+
- Improved :program:`clang-tidy` by adding the `--removed-arg` option to remove
171+
arguments sent to the compiler when invoking Clang-Tidy. This option was also
172+
added to :program:`run-clang-tidy.py` and :program:`clang-tidy-diff.py` and
173+
can be configured in the config file through the `RemovedArgs` option.
172174

173175
- Deprecated the :program:`clang-tidy` ``zircon`` module. All checks have been
174176
moved to the ``fuchsia`` module instead. The ``zircon`` module will be removed

clang-tools-extra/docs/clang-tidy/index.rst

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,7 @@ An overview of all the command-line options:
329329
example, to place the correct user name in
330330
TODO() comments in the relevant check.
331331
WarningsAsErrors - Same as '--warnings-as-errors'.
332-
RemovedArgs - List of arguments to remove from the command
333-
line sent to the compiler. Please note that
334-
removing arguments might change the semantic
335-
of the analzed code, possibly leading to
336-
compiler errors, false positives or
337-
false negatives. This option is applied
338-
before --extra-arg and --extra-arg-before
332+
RemovedArgs - Same as '--removed-arg'
339333
340334
The effective configuration can be inspected using --dump-config:
341335
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: not clang-tidy %s -- -fnot-an-option | FileCheck %s -check-prefix=INVALID-A
22
// RUN: clang-tidy %s --config="{RemovedArgs: ['-fnot-an-option']}" -- -fnot-an-option
33
// RUN: clang-tidy %s --config="{RemovedArgs: ['-fnot-another-option', '-fnot-an-option']}" -- -fnot-an-option -fnot-another-option
4-
// RUN clang-tidy %s --removed-arg="-fnot-an-option" -- -fnot-an-option -fnot-another-option | FileCheck %s -check-prefix=INVALID-B
4+
// RUN: not clang-tidy %s --removed-arg="-fnot-an-option" -- -fnot-an-option -fnot-another-option | FileCheck %s -check-prefix=INVALID-B
55

66
// INVALID-A: error: unknown argument: '-fnot-an-option' [clang-diagnostic-error]
77
// INVALID-B: error: unknown argument: '-fnot-another-option' [clang-diagnostic-error]

0 commit comments

Comments
 (0)