Skip to content

Commit

Permalink
[ci] Enable strict-casts (flutter#3127)
Browse files Browse the repository at this point in the history
* Enable strict-casts and fix violations

* Bump versions

* Fix Pigeon version bump
  • Loading branch information
stuartmorgan authored Jan 31, 2023
1 parent f9037e4 commit ab62689
Show file tree
Hide file tree
Showing 50 changed files with 157 additions and 132 deletions.
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

analyzer:
language:
strict-casts: false # DIFFERENT FROM FLUTTER/FLUTTER, too many violations, TODO(goderbauer): Clean this up.
strict-casts: true
strict-raw-types: true
errors:
# allow self-reference to deprecated members (we do this because otherwise we have
Expand Down
3 changes: 2 additions & 1 deletion packages/cross_file/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 0.3.3+3

* Updates code to fix strict-cast violations.
* Updates minimum SDK version to Flutter 3.0.

## 0.3.3+2
Expand Down
2 changes: 1 addition & 1 deletion packages/cross_file/lib/src/types/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class XFile extends XFileBase {
rethrow;
}

_browserBlob = request.response;
_browserBlob = request.response as Blob?;

assert(_browserBlob != null, 'The Blob backing this XFile cannot be null!');

Expand Down
2 changes: 1 addition & 1 deletion packages/cross_file/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: cross_file
description: An abstraction to allow working with files across multiple platforms.
repository: https://github.com/flutter/packages/tree/main/packages/cross_file
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+cross_file%22
version: 0.3.3+2
version: 0.3.3+3

environment:
sdk: ">=2.17.0 <3.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/cross_file/test/x_file_html_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void main() {

test('Stores data as a Blob', () async {
// Read the blob from its path 'natively'
final Object response = await html.window.fetch(file.path);
final Object response = await html.window.fetch(file.path) as Object;
// Call '.arrayBuffer()' on the fetch response object to look at its bytes.
final ByteBuffer data = await js_util.promiseToFuture(
js_util.callMethod(response, 'arrayBuffer', <Object?>[]),
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_image/test/network_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void main() {
Timer.run(onAttempt);
return fakeAsync.run((FakeAsync fakeAsync) {
return NetworkImageWithRetry.defaultFetchStrategy(uri, failure);
});
}) as Future<FetchInstructions>;
},
);

Expand All @@ -126,7 +126,7 @@ void main() {
Timer.run(onAttempt);
return fakeAsync.run((FakeAsync fakeAsync) {
return NetworkImageWithRetry.defaultFetchStrategy(uri, failure);
});
}) as Future<FetchInstructions>;
},
);

Expand Down
32 changes: 18 additions & 14 deletions packages/flutter_markdown/test/image_test_mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ MockHttpClient createMockImageHttpClient(SecurityContext? _) {
// Define an image stream that streams the mock test image for all
// image tests that request an image.
StreamSubscription<List<int>> imageStream(Invocation invocation) {
final void Function(List<int>)? onData = invocation.positionalArguments[0];
final void Function()? onDone = invocation.namedArguments[#onDone];
final void Function(List<int>)? onData =
invocation.positionalArguments[0] as Function(List<int>)?;
final void Function()? onDone =
invocation.namedArguments[#onDone] as Function()?;
final void Function(Object, [StackTrace?])? onError =
invocation.namedArguments[#onError];
final bool? cancelOnError = invocation.namedArguments[#cancelOnError];
invocation.namedArguments[#onError] as Function(Object, [StackTrace?])?;
final bool? cancelOnError =
invocation.namedArguments[#cancelOnError] as bool?;

return Stream<List<int>>.fromIterable(<List<int>>[transparentImage]).listen(
onData,
Expand Down Expand Up @@ -345,16 +348,17 @@ class MockHttpClientResponse extends Mock implements HttpClientResponse {
StreamSubscription<List<int>> listen(void Function(List<int> event)? onData,
{Function? onError, void Function()? onDone, bool? cancelOnError}) =>
super.noSuchMethod(
Invocation.method(
#listen,
<Object?>[onData],
<Symbol, Object?>{
#onError: onError,
#onDone: onDone,
#cancelOnError: cancelOnError
},
),
returnValue: _FakeStreamSubscription<List<int>>());
Invocation.method(
#listen,
<Object?>[onData],
<Symbol, Object?>{
#onError: onError,
#onDone: onDone,
#cancelOnError: cancelOnError
},
),
returnValue: _FakeStreamSubscription<List<int>>())
as StreamSubscription<List<int>>;

@override
int get statusCode =>
Expand Down
4 changes: 4 additions & 0 deletions packages/flutter_migrate/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.1+1

* Updates code to fix strict-cast violations.

## 0.0.1

* Initial version.
3 changes: 2 additions & 1 deletion packages/flutter_migrate/lib/src/environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class FlutterToolsEnvironment {
// minimally validate basic JSON format and trim away any accidental logging before.
if (commandOutput.contains(RegExp(r'[\s\S]*{[\s\S]+}[\s\S]*'))) {
commandOutput = commandOutput.substring(commandOutput.indexOf('{'));
mapping = jsonDecode(commandOutput.replaceAll(r'\', r'\\'));
mapping = jsonDecode(commandOutput.replaceAll(r'\', r'\\'))
as Map<String, Object?>;
}
return FlutterToolsEnvironment(mapping: mapping);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/flutter_migrate/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MigrateUtils {
commandDescription: 'git ${cmdArgs.join(' ')}');
return DiffResult(
diffType: DiffType.command,
diff: result.stdout,
diff: result.stdout as String,
exitCode: result.exitCode);
}

Expand Down Expand Up @@ -129,7 +129,7 @@ class MigrateUtils {
}
final ProcessResult result =
await _runCommand(cmdArgs, workingDirectory: outputDirectory);
final String error = result.stderr;
final String error = result.stderr as String;

// Catch errors due to parameters not existing.

Expand Down Expand Up @@ -305,9 +305,9 @@ class MigrateUtils {
_logger.printError(commandDescription, indent: 2);
}
_logger.printError('Stdout:');
_logger.printError(result.stdout, indent: 2);
_logger.printError(result.stdout as String, indent: 2);
_logger.printError('Stderr:');
_logger.printError(result.stderr, indent: 2);
_logger.printError(result.stderr as String, indent: 2);
}
if (exit) {
throwToolExit(
Expand Down Expand Up @@ -428,7 +428,7 @@ abstract class MergeResult {
class StringMergeResult extends MergeResult {
/// Initializes a BinaryMergeResult based off of a ProcessResult.
StringMergeResult(super.result, super.localPath)
: mergedString = result.stdout;
: mergedString = result.stdout as String;

/// Manually initializes a StringMergeResult with explicit values.
StringMergeResult.explicit({
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_migrate/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_migrate
description: A tool to migrate legacy flutter projects to modern versions.
version: 0.0.1
version: 0.0.1+1
repository: https://github.com/flutter/packages/tree/main/packages/flutter_migrate
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Ap%3A%20flutter_migrate
publish_to: none
Expand Down
8 changes: 4 additions & 4 deletions packages/flutter_migrate/test/migrate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ Modified files:
'--verbose',
], workingDirectory: tempDir.path);
logger.printStatus('${result.exitCode}', color: TerminalColor.blue);
logger.printStatus(result.stdout, color: TerminalColor.green);
logger.printStatus(result.stderr, color: TerminalColor.red);
logger.printStatus(result.stdout as String, color: TerminalColor.green);
logger.printStatus(result.stderr as String, color: TerminalColor.red);
expect(result.exitCode, 0);
expect(result.stdout.toString(), contains('Migration complete'));

Expand Down Expand Up @@ -151,8 +151,8 @@ class MyApp extends StatelessWidget {
'--verbose',
], workingDirectory: tempDir.path);
logger.printStatus('${result.exitCode}', color: TerminalColor.blue);
logger.printStatus(result.stdout, color: TerminalColor.green);
logger.printStatus(result.stderr, color: TerminalColor.red);
logger.printStatus(result.stdout as String, color: TerminalColor.green);
logger.printStatus(result.stderr as String, color: TerminalColor.red);
expect(result.exitCode, 0);
expect(result.stdout.toString(), contains('Migration complete'));

Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_migrate/test/update_locks_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ flutter:
''', flush: true);
await updatePubspecDependencies(flutterProject, utils, logger, terminal,
force: true);
final YamlMap pubspecYaml = loadYaml(pubspec.readAsStringSync());
final YamlMap dependenciesMap = pubspecYaml['dependencies'];
final YamlMap pubspecYaml = loadYaml(pubspec.readAsStringSync()) as YamlMap;
final YamlMap dependenciesMap = pubspecYaml['dependencies'] as YamlMap;
expect(
_VersionCode.fromString(dependenciesMap['characters'] as String) >
_VersionCode.fromString('1.2.0'),
Expand Down
3 changes: 2 additions & 1 deletion packages/metrics_center/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 1.0.7

* Updates code to fix strict-cast violations.
* Updates minimum SDK version to Flutter 3.0.

## 1.0.6
Expand Down
2 changes: 1 addition & 1 deletion packages/metrics_center/lib/src/google_benchmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GoogleBenchmarkParser {
)..removeWhere((String k, String v) => _kContextIgnoreKeys.contains(k));

final List<MetricPoint> points = <MetricPoint>[];
for (final dynamic item in jsonResult['benchmarks']) {
for (final dynamic item in jsonResult['benchmarks'] as List<dynamic>) {
_parseAnItem(item as Map<String, dynamic>, points, context);
}
return points;
Expand Down
2 changes: 1 addition & 1 deletion packages/metrics_center/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: metrics_center
version: 1.0.6
version: 1.0.7
description:
Support multiple performance metrics sources/formats and destinations.
repository: https://github.com/flutter/packages/tree/main/packages/metrics_center
Expand Down
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 7.1.5

* Updates code to fix strict-cast violations.

## 7.1.4

* [java] Fixes raw types lint issues.
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'ast.dart';
/// The current version of pigeon.
///
/// This must match the version in pubspec.yaml.
const String pigeonVersion = '7.1.4';
const String pigeonVersion = '7.1.5';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
39 changes: 20 additions & 19 deletions packages/pigeon/lib/pigeon_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1338,33 +1338,34 @@ ${_argParser.usage}''';
final ArgResults results = _argParser.parse(args);

final PigeonOptions opts = PigeonOptions(
input: results['input'],
dartOut: results['dart_out'],
dartTestOut: results['dart_test_out'],
objcHeaderOut: results['objc_header_out'],
objcSourceOut: results['objc_source_out'],
input: results['input'] as String?,
dartOut: results['dart_out'] as String?,
dartTestOut: results['dart_test_out'] as String?,
objcHeaderOut: results['objc_header_out'] as String?,
objcSourceOut: results['objc_source_out'] as String?,
objcOptions: ObjcOptions(
prefix: results['objc_prefix'],
prefix: results['objc_prefix'] as String?,
),
javaOut: results['java_out'],
javaOut: results['java_out'] as String?,
javaOptions: JavaOptions(
package: results['java_package'],
useGeneratedAnnotation: results['java_use_generated_annotation'],
package: results['java_package'] as String?,
useGeneratedAnnotation:
results['java_use_generated_annotation'] as bool?,
),
swiftOut: results['experimental_swift_out'],
kotlinOut: results['experimental_kotlin_out'],
swiftOut: results['experimental_swift_out'] as String?,
kotlinOut: results['experimental_kotlin_out'] as String?,
kotlinOptions: KotlinOptions(
package: results['experimental_kotlin_package'],
package: results['experimental_kotlin_package'] as String?,
),
cppHeaderOut: results['experimental_cpp_header_out'],
cppSourceOut: results['experimental_cpp_source_out'],
cppHeaderOut: results['experimental_cpp_header_out'] as String?,
cppSourceOut: results['experimental_cpp_source_out'] as String?,
cppOptions: CppOptions(
namespace: results['cpp_namespace'],
namespace: results['cpp_namespace'] as String?,
),
copyrightHeader: results['copyright_header'],
oneLanguage: results['one_language'],
astOut: results['ast_out'],
debugGenerators: results['debug_generators'],
copyrightHeader: results['copyright_header'] as String?,
oneLanguage: results['one_language'] as bool?,
astOut: results['ast_out'] as String?,
debugGenerators: results['debug_generators'] as bool?,
);
return opts;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/mock_handler_tester/test/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.1.4), do not edit directly.
// Autogenerated from Pigeon (v7.1.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/mock_handler_tester/test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.1.4), do not edit directly.
// Autogenerated from Pigeon (v7.1.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import
// ignore_for_file: avoid_relative_lib_imports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.1.4), do not edit directly.
// Autogenerated from Pigeon (v7.1.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package com.example.alternate_language_test_plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.1.4), do not edit directly.
// Autogenerated from Pigeon (v7.1.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import <Foundation/Foundation.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.1.4), do not edit directly.
// Autogenerated from Pigeon (v7.1.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import "CoreTests.gen.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.1.4), do not edit directly.
// Autogenerated from Pigeon (v7.1.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.1.4), do not edit directly.
// Autogenerated from Pigeon (v7.1.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.1.4), do not edit directly.
// Autogenerated from Pigeon (v7.1.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.1.4), do not edit directly.
// Autogenerated from Pigeon (v7.1.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.1.4), do not edit directly.
// Autogenerated from Pigeon (v7.1.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
Loading

0 comments on commit ab62689

Please sign in to comment.