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

Commit f4600a9

Browse files
authored
Revert "Enable clang-tidy for pre-push (opt-out), exclude performance-unnecessary-value-param (#44936)"
This reverts commit 4d1050f.
1 parent decc8f7 commit f4600a9

File tree

10 files changed

+53
-349
lines changed

10 files changed

+53
-349
lines changed

.clang-tidy

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
1-
# These checks are run by the CI presubmit script, but are not run by the
2-
# githooks presubmit script. The githooks presubmit script runs a subset of
3-
# these checks.
4-
#
5-
# See "./tools/clang_tidy/lib/src/hooks_exclude.dart".
6-
Checks: >-
7-
bugprone-use-after-move,
8-
bugprone-unchecked-optional-access,
9-
clang-analyzer-*,
10-
clang-diagnostic-*,
11-
darwin-*,
12-
google-*,
13-
modernize-use-default-member-init,
14-
objc-*,
15-
-objc-nsinvocation-argument-lifetime,
16-
readability-identifier-naming,
17-
-google-build-using-namespace,
18-
-google-default-arguments,
19-
-google-objc-global-variable-declaration,
20-
-google-objc-avoid-throwing-exception,
21-
-google-readability-casting,
22-
-clang-analyzer-nullability.NullPassedToNonnull,
23-
-clang-analyzer-nullability.NullablePassedToNonnull,
24-
-clang-analyzer-nullability.NullReturnedFromNonnull,
25-
-clang-analyzer-nullability.NullableReturnedFromNonnull,
26-
performance-move-const-arg,
27-
performance-unnecessary-value-param
1+
# Prefix check with "-" to ignore.
2+
# Note: Some of the checks here are used as errors selectively, see
3+
# //ci/lint.sh
4+
Checks: "bugprone-use-after-move,\
5+
bugprone-unchecked-optional-access,\
6+
clang-analyzer-*,\
7+
clang-diagnostic-*,\
8+
darwin-*,\
9+
google-*,\
10+
modernize-use-default-member-init,\
11+
objc-*,\
12+
-objc-nsinvocation-argument-lifetime,\
13+
readability-identifier-naming,\
14+
-google-build-using-namespace,\
15+
-google-default-arguments,\
16+
-google-objc-global-variable-declaration,\
17+
-google-objc-avoid-throwing-exception,\
18+
-google-readability-casting,\
19+
-clang-analyzer-nullability.NullPassedToNonnull,\
20+
-clang-analyzer-nullability.NullablePassedToNonnull,\
21+
-clang-analyzer-nullability.NullReturnedFromNonnull,\
22+
-clang-analyzer-nullability.NullableReturnedFromNonnull,\
23+
performance-move-const-arg,\
24+
performance-unnecessary-value-param"
2825

2926
CheckOptions:
3027
- key: modernize-use-default-member-init.UseAssignment

tools/clang_tidy/lib/clang_tidy.dart

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
// found in the LICENSE file.
44

55
import 'dart:convert' show LineSplitter, jsonDecode;
6-
import 'dart:io' as io show Directory, File, stderr, stdout;
6+
import 'dart:io' as io show File, stderr, stdout;
77

88
import 'package:meta/meta.dart';
99
import 'package:path/path.dart' as path;
1010
import 'package:process_runner/process_runner.dart';
1111

1212
import 'src/command.dart';
1313
import 'src/git_repo.dart';
14-
import 'src/hooks_exclude.dart';
1514
import 'src/options.dart';
1615

1716
const String _linterOutputHeader = '''
@@ -48,8 +47,6 @@ class ClangTidy {
4847
/// an instance of [ClangTidy].
4948
///
5049
/// `buildCommandsPath` is the path to the build_commands.json file.
51-
/// `configPath` is a path to a `.clang-tidy` config file.
52-
/// `excludeSlowChecks` when true indicates that slow checks should be skipped.
5350
/// `repoPath` is the path to the Engine repo.
5451
/// `checksArg` are specific checks for clang-tidy to do.
5552
/// `lintAll` when true indicates that all files should be linted.
@@ -59,8 +56,6 @@ class ClangTidy {
5956
/// will otherwise go to stderr.
6057
ClangTidy({
6158
required io.File buildCommandsPath,
62-
io.File? configPath,
63-
bool excludeSlowChecks = false,
6459
String checksArg = '',
6560
bool lintAll = false,
6661
bool lintHead = false,
@@ -70,8 +65,6 @@ class ClangTidy {
7065
}) :
7166
options = Options(
7267
buildCommandsPath: buildCommandsPath,
73-
configPath: configPath,
74-
excludeSlowChecks: excludeSlowChecks,
7568
checksArg: checksArg,
7669
lintAll: lintAll,
7770
lintHead: lintHead,
@@ -161,20 +154,10 @@ class ClangTidy {
161154
);
162155
}
163156

164-
io.File? configPath = options.configPath;
165-
io.Directory? rewriteDir;
166-
if (configPath != null && options.excludeSlowChecks) {
167-
configPath = _createClangTidyConfigExcludingSlowLints(configPath);
168-
rewriteDir = io.Directory(path.dirname(configPath.path));
169-
}
170157
final _ComputeJobsResult computeJobsResult = await _computeJobs(
171158
changedFileBuildCommands,
172159
options,
173-
configPath,
174160
);
175-
if (rewriteDir != null) {
176-
rewriteDir.deleteSync(recursive: true);
177-
}
178161
final int computeResult = computeJobsResult.sawMalformed ? 1 : 0;
179162
final List<WorkerJob> jobs = computeJobsResult.jobs;
180163

@@ -308,7 +291,6 @@ class ClangTidy {
308291
Future<_ComputeJobsResult> _computeJobs(
309292
List<Command> commands,
310293
Options options,
311-
io.File? configPath,
312294
) async {
313295
bool sawMalformed = false;
314296
final List<WorkerJob> jobs = <WorkerJob>[];
@@ -329,7 +311,7 @@ class ClangTidy {
329311
sawMalformed = true;
330312
case LintAction.lint:
331313
_outSink.writeln('🔶 linting $relativePath');
332-
jobs.add(command.createLintJob(options, withPath: configPath));
314+
jobs.add(command.createLintJob(options));
333315
case LintAction.skipThirdParty:
334316
_outSink.writeln('🔷 ignoring $relativePath (third_party)');
335317
case LintAction.skipMissing:
@@ -339,10 +321,6 @@ class ClangTidy {
339321
return _ComputeJobsResult(jobs, sawMalformed);
340322
}
341323

342-
static io.File _createClangTidyConfigExcludingSlowLints(io.File configPath) {
343-
return rewriteClangTidyConfig(configPath);
344-
}
345-
346324
static Iterable<String> _trimGenerator(String output) sync* {
347325
const LineSplitter splitter = LineSplitter();
348326
final List<String> lines = splitter.convert(output);

tools/clang_tidy/lib/src/command.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,10 @@ class Command {
131131
}
132132

133133
/// The job for the process runner for the lint needed for this command.
134-
WorkerJob createLintJob(Options options, {io.File? withPath}) {
134+
WorkerJob createLintJob(Options options) {
135135
final List<String> args = <String>[
136136
filePath,
137137
'--warnings-as-errors=${options.warningsAsErrors ?? '*'}',
138-
if (options.configPath != null)
139-
'--config-file=${withPath != null ? withPath.path : options.configPath}',
140138
if (options.checks != null)
141139
options.checks!,
142140
if (options.fix) ...<String>[

tools/clang_tidy/lib/src/hooks_exclude.dart

Lines changed: 0 additions & 40 deletions
This file was deleted.

tools/clang_tidy/lib/src/options.dart

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class Options {
2828
required this.buildCommandsPath,
2929
this.help = false,
3030
this.verbose = false,
31-
this.configPath,
32-
this.excludeSlowChecks = false,
3331
this.checksArg = '',
3432
this.lintAll = false,
3533
this.lintHead = false,
@@ -76,8 +74,6 @@ class Options {
7674
help: options['help'] as bool,
7775
verbose: options['verbose'] as bool,
7876
buildCommandsPath: buildCommandsPath,
79-
configPath: options.wasParsed('config-file') ? io.File(options['config-file'] as String) : null,
80-
excludeSlowChecks: options['exclude-slow-checks'] as bool,
8177
checksArg: options.wasParsed('checks') ? options['checks'] as String : '',
8278
lintAll: io.Platform.environment['FLUTTER_LINT_ALL'] != null ||
8379
options['lint-all'] as bool,
@@ -201,16 +197,6 @@ class Options {
201197
'string, indicating all checks should be performed.',
202198
defaultsTo: '',
203199
)
204-
..addOption(
205-
'config-file',
206-
help: 'Path to a .clang-tidy configuration file.',
207-
valueHelp: 'path/to/.clang-tidy',
208-
)
209-
..addFlag(
210-
'exclude-slow-checks',
211-
help: 'Exclude checks that are too slow for git hooks.',
212-
negatable: false,
213-
)
214200
..addFlag(
215201
'enable-check-profile',
216202
help: 'Enable per-check timing profiles and print a report to stderr.',
@@ -226,12 +212,6 @@ class Options {
226212
/// The location of the compile_commands.json file.
227213
final io.File buildCommandsPath;
228214

229-
/// A location of a `.clang-tidy` configuration file.
230-
final io.File? configPath;
231-
232-
/// Whether to exclude lints that are too slow for git hooks.
233-
final bool excludeSlowChecks;
234-
235215
/// The location of shard compile_commands.json files.
236216
final List<io.File> shardCommandsPaths;
237217

@@ -291,13 +271,6 @@ class Options {
291271
return 'ERROR: --compile-commands option cannot be used with --target-variant.';
292272
}
293273

294-
if (argResults.wasParsed('config-file')) {
295-
final io.File configPath = io.File(argResults['config-file'] as String);
296-
if (!configPath.existsSync()) {
297-
return 'ERROR: Config file ${configPath.path} does not exist.';
298-
}
299-
}
300-
301274
if (compileCommandsParsed && argResults.wasParsed('src-dir')) {
302275
return 'ERROR: --compile-commands option cannot be used with --src-dir.';
303276
}

tools/clang_tidy/test/clang_tidy_test.dart

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:io' as io show Directory, File, Platform, stderr;
66

77
import 'package:clang_tidy/clang_tidy.dart';
88
import 'package:clang_tidy/src/command.dart';
9-
import 'package:clang_tidy/src/hooks_exclude.dart';
109
import 'package:clang_tidy/src/options.dart';
1110
import 'package:litetest/litetest.dart';
1211
import 'package:path/path.dart' as path;
@@ -149,44 +148,6 @@ Future<int> main(List<String> args) async {
149148
print(outBuffer);
150149
});
151150

152-
test('Accepts --config-file', () async {
153-
// If buildCommands is in "$ENGINE/src/out/host_debug", then the config
154-
// file should be in "$ENGINE/src/flutter/.clang-tidy-for-githooks".
155-
late final String flutterRoot;
156-
157-
// Find the 'src' directory and append 'flutter/.clang-tidy-for-githooks'.
158-
{
159-
final List<String> buildCommandParts = path.split(path.absolute(buildCommands));
160-
for (int i = 0; i < buildCommandParts.length; ++i) {
161-
if (buildCommandParts[i] == 'src') {
162-
flutterRoot = path.joinAll(<String>[
163-
...buildCommandParts.sublist(0, i + 1),
164-
'flutter',
165-
]);
166-
break;
167-
}
168-
}
169-
}
170-
171-
final StringBuffer outBuffer = StringBuffer();
172-
final StringBuffer errBuffer = StringBuffer();
173-
final ClangTidy clangTidy = ClangTidy.fromCommandLine(
174-
<String>[
175-
'--compile-commands',
176-
buildCommands,
177-
'--config-file=${path.join(flutterRoot, '.clang-tidy')}',
178-
],
179-
outSink: outBuffer,
180-
errSink: errBuffer,
181-
);
182-
183-
final int result = await clangTidy.run();
184-
185-
expect(result, equals(0));
186-
expect(clangTidy.options.configPath?.path, endsWith('.clang-tidy'));
187-
print(outBuffer);
188-
});
189-
190151
test('shard-id valid', () async {
191152
_withTempFile('shard-id-valid', (String path) {
192153
final Options options = Options.fromCommandLine( <String>[
@@ -517,38 +478,5 @@ Future<int> main(List<String> args) async {
517478
expect(lintAction, equals(LintAction.lint));
518479
});
519480

520-
test('rewriteClangTidyConfig should remove "performance-unnecessary-value-param"', () {
521-
final io.Directory tmpDir = io.Directory.systemTemp.createTempSync('clang_tidy_test');
522-
523-
final io.File input = io.File(path.join(tmpDir.path, '.clang-tidy'));
524-
input.writeAsStringSync('''
525-
Checks: >-
526-
bugprone-use-after-move,
527-
bugprone-unchecked-optional-access,
528-
clang-analyzer-*,
529-
clang-diagnostic-*,
530-
darwin-*,
531-
google-*,
532-
modernize-use-default-member-init,
533-
objc-*,
534-
-objc-nsinvocation-argument-lifetime,
535-
readability-identifier-naming,
536-
-google-build-using-namespace,
537-
-google-default-arguments,
538-
-google-objc-global-variable-declaration,
539-
-google-objc-avoid-throwing-exception,
540-
-google-readability-casting,
541-
-clang-analyzer-nullability.NullPassedToNonnull,
542-
-clang-analyzer-nullability.NullablePassedToNonnull,
543-
-clang-analyzer-nullability.NullReturnedFromNonnull,
544-
-clang-analyzer-nullability.NullableReturnedFromNonnull,
545-
performance-move-const-arg,
546-
performance-unnecessary-value-param
547-
''');
548-
549-
final io.File output = rewriteClangTidyConfig(input);
550-
expect(output.readAsStringSync().contains('performance-unnecessary-value-param'), isFalse);
551-
});
552-
553481
return 0;
554482
}

0 commit comments

Comments
 (0)