Skip to content

Commit 4f5aacf

Browse files
pqCommit Queue
authored andcommitted
[CQ] bump analyzer_cli to 3.7 and tall-style re-format
Change-Id: Ic0e1e33da71036800432aa3dae8df22dbef8a460 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404343 Reviewed-by: Konstantin Shcheglov <[email protected]> Auto-Submit: Phil Quitslund <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent e470c55 commit 4f5aacf

20 files changed

+654
-404
lines changed

pkg/analyzer_cli/lib/src/analyzer_impl.dart

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,30 @@ class AnalyzerImpl {
4646
/// specified the "--package-warnings" option.
4747
String? _selfPackageName;
4848

49-
AnalyzerImpl(this.analysisOptions, this.analysisDriver, this.libraryFile,
50-
this.options, this.stats, this.startTime);
49+
AnalyzerImpl(
50+
this.analysisOptions,
51+
this.analysisDriver,
52+
this.libraryFile,
53+
this.options,
54+
this.stats,
55+
this.startTime,
56+
);
5157

5258
void addCompilationUnitSource(
53-
LibraryFragment unit, Set<LibraryFragment> units) {
59+
LibraryFragment unit,
60+
Set<LibraryFragment> units,
61+
) {
5462
if (!units.add(unit)) {
5563
return;
5664
}
5765
files.add(unit.source.fullName);
5866
}
5967

60-
void addLibrarySources(LibraryElement2 library,
61-
Set<LibraryElement2> libraries, Set<LibraryFragment> units) {
68+
void addLibrarySources(
69+
LibraryElement2 library,
70+
Set<LibraryElement2> libraries,
71+
Set<LibraryFragment> units,
72+
) {
6273
if (!libraries.add(library)) {
6374
return;
6475
}
@@ -93,8 +104,10 @@ class AnalyzerImpl {
93104
/// information is printed. If [printMode] is `1`, then errors will be printed.
94105
/// If [printMode] is `2`, then performance information will be printed, and
95106
/// it will be marked as being for a cold VM.
96-
Future<ErrorSeverity> analyze(ErrorFormatter formatter,
97-
{int printMode = 1}) async {
107+
Future<ErrorSeverity> analyze(
108+
ErrorFormatter formatter, {
109+
int printMode = 1,
110+
}) async {
98111
setupForAnalysis();
99112
return await _analyze(printMode, formatter);
100113
}
@@ -141,7 +154,9 @@ class AnalyzerImpl {
141154
}
142155

143156
Future<ErrorSeverity> _analyze(
144-
int printMode, ErrorFormatter formatter) async {
157+
int printMode,
158+
ErrorFormatter formatter,
159+
) async {
145160
// Don't try to analyze parts.
146161
if (libraryFile.kind is! LibraryFileKind) {
147162
var libraryPath = libraryFile.path;
@@ -235,9 +250,11 @@ class StdInstrumentation extends NoopInstrumentationService {
235250
}
236251

237252
@override
238-
void logException(dynamic exception,
239-
[StackTrace? stackTrace,
240-
List<InstrumentationServiceAttachment>? attachments = const []]) {
253+
void logException(
254+
dynamic exception, [
255+
StackTrace? stackTrace,
256+
List<InstrumentationServiceAttachment>? attachments = const [],
257+
]) {
241258
errorSink.writeln(exception);
242259
errorSink.writeln(stackTrace);
243260
}

pkg/analyzer_cli/lib/src/batch_mode.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class BatchRunner {
3434
if (line.isEmpty) {
3535
var time = stopwatch.elapsedMilliseconds;
3636
outSink.writeln(
37-
'>>> BATCH END (${totalTests - testsFailed}/$totalTests) ${time}ms');
37+
'>>> BATCH END (${totalTests - testsFailed}/$totalTests) ${time}ms',
38+
);
3839
exitCode = batchResult.ordinal;
3940
}
4041
// Prepare arguments.
@@ -57,7 +58,8 @@ class BatchRunner {
5758
errorSink.writeln('>>> EOF STDERR');
5859
var resultPassString = resultPass ? 'PASS' : 'FAIL';
5960
outSink.writeln(
60-
'>>> TEST $resultPassString ${stopwatch.elapsedMilliseconds}ms');
61+
'>>> TEST $resultPassString ${stopwatch.elapsedMilliseconds}ms',
62+
);
6163
} catch (e, stackTrace) {
6264
errorSink.writeln(e);
6365
errorSink.writeln(stackTrace);

pkg/analyzer_cli/lib/src/driver.dart

Lines changed: 94 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,29 @@ class Driver implements CommandLineStarter {
144144

145145
if (options.perfReport != null) {
146146
var json = makePerfReport(
147-
startTime, currentTimeMillis, options, _analyzedFileCount, stats);
147+
startTime,
148+
currentTimeMillis,
149+
options,
150+
_analyzedFileCount,
151+
stats,
152+
);
148153
io.File(options.perfReport!).writeAsStringSync(json);
149154
}
150155
}
151156

152157
/// Perform analysis according to the given [options].
153158
Future<ErrorSeverity> _analyzeAll(CommandLineOptions options) async {
154159
if (!options.jsonFormat && !options.machineFormat) {
155-
var fileNames = options.sourceFiles.map((String file) {
156-
file = path.normalize(file);
157-
if (file == '.') {
158-
file = path.basename(path.current);
159-
} else if (file == '..') {
160-
file = path.basename(path.normalize(path.absolute(file)));
161-
}
162-
return file;
163-
}).toList();
160+
var fileNames =
161+
options.sourceFiles.map((String file) {
162+
file = path.normalize(file);
163+
if (file == '.') {
164+
file = path.basename(path.current);
165+
} else if (file == '..') {
166+
file = path.basename(path.normalize(path.absolute(file)));
167+
}
168+
return file;
169+
}).toList();
164170

165171
outSink.writeln("Analyzing ${fileNames.join(', ')}...");
166172
}
@@ -179,7 +185,10 @@ class Driver implements CommandLineStarter {
179185
var filePath = error.source.fullName;
180186
var file = analysisDriver!.resourceProvider.getFile(filePath);
181187
return determineProcessedSeverity(
182-
error, options, analysisDriver!.getAnalysisOptionsForFile(file));
188+
error,
189+
options,
190+
analysisDriver!.getAnalysisOptionsForFile(file),
191+
);
183192
};
184193

185194
// We currently print out to stderr to ensure that when in batch mode we
@@ -190,16 +199,28 @@ class Driver implements CommandLineStarter {
190199
// batch flag and source file" error message.
191200
ErrorFormatter formatter;
192201
if (options.jsonFormat) {
193-
formatter = JsonErrorFormatter(outSink, options, stats,
194-
severityProcessor: defaultSeverityProcessor);
202+
formatter = JsonErrorFormatter(
203+
outSink,
204+
options,
205+
stats,
206+
severityProcessor: defaultSeverityProcessor,
207+
);
195208
} else if (options.machineFormat) {
196209
// The older machine format emits to stderr (instead of stdout) for legacy
197210
// reasons.
198-
formatter = MachineErrorFormatter(errorSink, options, stats,
199-
severityProcessor: defaultSeverityProcessor);
211+
formatter = MachineErrorFormatter(
212+
errorSink,
213+
options,
214+
stats,
215+
severityProcessor: defaultSeverityProcessor,
216+
);
200217
} else {
201-
formatter = HumanErrorFormatter(outSink, options, stats,
202-
severityProcessor: defaultSeverityProcessor);
218+
formatter = HumanErrorFormatter(
219+
outSink,
220+
options,
221+
stats,
222+
severityProcessor: defaultSeverityProcessor,
223+
);
203224
}
204225

205226
var allResult = ErrorSeverity.NONE;
@@ -275,11 +296,14 @@ class Driver implements CommandLineStarter {
275296
isPart: false,
276297
errors: errors,
277298
analysisOptions: analysisOptions,
278-
)
299+
),
279300
]);
280301
for (var error in errors) {
281-
var severity =
282-
determineProcessedSeverity(error, options, analysisOptions);
302+
var severity = determineProcessedSeverity(
303+
error,
304+
options,
305+
analysisOptions,
306+
);
283307
if (severity != null) {
284308
allResult = allResult.max(severity);
285309
}
@@ -294,17 +318,23 @@ class Driver implements CommandLineStarter {
294318
var node = loadYamlNode(content, sourceUrl: file.toUri());
295319

296320
if (node is YamlMap) {
297-
errors.addAll(validatePubspec(
298-
contents: node,
299-
source: FileSource(file),
300-
provider: resourceProvider,
301-
analysisOptions: analysisOptions,
302-
));
321+
errors.addAll(
322+
validatePubspec(
323+
contents: node,
324+
source: FileSource(file),
325+
provider: resourceProvider,
326+
analysisOptions: analysisOptions,
327+
),
328+
);
303329
}
304330
if (errors.isNotEmpty) {
305331
for (var error in errors) {
306-
var severity = determineProcessedSeverity(
307-
error, options, analysisOptions)!;
332+
var severity =
333+
determineProcessedSeverity(
334+
error,
335+
options,
336+
analysisOptions,
337+
)!;
308338
allResult = allResult.max(severity);
309339
}
310340
var lineInfo = LineInfo.fromContent(content);
@@ -329,14 +359,17 @@ class Driver implements CommandLineStarter {
329359
} else if (file_paths.isAndroidManifestXml(pathContext, path)) {
330360
try {
331361
var file = resourceProvider.getFile(path);
332-
var analysisOptions =
333-
analysisDriver.getAnalysisOptionsForFile(file);
362+
var analysisOptions = analysisDriver.getAnalysisOptionsForFile(
363+
file,
364+
);
334365
var content = file.readAsStringSync();
335366
var source = FileSource(file);
336367
var validator = ManifestValidator(source);
337368
var lineInfo = LineInfo.fromContent(content);
338369
var errors = validator.validate(
339-
content, analysisOptions.chromeOsManifestChecks);
370+
content,
371+
analysisOptions.chromeOsManifestChecks,
372+
);
340373
await formatter.formatErrors([
341374
ErrorsResultImpl(
342375
session: analysisDriver.currentSession,
@@ -409,8 +442,10 @@ class Driver implements CommandLineStarter {
409442
var directory = io.Directory(filePath);
410443
if (directory.existsSync()) {
411444
var pathContext = resourceProvider.pathContext;
412-
for (var entry
413-
in directory.listSync(recursive: true, followLinks: false)) {
445+
for (var entry in directory.listSync(
446+
recursive: true,
447+
followLinks: false,
448+
)) {
414449
var relative = path.relative(entry.path, from: directory.path);
415450
if ((file_paths.isDart(pathContext, entry.path) ||
416451
file_paths.isAndroidManifestXml(pathContext, entry.path)) &&
@@ -431,13 +466,23 @@ class Driver implements CommandLineStarter {
431466

432467
/// Analyze a single source.
433468
Future<ErrorSeverity> _runAnalyzer(
434-
FileState file, CommandLineOptions options, ErrorFormatter formatter) {
469+
FileState file,
470+
CommandLineOptions options,
471+
ErrorFormatter formatter,
472+
) {
435473
var startTime = currentTimeMillis;
436474
final analysisDriver = this.analysisDriver!;
437-
var analysisOptions =
438-
analysisDriver.getAnalysisOptionsForFile(file.resource);
475+
var analysisOptions = analysisDriver.getAnalysisOptionsForFile(
476+
file.resource,
477+
);
439478
var analyzer = AnalyzerImpl(
440-
analysisOptions, analysisDriver, file, options, stats, startTime);
479+
analysisOptions,
480+
analysisDriver,
481+
file,
482+
options,
483+
stats,
484+
startTime,
485+
);
441486
return analyzer.analyze(formatter);
442487
}
443488

@@ -448,8 +493,10 @@ class Driver implements CommandLineStarter {
448493
var path = options.defaultAnalysisOptionsPath;
449494
if (path != null) {
450495
if (!resourceProvider.getFile(path).exists) {
451-
printAndFail('Options file not found: $path',
452-
exitCode: ErrorSeverity.ERROR.ordinal);
496+
printAndFail(
497+
'Options file not found: $path',
498+
exitCode: ErrorSeverity.ERROR.ordinal,
499+
);
453500
}
454501
}
455502
}
@@ -460,7 +507,9 @@ class Driver implements CommandLineStarter {
460507

461508
/// Return whether the [newOptions] are equal to the [previous].
462509
static bool _equalCommandLineOptions(
463-
CommandLineOptions? previous, CommandLineOptions newOptions) {
510+
CommandLineOptions? previous,
511+
CommandLineOptions newOptions,
512+
) {
464513
return previous != null &&
465514
newOptions.defaultPackagesPath == previous.defaultPackagesPath &&
466515
_equalMaps(newOptions.declaredVariables, previous.declaredVariables) &&
@@ -509,7 +558,7 @@ class _AnalysisContextProvider {
509558
DriverBasedAnalysisContext? _analysisContext;
510559

511560
_AnalysisContextProvider(this._resourceProvider)
512-
: _fileContentCache = FileContentCache(_resourceProvider);
561+
: _fileContentCache = FileContentCache(_resourceProvider);
513562

514563
DriverBasedAnalysisContext? get analysisContext {
515564
return _analysisContext;
@@ -531,11 +580,10 @@ class _AnalysisContextProvider {
531580

532581
// Exclude patterns are relative to the directory with the options file.
533582
return PathFilter(
534-
contextRoot.root.path,
535-
optionsFile.parent.path,
536-
analysisContext!
537-
.getAnalysisOptionsForFile(optionsFile)
538-
.excludePatterns);
583+
contextRoot.root.path,
584+
optionsFile.parent.path,
585+
analysisContext!.getAnalysisOptionsForFile(optionsFile).excludePatterns,
586+
);
539587
}
540588

541589
void configureForPath(String path) {

0 commit comments

Comments
 (0)