flutter/dev/devicelab/bin/tasks/technical_debt__cost.dart
Ian Hickson 809721d0ee
Revert "Track number of package dependencies in Flutter" (#20774)
* Revert "Deprecated CupertinoDialog in favor of a new widget called CupertinoP… (#20649)"

This reverts commit 3a4ae280e3.

* Revert "Feature pesto new recipes (#19415)"

This reverts commit e2f3b3d6f2.

* Revert "Use markdown table (#20721)"

This reverts commit 82d43b952a.

* Revert "Documentation regarding tap gesture callbacks (#20647)"

This reverts commit 3acc278521.

* Revert "Add branch to footer information in flutter docs (#20711)"

This reverts commit 9118d3d715.

* Revert "Performance test cleanup (#20652)"

This reverts commit 1993a67381.

* Revert "Track number of package dependencies in Flutter (#20722)"

This reverts commit 03d6f18f4a.
2018-08-17 18:34:05 -07:00

67 lines
2.5 KiB
Dart

// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:path/path.dart' as path;
// the numbers below are odd, so that the totals don't seem round. :-)
const double todoCost = 1009.0; // about two average SWE days, in dollars
const double ignoreCost = 2003.0; // four average SWE days, in dollars
const double pythonCost = 3001.0; // six average SWE days, in dollars
const double skipCost = 2473.0; // 20 hours: 5 to fix the issue we're ignoring, 15 to fix the bugs we missed because the test was off
const double asDynamicCost = 2003.0; // same as ignoring analyzer warning
final RegExp todoPattern = new RegExp(r'(?://|#) *TODO');
final RegExp ignorePattern = new RegExp(r'// *ignore:');
final RegExp asDynamicPattern = new RegExp(r'as dynamic');
Future<double> findCostsForFile(File file) async {
if (path.extension(file.path) == '.py')
return pythonCost;
if (path.extension(file.path) != '.dart' &&
path.extension(file.path) != '.yaml' &&
path.extension(file.path) != '.sh')
return 0.0;
final bool isTest = file.path.endsWith('_test.dart');
double total = 0.0;
for (String line in await file.readAsLines()) {
if (line.contains(todoPattern))
total += todoCost;
if (line.contains(ignorePattern))
total += ignoreCost;
if (line.contains(asDynamicPattern))
total += asDynamicCost;
if (isTest && line.contains('skip:'))
total += skipCost;
}
return total;
}
const String _kBenchmarkKey = 'technical_debt_in_dollars';
Future<Null> main() async {
await task(() async {
final Process git = await startProcess(
'git',
<String>['ls-files', '--full-name', flutterDirectory.path],
workingDirectory: flutterDirectory.path,
);
double total = 0.0;
await for (String entry in git.stdout.transform(utf8.decoder).transform(const LineSplitter()))
total += await findCostsForFile(new File(path.join(flutterDirectory.path, entry)));
final int gitExitCode = await git.exitCode;
if (gitExitCode != 0)
throw new Exception('git exit with unexpected error code $gitExitCode');
return new TaskResult.success(
<String, dynamic>{_kBenchmarkKey: total},
benchmarkScoreKeys: <String>[_kBenchmarkKey],
);
});
}