Skip to content

Commit

Permalink
Analyze all dart code on CI (flutter#35147)
Browse files Browse the repository at this point in the history
  • Loading branch information
goderbauer authored Aug 5, 2022
1 parent eaeae8e commit 1f9d87d
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 71 deletions.
24 changes: 8 additions & 16 deletions ci/analyze.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,21 @@ echo ""

"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/flutter_frontend_server"

"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/tools/licenses"
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/tools"

"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/litetest"

"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/benchmark"

"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/smoke_test_failure"

"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/dart"

"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/scenario_app"

"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing/symbols"

"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/tools/githooks"

"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/tools/clang_tidy"
(cd "$FLUTTER_DIR/testing/skia_gold_client"; "$DART" pub get)
"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/testing"

echo ""

# Check that dart libraries conform.
echo "Checking the integrity of the Web SDK"
(cd "$FLUTTER_DIR/web_sdk"; "$DART" pub get)
(cd "$FLUTTER_DIR/web_sdk/web_test_utils"; "$DART" pub get)
(cd "$FLUTTER_DIR/web_sdk/web_engine_tester"; "$DART" pub get)

"$DART" analyze --fatal-infos --fatal-warnings "$FLUTTER_DIR/web_sdk"

WEB_SDK_TEST_FILES="$FLUTTER_DIR/web_sdk/test/*"
for testFile in $WEB_SDK_TEST_FILES
do
Expand Down
5 changes: 5 additions & 0 deletions tools/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include: ../analysis_options.yaml

linter:
rules:
avoid_print: false
4 changes: 2 additions & 2 deletions tools/api_check/lib/apicheck.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ List<String> getDartClassFields({
final RegExp fieldExp = RegExp(r'_k(\w*)Index');
final List<String> fields = <String>[];
for (final CompilationUnitMember unitMember in result.unit.declarations) {
if (unitMember is ClassDeclaration && unitMember.name.name == className) {
if (unitMember is ClassDeclaration && unitMember.name.name == className) { // ignore: deprecated_member_use
for (final ClassMember classMember in unitMember.members) {
if (classMember is FieldDeclaration) {
for (final VariableDeclaration field in classMember.fields.variables) {
final String fieldName = field.name.name;
final String fieldName = field.name.name; // ignore: deprecated_member_use
final RegExpMatch? match = fieldExp.firstMatch(fieldName);
if (match != null) {
fields.add(match.group(1)!);
Expand Down
2 changes: 1 addition & 1 deletion tools/api_check/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ environment:
dependencies:
analyzer: any
_fe_analyzer_shared: any
pub_semver: any

dev_dependencies:
async_helper: any
expect: any
litetest: any
path: any
pub_semver: any
smith: any

dependency_overrides:
Expand Down
10 changes: 6 additions & 4 deletions tools/const_finder/test/const_finder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: avoid_dynamic_calls

import 'dart:convert' show jsonEncode;
import 'dart:io';

Expand Down Expand Up @@ -175,7 +177,7 @@ Future<void> main(List<String> args) async {
final String frontendServer = args[0];
final String sdkRoot = args[1];
try {
void _checkProcessResult(ProcessResult result) {
void checkProcessResult(ProcessResult result) {
if (result.exitCode != 0) {
stdout.writeln(result.stdout);
stderr.writeln(result.stderr);
Expand All @@ -186,7 +188,7 @@ Future<void> main(List<String> args) async {
stdout.writeln('Generating kernel fixtures...');
stdout.writeln(consts);

_checkProcessResult(Process.runSync(dart, <String>[
checkProcessResult(Process.runSync(dart, <String>[
frontendServer,
'--sdk-root=$sdkRoot',
'--target=flutter',
Expand All @@ -197,7 +199,7 @@ Future<void> main(List<String> args) async {
box,
]));

_checkProcessResult(Process.runSync(dart, <String>[
checkProcessResult(Process.runSync(dart, <String>[
frontendServer,
'--sdk-root=$sdkRoot',
'--target=flutter',
Expand All @@ -208,7 +210,7 @@ Future<void> main(List<String> args) async {
consts,
]));

_checkProcessResult(Process.runSync(dart, <String>[
checkProcessResult(Process.runSync(dart, <String>[
frontendServer,
'--sdk-root=$sdkRoot',
'--target=flutter',
Expand Down
4 changes: 2 additions & 2 deletions tools/const_finder/test/fixtures/lib/box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
// https://github.com/dart-lang/sdk/blob/ca3ad264a64937d5d336cd04dbf2746d1b7d8fc4/tests/language_2/canonicalize/hashing_memoize_instance_test.dart

class Box {
const Box(this.content1, this.content2);
final Object content1;
final Object content2;
const Box(this.content1, this.content2);
}

const Box box1_0 = Box(null, null);
Expand Down Expand Up @@ -217,7 +217,7 @@ const Box box2_98 = Box(box2_97, box2_97);
const Box box2_99 = Box(box2_98, box2_98);

Object confuse(Box x) {
try { throw x; } catch (e) { return e; }
try { throw x; } catch (e) { return e; } // ignore: only_throw_errors
}

void main() {
Expand Down
2 changes: 1 addition & 1 deletion tools/const_finder/test/fixtures/lib/consts.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.

// ignore_for_file: prefer_const_constructors, unused_local_variable
// ignore_for_file: prefer_const_constructors, unused_local_variable, depend_on_referenced_packages
import 'dart:core';

import 'package:const_finder_fixtures_package/package.dart';
Expand Down
2 changes: 1 addition & 1 deletion tools/const_finder/test/fixtures/lib/consts_and_non.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.

// ignore_for_file: prefer_const_constructors, unused_local_variable
// ignore_for_file: prefer_const_constructors, unused_local_variable, depend_on_referenced_packages
import 'dart:core';

import 'package:const_finder_fixtures_package/package.dart';
Expand Down
2 changes: 1 addition & 1 deletion tools/const_finder/test/fixtures/pkg/package.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.

// ignore_for_file: prefer_const_constructors
// ignore_for_file: prefer_const_constructors, depend_on_referenced_packages
import 'package:const_finder_fixtures/target.dart';

void createTargetInPackage() {
Expand Down
5 changes: 4 additions & 1 deletion tools/gen_locale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// TODO(goderbauer): Migrate this to null safety, https://github.com/flutter/flutter/issues/108933
// @dart = 2.7

// This file is used to generate the switch statements in the Locale class.
// See: ../lib/ui/window.dart

Expand Down Expand Up @@ -30,7 +33,7 @@ Map<String, List<String>> parseSection(String section) {
}
final int colon = line.indexOf(':');
if (colon <= 0) {
throw 'not sure how to deal with "$line"';
throw StateError('not sure how to deal with "$line"');
}
final String name = line.substring(0, colon);
final String value = line.substring(colon + 2);
Expand Down
5 changes: 4 additions & 1 deletion web_sdk/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: web_sdk_tests
author: Flutter Authors <[email protected]>

# Keep the SDK version range in sync with lib/web_ui/pubspec.yaml
environment:
sdk: ">=2.12.0-0 <3.0.0"

dependencies:
args: 2.3.1
path: 1.8.2

dev_dependencies:
analyzer: 4.3.1
test: 1.21.4
6 changes: 3 additions & 3 deletions web_sdk/sdk_rewriter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import 'package:path/path.dart' as path;
final ArgParser argParser = ArgParser()
..addOption('output-dir')
..addOption('input-dir')
..addFlag('ui', defaultsTo: false)
..addFlag('engine', defaultsTo: false)
..addFlag('ui')
..addFlag('engine')
..addMultiOption('input')
..addOption('stamp');

Expand Down Expand Up @@ -170,7 +170,7 @@ String _preprocessEnginePartFile(String source) {
// Do nothing.
} else {
// Insert the part directive at the beginning of the file.
source = 'part of engine;\n' + source;
source = 'part of engine;\n$source';
}
return source;
}
Expand Down
11 changes: 6 additions & 5 deletions web_sdk/test/api_conform_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: avoid_print

import 'dart:io';

import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/analysis/utilities.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:pub_semver/pub_semver.dart';

// Ignore members defined on Object.
const Set<String> _kObjectMembers = <String>{
Expand Down Expand Up @@ -187,8 +188,8 @@ void main() {
// check nullability
if (uiParam is SimpleFormalParameter &&
webParam is SimpleFormalParameter) {
bool isUiNullable = uiParam.type?.question != null;
bool isWebNullable = webParam.type?.question != null;
final bool isUiNullable = uiParam.type?.question != null;
final bool isWebNullable = webParam.type?.question != null;
if (isUiNullable != isWebNullable) {
failed = true;
print('Warning: lib/ui/ui.dart $className.$methodName parameter $i '
Expand Down Expand Up @@ -263,8 +264,8 @@ void main() {
'${uiParam.identifier!.name} is named, but not in lib/web_ui/ui.dart.');
}

bool isUiNullable = uiParam.type?.question != null;
bool isWebNullable = webParam.type?.question != null;
final bool isUiNullable = uiParam.type?.question != null;
final bool isWebNullable = webParam.type?.question != null;
if (isUiNullable != isWebNullable) {
failed = true;
print('Warning: lib/ui/ui.dart $typeDefName parameter $i '
Expand Down
2 changes: 2 additions & 0 deletions web_sdk/test/js_access_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: avoid_print

/// Checks that JavaScript API is accessed properly.
///
/// JavaScript access needs to be audited to make sure it follows security best
Expand Down
2 changes: 1 addition & 1 deletion web_sdk/test/sdk_rewriter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export 'engine/file3.dart';
'$caught',
'Exception: on line 3: unexpected code in /path/to/lib/web_ui/lib/src/engine.dart. '
'This file may only contain comments and exports. Found:\n'
'import \'dart:something\';',
"import 'dart:something';",
);
});

Expand Down
2 changes: 1 addition & 1 deletion web_sdk/web_engine_tester/lib/golden_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'dart:convert';

import 'package:test/test.dart';
// ignore: implementation_imports
import 'package:ui/src/engine.dart' show operatingSystem, OperatingSystem, useCanvasKit;
import 'package:ui/src/engine.dart' show OperatingSystem, operatingSystem, useCanvasKit;
// ignore: implementation_imports
import 'package:ui/src/engine/dom.dart';
import 'package:ui/ui.dart';
Expand Down
10 changes: 6 additions & 4 deletions web_sdk/web_engine_tester/lib/static/host.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: avoid_dynamic_calls

@JS()
library test.host;

Expand All @@ -22,7 +24,7 @@ class _TestRunner {

/// Returns the current content shell runner, or `null` if none exists.
@JS()
external _TestRunner? get testRunner;
external _TestRunner? get testRunner; // ignore: library_private_types_in_public_api

/// A class that exposes the test API to JS.
///
Expand All @@ -31,15 +33,15 @@ external _TestRunner? get testRunner;
@JS()
@anonymous
class _JSApi {
external factory _JSApi({void Function() resume, void Function() restartCurrent});

/// Causes the test runner to resume running, as though the user had clicked
/// the "play" button.
external Function get resume;

/// Causes the test runner to restart the current test once it finishes
/// running.
external Function get restartCurrent;

external factory _JSApi({void Function() resume, void Function() restartCurrent});
}

/// Sets the top-level `dartTest` object so that it's visible to JS.
Expand Down Expand Up @@ -160,7 +162,7 @@ void main() {
}));
},
(dynamic error, StackTrace stackTrace) {
print('$error\n${Trace.from(stackTrace).terse}');
print('$error\n${Trace.from(stackTrace).terse}'); // ignore: avoid_print
},
);
}
Expand Down
1 change: 1 addition & 0 deletions web_sdk/web_engine_tester/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ dependencies:
stream_channel: 2.1.0
test: 1.17.7
webkit_inspection_protocol: 1.0.0
stack_trace: 1.10.0
ui:
path: ../../lib/web_ui
20 changes: 10 additions & 10 deletions web_sdk/web_test_utils/lib/environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class Environment {
return _prepareEnvironmentFromEngineDir(script, directory);
}

Environment._({
required this.self,
required this.webUiRootDir,
required this.engineSrcDir,
required this.engineToolsDir,
required this.outDir,
required this.hostDebugUnoptDir,
required this.dartSdkDir,
});

static Environment _prepareEnvironmentFromEngineDir(
io.File self, io.Directory engineSrcDir) {
final io.Directory engineToolsDir =
Expand Down Expand Up @@ -72,16 +82,6 @@ class Environment {
);
}

Environment._({
required this.self,
required this.webUiRootDir,
required this.engineSrcDir,
required this.engineToolsDir,
required this.outDir,
required this.hostDebugUnoptDir,
required this.dartSdkDir,
});

/// The Dart script that's currently running.
final io.File self;

Expand Down
Loading

0 comments on commit 1f9d87d

Please sign in to comment.