From 64f7c65f270bd432075e653f011e7bfb55e560a2 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Tue, 9 Nov 2021 09:53:03 -0800 Subject: [PATCH] Use clang-tidy config file from repo instead of default (flutter/engine#29595) --- .../src/flutter/tools/clang_tidy/lib/clang_tidy.dart | 2 +- .../flutter/tools/clang_tidy/lib/src/command.dart | 9 +++++++-- .../flutter/tools/clang_tidy/lib/src/options.dart | 10 ++++------ .../tools/clang_tidy/test/clang_tidy_test.dart | 12 +++++++++++- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/tools/clang_tidy/lib/clang_tidy.dart b/engine/src/flutter/tools/clang_tidy/lib/clang_tidy.dart index d5bc169471..2cdd81d8ec 100644 --- a/engine/src/flutter/tools/clang_tidy/lib/clang_tidy.dart +++ b/engine/src/flutter/tools/clang_tidy/lib/clang_tidy.dart @@ -184,7 +184,7 @@ class ClangTidy { Future<_ComputeJobsResult> _computeJobs( List commands, io.Directory repoPath, - String checks, + String? checks, ) async { bool sawMalformed = false; final List jobs = []; diff --git a/engine/src/flutter/tools/clang_tidy/lib/src/command.dart b/engine/src/flutter/tools/clang_tidy/lib/src/command.dart index 9fedf28768..73cbca7f40 100644 --- a/engine/src/flutter/tools/clang_tidy/lib/src/command.dart +++ b/engine/src/flutter/tools/clang_tidy/lib/src/command.dart @@ -126,8 +126,13 @@ class Command { } /// The job for the process runner for the lint needed for this command. - WorkerJob createLintJob(String checks) { - final List args = [filePath, checks, '--']; + WorkerJob createLintJob(String? checks) { + final List args = [ + filePath, + if (checks != null) + checks, + '--', + ]; args.addAll(tidyArgs.split(' ')); return WorkerJob( [tidyPath, ...args], diff --git a/engine/src/flutter/tools/clang_tidy/lib/src/options.dart b/engine/src/flutter/tools/clang_tidy/lib/src/options.dart index 2af805d52f..9efa28da37 100644 --- a/engine/src/flutter/tools/clang_tidy/lib/src/options.dart +++ b/engine/src/flutter/tools/clang_tidy/lib/src/options.dart @@ -19,10 +19,8 @@ class Options { this.lintAll = false, this.errorMessage, StringSink? errSink, - }) { - checks = checksArg.isNotEmpty ? '--checks=$checksArg' : '--config='; - _errSink = errSink ?? io.stderr; - } + }) : checks = checksArg.isNotEmpty ? '--checks=$checksArg' : null, + _errSink = errSink ?? io.stderr; factory Options._error( String message, { @@ -131,7 +129,7 @@ class Options { final String checksArg; /// Check arguments to plumb through to clang-tidy. - late final String checks; + final String? checks; /// Whether all files should be linted. final bool lintAll; @@ -140,7 +138,7 @@ class Options { /// contains the error message. final String? errorMessage; - late final StringSink _errSink; + final StringSink _errSink; /// Print command usage with an additional message. void printUsage({String? message}) { diff --git a/engine/src/flutter/tools/clang_tidy/test/clang_tidy_test.dart b/engine/src/flutter/tools/clang_tidy/test/clang_tidy_test.dart index 6dc15762bd..9ca27010c4 100644 --- a/engine/src/flutter/tools/clang_tidy/test/clang_tidy_test.dart +++ b/engine/src/flutter/tools/clang_tidy/test/clang_tidy_test.dart @@ -7,6 +7,7 @@ import 'dart:io' as io show Directory, File, Platform, stderr; import 'package:clang_tidy/clang_tidy.dart'; import 'package:clang_tidy/src/command.dart'; import 'package:litetest/litetest.dart'; +import 'package:process_runner/process_runner.dart'; Future main(List args) async { if (args.length < 2) { @@ -199,7 +200,16 @@ Future main(List args) async { ); expect(commands, isNotEmpty); - expect(commands.first.tidyPath, contains('clang/bin/clang-tidy')); + final Command command = commands.first; + expect(command.tidyPath, contains('clang/bin/clang-tidy')); + final WorkerJob job = command.createLintJob(null); + expect(job.command, [ + '../../buildtools/mac-x64/clang/bin/clang-tidy', + filePath, + '--', + '', + filePath, + ]); }); test('Command getLintAction flags third_party files', () async {