Skip to content

Commit b8f4b25

Browse files
devoncarewcommit-bot@chromium.org
authored andcommitted
move pkg/telemetry to using package:lints
Change-Id: I75130cc8d5964ef0f95a672858da8bbce8ffd78c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/200520 Commit-Queue: Devon Carew <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 37a24ac commit b8f4b25

File tree

7 files changed

+41
-40
lines changed

7 files changed

+41
-40
lines changed

pkg/analysis_server/lib/src/server/driver.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class Driver implements ServerStarter {
201201
final crashReportSender =
202202
CrashReportSender.prod(crashProductId, shouldSendCallback);
203203

204-
if (telemetry.SHOW_ANALYTICS_UI) {
204+
if (telemetry.showAnalyticsUI) {
205205
if (results.wasParsed(ANALYTICS_FLAG)) {
206206
analytics.enabled = results[ANALYTICS_FLAG];
207207
print(telemetry.createAnalyticsStatusMessage(analytics.enabled));
@@ -537,7 +537,7 @@ class Driver implements ServerStarter {
537537
print('Supported flags are:');
538538
print(parser.usage);
539539

540-
if (telemetry.SHOW_ANALYTICS_UI) {
540+
if (telemetry.showAnalyticsUI) {
541541
// Print analytics status and information.
542542
if (fromHelp) {
543543
print('');
@@ -648,11 +648,11 @@ class Driver implements ServerStarter {
648648
//
649649
parser.addFlag(ANALYTICS_FLAG,
650650
help: 'enable or disable sending analytics information to Google',
651-
hide: !telemetry.SHOW_ANALYTICS_UI);
651+
hide: !telemetry.showAnalyticsUI);
652652
parser.addFlag(SUPPRESS_ANALYTICS_FLAG,
653653
negatable: false,
654654
help: 'suppress analytics for this session',
655-
hide: !telemetry.SHOW_ANALYTICS_UI);
655+
hide: !telemetry.showAnalyticsUI);
656656

657657
//
658658
// Hidden; these are for internal development.

pkg/telemetry/analysis_options.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1+
include: package:lints/recommended.yaml
2+
13
analyzer:
24
strong-mode:
35
implicit-casts: false
46
linter:
57
rules:
6-
- annotate_overrides
7-
- empty_constructor_bodies
8-
- empty_statements
98
- unawaited_futures
10-
- unnecessary_brace_in_string_interps
11-
- valid_regexps

pkg/telemetry/lib/crash_reporting.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class CrashReportSender {
4545
final String crashProductId;
4646
final EnablementCallback shouldSend;
4747
final http.Client _httpClient;
48-
final Stopwatch _processStopwatch = new Stopwatch()..start();
48+
final Stopwatch _processStopwatch = Stopwatch()..start();
4949

5050
final ThrottlingBucket _throttle = ThrottlingBucket(10, Duration(minutes: 1));
5151
int _reportsSent = 0;
@@ -56,8 +56,8 @@ class CrashReportSender {
5656
this.shouldSend, {
5757
http.Client? httpClient,
5858
String endpointPath = _crashEndpointPathStaging,
59-
}) : _httpClient = httpClient ?? new http.Client(),
60-
_baseUri = new Uri(
59+
}) : _httpClient = httpClient ?? http.Client(),
60+
_baseUri = Uri(
6161
scheme: 'https', host: _crashServerHost, path: endpointPath);
6262

6363
/// Create a new [CrashReportSender] connected to the staging endpoint.
@@ -120,7 +120,7 @@ class CrashReportSender {
120120
},
121121
);
122122

123-
final http.MultipartRequest req = new http.MultipartRequest('POST', uri);
123+
final http.MultipartRequest req = http.MultipartRequest('POST', uri);
124124

125125
Map<String, String> fields = req.fields;
126126
fields['product'] = crashProductId;
@@ -144,9 +144,9 @@ class CrashReportSender {
144144
fields['weight'] = weight.toString();
145145
}
146146

147-
final Chain chain = new Chain.forTrace(stackTrace);
147+
final Chain chain = Chain.forTrace(stackTrace);
148148
req.files.add(
149-
new http.MultipartFile.fromString(
149+
http.MultipartFile.fromString(
150150
_stackTraceFileField,
151151
chain.terse.toString(),
152152
filename: _stackTraceFilename,
@@ -155,7 +155,7 @@ class CrashReportSender {
155155

156156
for (var attachment in attachments) {
157157
req.files.add(
158-
new http.MultipartFile.fromString(
158+
http.MultipartFile.fromString(
159159
attachment._field,
160160
attachment._value,
161161
filename: attachment._field,
@@ -200,4 +200,4 @@ class CrashReportAttachment {
200200

201201
/// A typedef to allow crash reporting to query as to whether it should send a
202202
/// crash report.
203-
typedef bool EnablementCallback();
203+
typedef EnablementCallback = bool Function();

pkg/telemetry/lib/src/utils.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ThrottlingBucket {
1515
final Duration replenishDuration;
1616

1717
late int _drops = bucketSize;
18-
late int _lastReplenish = new DateTime.now().millisecondsSinceEpoch;
18+
late int _lastReplenish = DateTime.now().millisecondsSinceEpoch;
1919

2020
ThrottlingBucket(this.bucketSize, this.replenishDuration);
2121

@@ -31,7 +31,7 @@ class ThrottlingBucket {
3131
}
3232

3333
void _checkReplenish() {
34-
int now = new DateTime.now().millisecondsSinceEpoch;
34+
int now = DateTime.now().millisecondsSinceEpoch;
3535

3636
int replenishMillis = replenishDuration.inMilliseconds;
3737

pkg/telemetry/lib/telemetry.dart

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ import 'dart:io';
66

77
import 'package:meta/meta.dart';
88
import 'package:path/path.dart' as path;
9+
// ignore: implementation_imports
910
import 'package:usage/src/usage_impl.dart';
11+
// ignore: implementation_imports
1012
import 'package:usage/src/usage_impl_io.dart';
13+
// ignore: implementation_imports
1114
import 'package:usage/src/usage_impl_io.dart' as usage_io show getDartVersion;
1215
import 'package:usage/usage.dart';
1316
import 'package:usage/usage_io.dart';
1417

1518
export 'package:usage/usage.dart' show Analytics;
1619

1720
// TODO(devoncarew): Don't show the UI until we're ready to ship.
18-
final bool SHOW_ANALYTICS_UI = false;
21+
final bool showAnalyticsUI = false;
1922

2023
final String _dartDirectoryName = '.dart';
2124
final String _settingsFileName = 'analytics.json';
@@ -38,7 +41,7 @@ final String analyticsNotice =
3841
/// be disabled with --no-analytics).'`
3942
String createAnalyticsStatusMessage(
4043
bool enabled, {
41-
String command: 'analytics',
44+
String command = 'analytics',
4245
}) {
4346
String currentState = enabled ? 'enabled' : 'disabled';
4447
String toggleState = enabled ? 'disabled' : 'enabled';
@@ -63,7 +66,7 @@ Analytics createAnalyticsInstance(
6366
if (dir == null) {
6467
// Some systems don't support user home directories; for those, fail
6568
// gracefully by returning a disabled analytics object.
66-
return new _DisabledAnalytics(trackingId, applicationName);
69+
return _DisabledAnalytics(trackingId, applicationName);
6770
}
6871

6972
if (!dir.existsSync()) {
@@ -72,12 +75,12 @@ Analytics createAnalyticsInstance(
7275
} catch (e) {
7376
// If we can't create the directory for the analytics settings, fail
7477
// gracefully by returning a disabled analytics object.
75-
return new _DisabledAnalytics(trackingId, applicationName);
78+
return _DisabledAnalytics(trackingId, applicationName);
7679
}
7780
}
7881

79-
File settingsFile = new File(path.join(dir.path, _settingsFileName));
80-
return new _TelemetryAnalytics(
82+
File settingsFile = File(path.join(dir.path, _settingsFileName));
83+
return _TelemetryAnalytics(
8184
trackingId,
8285
applicationName,
8386
getDartVersion(),
@@ -96,10 +99,10 @@ Analytics createAnalyticsInstance(
9699
/// directory does not exist.
97100
@visibleForTesting
98101
Directory? getDartStorageDirectory() {
99-
Directory homeDirectory = new Directory(userHomeDir());
102+
Directory homeDirectory = Directory(userHomeDir());
100103
if (!homeDirectory.existsSync()) return null;
101104

102-
return new Directory(path.join(homeDirectory.path, _dartDirectoryName));
105+
return Directory(path.join(homeDirectory.path, _dartDirectoryName));
103106
}
104107

105108
/// Return the version of the Dart SDK.
@@ -118,8 +121,8 @@ class _TelemetryAnalytics extends AnalyticsImpl {
118121
required this.forceEnabled,
119122
}) : super(
120123
trackingId,
121-
new IOPersistentProperties.fromFile(settingsFile),
122-
new IOPostHandler(),
124+
IOPersistentProperties.fromFile(settingsFile),
125+
IOPostHandler(),
123126
applicationName: applicationName,
124127
applicationVersion: applicationVersion,
125128
) {

pkg/telemetry/test/crash_reporting_test.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,21 @@ void main() {
1818
late Request request;
1919

2020
setUp(() {
21-
mockClient = new MockClient((Request r) async {
21+
mockClient = MockClient((Request r) async {
2222
request = r;
23-
return new Response('crash-report-001', 200);
23+
return Response('crash-report-001', 200);
2424
});
2525

26-
analytics = new AnalyticsMock()..enabled = true;
26+
analytics = AnalyticsMock()..enabled = true;
2727
});
2828

29-
EnablementCallback shouldSend = () {
29+
EnablementCallback shouldSend;
30+
shouldSend = () {
3031
return true;
3132
};
3233

3334
test('general', () async {
34-
CrashReportSender sender = new CrashReportSender.prod(
35+
CrashReportSender sender = CrashReportSender.prod(
3536
analytics.trackingId, shouldSend,
3637
httpClient: mockClient);
3738

@@ -43,7 +44,7 @@ void main() {
4344
});
4445

4546
test('reportsSent', () async {
46-
CrashReportSender sender = new CrashReportSender.prod(
47+
CrashReportSender sender = CrashReportSender.prod(
4748
analytics.trackingId, shouldSend,
4849
httpClient: mockClient);
4950

@@ -59,7 +60,7 @@ void main() {
5960
});
6061

6162
test('contains message', () async {
62-
CrashReportSender sender = new CrashReportSender.prod(
63+
CrashReportSender sender = CrashReportSender.prod(
6364
analytics.trackingId, shouldSend,
6465
httpClient: mockClient);
6566

@@ -73,7 +74,7 @@ void main() {
7374
});
7475

7576
test('has attachments', () async {
76-
CrashReportSender sender = new CrashReportSender.prod(
77+
CrashReportSender sender = CrashReportSender.prod(
7778
analytics.trackingId, shouldSend,
7879
httpClient: mockClient);
7980

@@ -94,7 +95,7 @@ void main() {
9495
});
9596

9697
test('has ptime', () async {
97-
CrashReportSender sender = new CrashReportSender.prod(
98+
CrashReportSender sender = CrashReportSender.prod(
9899
analytics.trackingId, shouldSend,
99100
httpClient: mockClient);
100101

pkg/telemetry/test/utils_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import 'package:test/test.dart';
88
void main() {
99
group('ThrottlingBucket', () {
1010
test('can send', () {
11-
ThrottlingBucket bucket = new ThrottlingBucket(10, Duration(minutes: 1));
11+
ThrottlingBucket bucket = ThrottlingBucket(10, Duration(minutes: 1));
1212
expect(bucket.removeDrop(), true);
1313
});
1414

1515
test("doesn't send too many", () {
16-
ThrottlingBucket bucket = new ThrottlingBucket(10, Duration(minutes: 1));
16+
ThrottlingBucket bucket = ThrottlingBucket(10, Duration(minutes: 1));
1717
for (int i = 0; i < 10; i++) {
1818
expect(bucket.removeDrop(), true);
1919
}

0 commit comments

Comments
 (0)