Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit 6163c3b

Browse files
committed
test: fix tests
1 parent 996e53e commit 6163c3b

File tree

3 files changed

+32
-46
lines changed

3 files changed

+32
-46
lines changed

test/src/analyzers/lint_analyzer/rules/rules_list/avoid_passing_async_when_sync_expected/avoid_passing_async_when_sync_expected_rule_test.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@ void main() {
2626

2727
RuleTestHelper.verifyIssues(
2828
issues: issues,
29-
startLines: [50, 55, 58, 101],
29+
startLines: [49, 54, 57, 84],
3030
startColumns: [7, 7, 7, 9],
3131
locationTexts: [
32-
'synchronousWork: work1,',
33-
'synchronousWork3: () async {',
34-
'synchronousWork4: work4,',
35-
'onPressed: () async {',
32+
'synchronousWork: work1',
33+
'synchronousWork3: () async {\n'
34+
" print('work 3');\n"
35+
' }',
36+
'synchronousWork4: work4',
37+
'onPressed: () async {\n'
38+
' await Future.delayed(const Duration(seconds: 1));\n'
39+
' _incrementCounter();\n'
40+
' }',
3641
],
3742
messages: [
3843
'Expected a sync function but got async.',

test/src/analyzers/lint_analyzer/rules/rules_list/avoid_passing_async_when_sync_expected/examples/example.dart

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
import 'package:flutter/material.dart';
1+
class Widget {}
22

3-
void main() {
4-
runApp(const MyApp());
3+
class StatefulWidget extends Widget {}
4+
5+
class FloatingActionButton extends Widget {
6+
final VoidCallback onPressed;
7+
8+
const FloatingActionButton({required this.onPressed})
59
}
610

7-
class MyApp extends StatelessWidget {
8-
const MyApp({Key? key}) : super(key: key);
11+
class Scaffold extends Widget {
12+
final Widget floatingActionButton;
913

10-
@override
11-
Widget build(BuildContext context) {
12-
return MaterialApp(
13-
title: 'Flutter Demo',
14-
theme: ThemeData(
15-
primarySwatch: Colors.blue,
16-
),
17-
home: const MyHomePage(title: 'Flutter Demo Home Page'),
18-
);
19-
}
14+
const Scaffold({required this.floatingActionButton});
2015
}
2116

22-
class MyHomePage extends StatefulWidget {
23-
const MyHomePage({Key? key, required this.title}) : super(key: key);
17+
typedef VoidCallback = void Function();
18+
19+
abstract class State<T> {
20+
void initState();
2421

25-
final String title;
22+
void setState(VoidCallback callback) => callback();
23+
}
2624

25+
class MyHomePage extends StatefulWidget {
2726
@override
2827
State<MyHomePage> createState() => _MyHomePageState();
2928
}
@@ -55,7 +54,7 @@ class _MyHomePageState extends State<MyHomePage> {
5554
synchronousWork3: () async {
5655
print('work 3');
5756
},
58-
synchronousWork4: work4,
57+
synchronousWork4: work4, // LINT
5958
);
6059
}
6160

@@ -80,30 +79,12 @@ class _MyHomePageState extends State<MyHomePage> {
8079
@override
8180
Widget build(BuildContext context) {
8281
return Scaffold(
83-
appBar: AppBar(
84-
title: Text(widget.title),
85-
),
86-
body: Center(
87-
child: Column(
88-
mainAxisAlignment: MainAxisAlignment.center,
89-
children: <Widget>[
90-
const Text(
91-
'You have pushed the button this many times:',
92-
),
93-
Text(
94-
'$_counter',
95-
style: Theme.of(context).textTheme.headline4,
96-
),
97-
],
98-
),
99-
),
10082
floatingActionButton: FloatingActionButton(
83+
// LINT
10184
onPressed: () async {
10285
await Future.delayed(const Duration(seconds: 1));
10386
_incrementCounter();
10487
},
105-
tooltip: 'Increment',
106-
child: const Icon(Icons.add),
10788
),
10889
);
10990
}

test/src/analyzers/lint_analyzer/rules/rules_list/avoid_returning_widgets/examples/not_named_parameter_example.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ class Scaffold extends Widget {
3939
class CustomScrollView extends Widget {
4040
final Iterable<Widget> slivers;
4141

42-
const CustomScrollView({@required this.slivers});
42+
const CustomScrollView({required this.slivers});
4343
}
4444

4545
class SliverGrid extends Widget {
4646
final Widget delegate;
4747

48-
const SliverGrid({@required this.delegate});
48+
const SliverGrid({required this.delegate});
4949
}
5050

5151
class SliverChildBuilderDelegate extends Widget {
5252
final int childCount;
5353
final WidgetBuilder builder;
5454

55-
const SliverChildBuilderDelegate(this.builder, {@required this.childCount});
55+
const SliverChildBuilderDelegate(this.builder, {required this.childCount});
5656
}
5757

5858
typedef WidgetBuilder = Widget Function(BuildContext context);

0 commit comments

Comments
 (0)