Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7e46cf8

Browse files
authored
Use clang-tidy config file from repo instead of default (#29595)
1 parent 6db13a9 commit 7e46cf8

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

tools/clang_tidy/lib/clang_tidy.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class ClangTidy {
184184
Future<_ComputeJobsResult> _computeJobs(
185185
List<Command> commands,
186186
io.Directory repoPath,
187-
String checks,
187+
String? checks,
188188
) async {
189189
bool sawMalformed = false;
190190
final List<WorkerJob> jobs = <WorkerJob>[];

tools/clang_tidy/lib/src/command.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,13 @@ class Command {
126126
}
127127

128128
/// The job for the process runner for the lint needed for this command.
129-
WorkerJob createLintJob(String checks) {
130-
final List<String> args = <String>[filePath, checks, '--'];
129+
WorkerJob createLintJob(String? checks) {
130+
final List<String> args = <String>[
131+
filePath,
132+
if (checks != null)
133+
checks,
134+
'--',
135+
];
131136
args.addAll(tidyArgs.split(' '));
132137
return WorkerJob(
133138
<String>[tidyPath, ...args],

tools/clang_tidy/lib/src/options.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ class Options {
1919
this.lintAll = false,
2020
this.errorMessage,
2121
StringSink? errSink,
22-
}) {
23-
checks = checksArg.isNotEmpty ? '--checks=$checksArg' : '--config=';
24-
_errSink = errSink ?? io.stderr;
25-
}
22+
}) : checks = checksArg.isNotEmpty ? '--checks=$checksArg' : null,
23+
_errSink = errSink ?? io.stderr;
2624

2725
factory Options._error(
2826
String message, {
@@ -131,7 +129,7 @@ class Options {
131129
final String checksArg;
132130

133131
/// Check arguments to plumb through to clang-tidy.
134-
late final String checks;
132+
final String? checks;
135133

136134
/// Whether all files should be linted.
137135
final bool lintAll;
@@ -140,7 +138,7 @@ class Options {
140138
/// contains the error message.
141139
final String? errorMessage;
142140

143-
late final StringSink _errSink;
141+
final StringSink _errSink;
144142

145143
/// Print command usage with an additional message.
146144
void printUsage({String? message}) {

tools/clang_tidy/test/clang_tidy_test.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:io' as io show Directory, File, Platform, stderr;
77
import 'package:clang_tidy/clang_tidy.dart';
88
import 'package:clang_tidy/src/command.dart';
99
import 'package:litetest/litetest.dart';
10+
import 'package:process_runner/process_runner.dart';
1011

1112
Future<int> main(List<String> args) async {
1213
if (args.length < 2) {
@@ -199,7 +200,16 @@ Future<int> main(List<String> args) async {
199200
);
200201

201202
expect(commands, isNotEmpty);
202-
expect(commands.first.tidyPath, contains('clang/bin/clang-tidy'));
203+
final Command command = commands.first;
204+
expect(command.tidyPath, contains('clang/bin/clang-tidy'));
205+
final WorkerJob job = command.createLintJob(null);
206+
expect(job.command, <String>[
207+
'../../buildtools/mac-x64/clang/bin/clang-tidy',
208+
filePath,
209+
'--',
210+
'',
211+
filePath,
212+
]);
203213
});
204214

205215
test('Command getLintAction flags third_party files', () async {

0 commit comments

Comments
 (0)