Skip to content

unified_analytics and graphs: cleanup lints, bump pkg deps #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
unified_analytics and graphs: cleanup lints, bump pkg deps
  • Loading branch information
kevmoo committed Jun 1, 2023
commit e1c524c96e719434447ee90462a9071db4895d39
4 changes: 4 additions & 0 deletions pkgs/graphs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.2-wip

- Require Dart 3.0

## 2.3.1

- Update package repository after move.
Expand Down
19 changes: 3 additions & 16 deletions pkgs/graphs/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# https://dart.dev/guides/language/analysis-options
include: package:lints/recommended.yaml
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true
errors:
sort_pub_dependencies: ignore

linter:
rules:
- always_declare_return_types
- avoid_bool_literals_in_conditional_expressions
- avoid_catching_errors
- avoid_classes_with_only_static_members
- avoid_dynamic_calls
- avoid_private_typedef_functions
- avoid_redundant_argument_values
- avoid_returning_null
Expand All @@ -23,33 +22,21 @@ linter:
- avoid_void_async
- cancel_subscriptions
- comment_references
- directives_ordering
- join_return_with_assignment
- lines_longer_than_80_chars
- literal_only_boolean_expressions
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- no_runtimeType_toString
- omit_local_variable_types
- only_throw_errors
- package_api_docs
- prefer_asserts_in_initializer_lists
- prefer_const_constructors
- prefer_const_declarations
- prefer_expression_function_bodies
- prefer_final_locals
- prefer_relative_imports
- prefer_single_quotes
- require_trailing_commas
- test_types_in_equals
- throw_in_finally
- type_annotate_public_apis
- unawaited_futures
- unnecessary_await_in_return
- unnecessary_lambdas
- unnecessary_parenthesis
- unnecessary_raw_strings
- unnecessary_statements
- use_if_null_to_convert_nulls_to_bools
- use_raw_strings
- use_string_buffers
Expand Down
6 changes: 3 additions & 3 deletions pkgs/graphs/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: graphs
version: 2.3.1
version: 2.3.2-dev
description: Graph algorithms that operate on graphs in any representation
repository: https://github.com/dart-lang/tools/tree/main/pkgs/graphs

environment:
sdk: '>=2.18.0 <3.0.0'
sdk: ^3.0.0

dependencies:
collection: ^1.1.0

dev_dependencies:
lints: ^2.0.0
dart_flutter_team_lints: ^1.0.0
test: ^1.16.0

# For examples
Expand Down
4 changes: 4 additions & 0 deletions pkgs/unified_analytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.2-wip

- Allow latest package versions for `file` and `http`.

## 1.1.1

- Refactoring `dateStamp` utility function to be defined in `utils.dart` instead of having static methods in `Initializer` and `ConfigHandler`
Expand Down
2 changes: 1 addition & 1 deletion pkgs/unified_analytics/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml
include: package:dart_flutter_team_lints/analysis_options.yaml

# Uncomment the following section to specify additional rules.

Expand Down
12 changes: 6 additions & 6 deletions pkgs/unified_analytics/example/unified_analytics_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final Analytics analytics = Analytics.development(

// Timing a process and sending the event
void main() async {
DateTime start = DateTime.now();
var start = DateTime.now();

// Each client using this package will have it's own
// method to show the message but the below is a trivial
Expand All @@ -42,23 +42,23 @@ void main() async {
print('Current user is opted in: ${analytics.telemetryEnabled}');

// Example of long running process
int count = 0;
for (int i = 0; i < 2000; i++) {
var count = 0;
for (var i = 0; i < 2000; i++) {
count += i;
}
await Future<void>.delayed(const Duration(milliseconds: 100));

// Calculate the metric to send
final int runTime = DateTime.now().difference(start).inMilliseconds;
final runTime = DateTime.now().difference(start).inMilliseconds;
// Generate the body for the event data
final Map<String, int> eventData = {
final eventData = <String, int>{
'time_ms': runTime,
'count': count,
};
// Choose one of the enum values for [DashEvent] which should
// have all possible events; if not there, open an issue for the
// team to add
final DashEvent eventName =
final eventName =
DashEvent.hotReloadTime; // Select appropriate DashEvent enum value

// Make a call to the [Analytics] api to send the data
Expand Down
28 changes: 14 additions & 14 deletions pkgs/unified_analytics/lib/src/analytics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract class Analytics {

// Create the instance of the GA Client which will create
// an [http.Client] to send requests
final GAClient gaClient = GAClient(
final gaClient = GAClient(
measurementId: kGoogleAnalyticsMeasurementId,
apiSecret: kGoogleAnalyticsApiSecret,
);
Expand Down Expand Up @@ -99,12 +99,12 @@ abstract class Analytics {
}

// Credentials defined below for the test Google Analytics instance
const String kTestMeasurementId = 'G-N1NXG28J5B';
const String kTestApiSecret = '4yT8__oER3Cd84dtx6r-_A';
const kTestMeasurementId = 'G-N1NXG28J5B';
const kTestApiSecret = '4yT8__oER3Cd84dtx6r-_A';

// Create the instance of the GA Client which will create
// an [http.Client] to send requests
final GAClient gaClient = GAClient(
final gaClient = GAClient(
measurementId: kTestMeasurementId,
apiSecret: kTestApiSecret,
);
Expand Down Expand Up @@ -176,7 +176,8 @@ abstract class Analytics {
/// Boolean indicating whether or not telemetry is enabled
bool get telemetryEnabled;

/// Returns a map representation of the [UserProperty] for the [Analytics] instance
/// Returns a map representation of the [UserProperty] for the [Analytics]
/// instance.
///
/// This is what will get sent to Google Analytics with every request
Map<String, Map<String, Object?>> get userPropertyMap;
Expand Down Expand Up @@ -255,8 +256,8 @@ class AnalyticsImpl implements Analytics {
required DevicePlatform platform,
required this.toolsMessageVersion,
required this.fs,
required gaClient,
required enableAsserts,
required GAClient gaClient,
required bool enableAsserts,
}) : _gaClient = gaClient,
_enableAsserts = enableAsserts {
// Initialize date formatting for `package:intl` within constructor
Expand All @@ -266,7 +267,7 @@ class AnalyticsImpl implements Analytics {
// This initializer class will let the instance know
// if it was the first run; if it is, nothing will be sent
// on the first run
final Initializer initializer = Initializer(
final initializer = Initializer(
fs: fs,
tool: tool.label,
homeDirectory: homeDirectory,
Expand Down Expand Up @@ -295,7 +296,7 @@ class AnalyticsImpl implements Analytics {
//
// If the tool has not been added to the config file, then
// we will show the message as well
final int currentVersion =
final currentVersion =
_configHandler.parsedTools[tool.label]?.versionNumber ?? -1;
if (currentVersion < toolsMessageVersion) {
_showMessage = true;
Expand Down Expand Up @@ -326,8 +327,7 @@ class AnalyticsImpl implements Analytics {
@override
String get getConsentMessage {
// The command to swap in the consent message
final String commandString =
tool == DashTool.flutterTool ? 'flutter' : 'dart';
final commandString = tool == DashTool.flutterTool ? 'flutter' : 'dart';

return kToolsMessage
.replaceAll('[tool name]', tool.description)
Expand Down Expand Up @@ -395,7 +395,7 @@ class AnalyticsImpl implements Analytics {
if (!okToSend) return null;

// Construct the body of the request
final Map<String, Object?> body = generateRequestBody(
final body = generateRequestBody(
clientId: _clientId,
eventName: eventName,
eventData: eventData,
Expand All @@ -419,7 +419,7 @@ class AnalyticsImpl implements Analytics {
//
// We use don't use the sendEvent method because it may
// be blocked by the [telemetryEnabled] getter
final Map<String, Object?> body = generateRequestBody(
final body = generateRequestBody(
clientId: _clientId,
eventName: DashEvent.analyticsCollectionEnabled,
eventData: {'status': reportingBool},
Expand Down Expand Up @@ -525,7 +525,7 @@ class TestAnalytics extends AnalyticsImpl {
// Calling the [generateRequestBody] method will ensure that the
// session file is getting updated without actually making any
// POST requests to Google Analytics
final Map<String, Object?> body = generateRequestBody(
final body = generateRequestBody(
clientId: _clientId,
eventName: eventName,
eventData: eventData,
Expand Down
29 changes: 14 additions & 15 deletions pkgs/unified_analytics/lib/src/asserts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ void checkBody(Map<String, Object?> body) {
throw AnalyticsException('user_properties missing from top level keys');
}

final List events = body['events'] as List;
final Map<String, Object?> userProperties =
body['user_properties'] as Map<String, Object?>;
final events = body['events'] as List;
final userProperties = body['user_properties'] as Map<String, Object?>;

// GA4 Limitation:
// Requests can have a maximum of 25 events
Expand All @@ -32,8 +31,8 @@ void checkBody(Map<String, Object?> body) {
}

// Checks for each event object
for (Map<String, Object?> eventMap in events) {
final String eventName = eventMap['name'] as String;
for (var eventMap in events.cast<Map<String, Object?>>()) {
final eventName = eventMap['name'] as String;

// GA4 Limitation:
// Event names must be 40 characters or fewer, may only contain
Expand All @@ -50,8 +49,7 @@ void checkBody(Map<String, Object?> body) {
throw AnalyticsException('Event name first char must be alphabetic char');
}

final Map<String, Object?> eventParams =
eventMap['params'] as Map<String, Object?>;
final eventParams = eventMap['params'] as Map<String, Object?>;

// GA4 Limitation:
// Events can have a maximum of 25 parameters
Expand All @@ -60,9 +58,9 @@ void checkBody(Map<String, Object?> body) {
}

// Loop through each of the event parameters
for (MapEntry entry in eventParams.entries) {
final String key = entry.key;
final Object? value = entry.value;
for (var entry in eventParams.entries) {
final key = entry.key;
final value = entry.value;

// GA4 Limitation:
// Ensure that each value for the event params is one
Expand All @@ -85,7 +83,8 @@ void checkBody(Map<String, Object?> body) {
}
if (!alphaNumericPattern.hasMatch(key)) {
throw AnalyticsException(
'Event param name can only have alphanumeric chars and underscores');
'Event param name can only have alphanumeric chars and underscores',
);
}
if (!alphabeticPattern.hasMatch(key[0])) {
throw AnalyticsException(
Expand All @@ -112,9 +111,9 @@ void checkBody(Map<String, Object?> body) {
}

// Checks for each user property item
for (MapEntry entry in userProperties.entries) {
final String key = entry.key;
final Map<String, Object?> value = entry.value as Map<String, Object?>;
for (var entry in userProperties.entries) {
final key = entry.key;
final value = entry.value as Map<String, Object?>;

// GA4 Limitation:
// User property names must be 24 characters or fewer
Expand All @@ -124,7 +123,7 @@ void checkBody(Map<String, Object?> body) {

// GA4 Limitation:
// User property values must be 36 characters or fewer
final Object? userPropValue = value['value'];
final userPropValue = value['value'];
if (userPropValue is String && userPropValue.length > 36) {
throw AnalyticsException(
'Limit user property values to 36 chars or less');
Expand Down
Loading