Count non-null-safe code in our tech debt benchmark (#83846)
This commit is contained in:
parent
cf7ed18da1
commit
243d889445
@ -22,6 +22,7 @@ dependencies:
|
||||
async: 2.7.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
boolean_selector: 2.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
charcode: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
checked_yaml: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
cli_util: 0.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
collection: 1.15.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
convert: 3.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
@ -33,6 +34,7 @@ dependencies:
|
||||
http_multi_server: 3.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
io: 1.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
js: 0.6.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
json_annotation: 4.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
logging: 1.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
matcher: 0.12.10 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
mime: 1.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
@ -41,6 +43,7 @@ dependencies:
|
||||
pedantic: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
pool: 1.5.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
pub_semver: 2.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
pubspec_parse: 1.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
shelf: 1.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
shelf_packages_handler: 3.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
shelf_static: 1.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
@ -63,4 +66,4 @@ dependencies:
|
||||
dev_dependencies:
|
||||
test_api: 0.4.0
|
||||
|
||||
# PUBSPEC CHECKSUM: 08fb
|
||||
# PUBSPEC CHECKSUM: 9c84
|
||||
|
@ -9,6 +9,8 @@ import 'package:flutter_devicelab/framework/framework.dart';
|
||||
import 'package:flutter_devicelab/framework/task_result.dart';
|
||||
import 'package:flutter_devicelab/framework/utils.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:pub_semver/pub_semver.dart';
|
||||
import 'package:pubspec_parse/pubspec_parse.dart';
|
||||
|
||||
// the numbers below are prime, so that the totals don't seem round. :-)
|
||||
const double todoCost = 1009.0; // about two average SWE days, in dollars
|
||||
@ -19,6 +21,8 @@ const double ignoreForFileCost = 2477.0; // similar thinking as skipCost
|
||||
const double asDynamicCost = 2011.0; // a few days to refactor the code.
|
||||
const double deprecationCost = 233.0; // a few hours to remove the old code.
|
||||
const double legacyDeprecationCost = 9973.0; // a couple of weeks.
|
||||
const double packageNullSafetyMigrationCost = 2017.0; // a few days to migrate package.
|
||||
const double fileNullSafetyMigrationCost = 257.0; // a few hours to migrate file.
|
||||
|
||||
final RegExp todoPattern = RegExp(r'(?://|#) *TODO');
|
||||
final RegExp ignorePattern = RegExp(r'// *ignore:');
|
||||
@ -27,6 +31,9 @@ final RegExp asDynamicPattern = RegExp(r'\bas dynamic\b');
|
||||
final RegExp deprecationPattern = RegExp(r'^ *@[dD]eprecated');
|
||||
const Pattern globalsPattern = 'globals.';
|
||||
const String legacyDeprecationPattern = '// flutter_ignore: deprecation_syntax, https';
|
||||
final RegExp dartVersionPattern = RegExp(r'// *@dart *= *(\d+).(\d+)');
|
||||
|
||||
final Version firstNullSafeDartVersion = Version(2, 12, 0);
|
||||
|
||||
Future<double> findCostsForFile(File file) async {
|
||||
if (path.extension(file.path) == '.py')
|
||||
@ -36,6 +43,7 @@ Future<double> findCostsForFile(File file) async {
|
||||
path.extension(file.path) != '.sh')
|
||||
return 0.0;
|
||||
final bool isTest = file.path.endsWith('_test.dart');
|
||||
final bool isDart = file.path.endsWith('.dart');
|
||||
double total = 0.0;
|
||||
for (final String line in await file.readAsLines()) {
|
||||
if (line.contains(todoPattern))
|
||||
@ -52,10 +60,34 @@ Future<double> findCostsForFile(File file) async {
|
||||
total += legacyDeprecationCost;
|
||||
if (isTest && line.contains('skip:'))
|
||||
total += skipCost;
|
||||
if (isDart && isOptingOutOfNullSafety(line))
|
||||
total += fileNullSafetyMigrationCost;
|
||||
}
|
||||
if (path.basename(file.path) == 'pubspec.yaml' && !packageIsNullSafe(file))
|
||||
total += packageNullSafetyMigrationCost;
|
||||
return total;
|
||||
}
|
||||
|
||||
bool isOptingOutOfNullSafety(String line) {
|
||||
final RegExpMatch match = dartVersionPattern.firstMatch(line);
|
||||
if (match == null) {
|
||||
return false;
|
||||
}
|
||||
assert(match.groupCount == 2);
|
||||
return Version(int.parse(match.group(1)), int.parse(match.group(2)), 0) < firstNullSafeDartVersion;
|
||||
}
|
||||
|
||||
bool packageIsNullSafe(File file) {
|
||||
assert(path.basename(file.path) == 'pubspec.yaml');
|
||||
final Pubspec pubspec = Pubspec.parse(file.readAsStringSync());
|
||||
final VersionConstraint constraint = pubspec.environment == null ? null : pubspec.environment['sdk'];
|
||||
final bool hasConstraint = constraint != null && !constraint.isAny && !constraint.isEmpty;
|
||||
return hasConstraint &&
|
||||
constraint is VersionRange &&
|
||||
constraint.min != null &&
|
||||
Version(constraint.min.major, constraint.min.minor, 0) >= firstNullSafeDartVersion;
|
||||
}
|
||||
|
||||
Future<int> findGlobalsForFile(File file) async {
|
||||
if (path.extension(file.path) != '.dart')
|
||||
return 0;
|
||||
|
@ -15,20 +15,25 @@ dependencies:
|
||||
path: 1.8.0
|
||||
platform: 3.0.0
|
||||
process: 4.2.1
|
||||
pubspec_parse: 1.0.0
|
||||
stack_trace: 1.10.0
|
||||
|
||||
logging: 1.0.1
|
||||
|
||||
async: 2.7.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
charcode: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
checked_yaml: 2.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
collection: 1.15.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
crypto: 3.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
http_parser: 4.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
json_annotation: 4.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
pedantic: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
pub_semver: 2.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
source_span: 1.8.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
string_scanner: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
term_glyph: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
typed_data: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
yaml: 3.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
|
||||
dev_dependencies:
|
||||
test: 1.17.5
|
||||
@ -49,7 +54,6 @@ dev_dependencies:
|
||||
node_preamble: 2.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
package_config: 2.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
pool: 1.5.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
pub_semver: 2.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
shelf: 1.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
shelf_packages_handler: 3.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
shelf_static: 1.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
@ -63,6 +67,5 @@ dev_dependencies:
|
||||
watcher: 1.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
web_socket_channel: 2.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
webkit_inspection_protocol: 1.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
yaml: 3.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
|
||||
# PUBSPEC CHECKSUM: 08fb
|
||||
# PUBSPEC CHECKSUM: 9c84
|
||||
|
Loading…
x
Reference in New Issue
Block a user