Skip to content

Commit 94d3507

Browse files
Remove return types on overrides so they can be inferred
The fewer explicit types we have, the fewer need to be updated during the transition to null safety Done via replacement of `(@OverRide\n )(?![gs]et )([^(=\n]+ )([^(=\n]+\()` with `$1/$3`
1 parent 35297ff commit 94d3507

File tree

8 files changed

+53
-53
lines changed

8 files changed

+53
-53
lines changed

example/test/error_boundary_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ class _ErrorBoundaryComponent extends react.Component2 {
4545
Map get initialState => {'hasError': false};
4646

4747
@override
48-
Map getDerivedStateFromError(dynamic error) => {'hasError': true};
48+
getDerivedStateFromError(dynamic error) => {'hasError': true};
4949

5050
@override
51-
void componentDidCatch(dynamic error, ReactErrorInfo info) {
51+
componentDidCatch(dynamic error, ReactErrorInfo info) {
5252
props['onComponentDidCatch']?.call(error, info);
5353
}
5454

example/test/react_test_components.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,30 +96,30 @@ class _ClockComponent extends react.Component {
9696
getDefaultProps() => {'refreshRate': 1000};
9797

9898
@override
99-
void componentWillMount() {
99+
componentWillMount() {
100100
timer = Timer.periodic(Duration(milliseconds: props['refreshRate'] as int), tick);
101101
}
102102

103103
@override
104-
void componentWillUnmount() {
104+
componentWillUnmount() {
105105
timer.cancel();
106106
}
107107

108108
@override
109-
void componentDidMount() {
109+
componentDidMount() {
110110
final rootNode = react_dom.findDOMNode(this);
111111
rootNode.style.backgroundColor = '#FFAAAA';
112112
}
113113

114114
@override
115-
bool shouldComponentUpdate(nextProps, nextState) {
115+
shouldComponentUpdate(nextProps, nextState) {
116116
//print("Next state: $nextState, props: $nextProps");
117117
//print("Old state: $state, props: $props");
118118
return nextState['secondsElapsed'] % 2 == 1;
119119
}
120120

121121
@override
122-
void componentWillReceiveProps(nextProps) {
122+
componentWillReceiveProps(nextProps) {
123123
print('Received props: $nextProps');
124124
}
125125

@@ -146,14 +146,14 @@ class _ListComponent extends react.Component {
146146
}
147147

148148
@override
149-
void componentWillUpdate(nextProps, nextState) {
149+
componentWillUpdate(nextProps, nextState) {
150150
if ((nextState['items'] as List).length > (state['items'] as List).length) {
151151
print('Adding ' + (nextState['items'] as List).last.toString());
152152
}
153153
}
154154

155155
@override
156-
void componentDidUpdate(prevProps, prevState) {
156+
componentDidUpdate(prevProps, prevState) {
157157
if ((prevState['items'] as List).length > (state['items'] as List).length) {
158158
print('Removed ' + (prevState['items'] as List).first.toString());
159159
}
@@ -204,7 +204,7 @@ class _LegacyContextComponent extends react.Component {
204204
Iterable<String> get childContextKeys => const ['foo', 'bar', 'renderCount'];
205205

206206
@override
207-
Map<String, dynamic> getChildContext() => {
207+
getChildContext() => {
208208
'foo': {'object': 'with value'},
209209
'bar': true,
210210
'renderCount': state['renderCount']
@@ -439,7 +439,7 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot
439439
}
440440

441441
@override
442-
String getSnapshotBeforeUpdate(nextProps, prevState) {
442+
getSnapshotBeforeUpdate(nextProps, prevState) {
443443
if ((prevState['items'] as List).length > (state['items'] as List).length) {
444444
return 'removed ' + (prevState['items'].last as List).toString();
445445
} else {
@@ -448,7 +448,7 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot
448448
}
449449

450450
@override
451-
void componentDidUpdate(prevProps, prevState, [String snapshot]) {
451+
componentDidUpdate(prevProps, prevState, [String snapshot]) {
452452
if (snapshot != null) {
453453
print('Updated DOM and $snapshot');
454454
return;
@@ -501,7 +501,7 @@ var component2TestComponent = react.registerComponent(() => _Component2TestCompo
501501

502502
class _ErrorComponent extends react.Component2 {
503503
@override
504-
void componentDidMount() {
504+
componentDidMount() {
505505
if (!(props['errored'] as bool)) {
506506
throw _CustomException('It broke!', 2);
507507
}
@@ -546,7 +546,7 @@ class _Component2ErrorTestComponent extends react.Component2 {
546546
};
547547

548548
@override
549-
void componentDidCatch(error, info) {
549+
componentDidCatch(error, info) {
550550
if (error is _CustomException) {
551551
print(info.dartStackTrace);
552552
setState({'error': error.randomMessage});

test/factory/common_factory_tests.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ class EventTestCase {
651651
void simulate(Element node) => callMethod(_Simulate, _camelCaseEventName, [node]);
652652

653653
@override
654-
String toString() => 'EventHelper: ($eventPropKey) $description';
654+
toString() => 'EventHelper: ($eventPropKey) $description';
655655
}
656656

657657
extension on String {

test/js_builds/shared_tests.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ class _ErrorBoundaryComponent extends react.Component2 {
198198
Map get initialState => {'hasError': false};
199199

200200
@override
201-
Map getDerivedStateFromError(dynamic error) => {'hasError': true};
201+
getDerivedStateFromError(dynamic error) => {'hasError': true};
202202

203203
@override
204-
void componentDidCatch(dynamic error, ReactErrorInfo info) {
204+
componentDidCatch(dynamic error, ReactErrorInfo info) {
205205
props['onComponentDidCatch'](error, info);
206206
}
207207

test/lifecycle_test/component.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final SetStateTest = react.registerComponent(() => _SetStateTest()) as ReactDart
1212

1313
class _SetStateTest extends react.Component with LifecycleTestHelper {
1414
@override
15-
Map getDefaultProps() => const {'shouldUpdate': true};
15+
getDefaultProps() => const {'shouldUpdate': true};
1616

1717
@override
1818
getInitialState() => const {'counter': 1};
@@ -126,7 +126,7 @@ class _ContextWrapperWithoutKeys extends react.Component with LifecycleTestHelpe
126126
Iterable<String> get childContextKeys => const [];
127127

128128
@override
129-
Map<String, dynamic> getChildContext() {
129+
getChildContext() {
130130
lifecycleCall('getChildContext');
131131
return {
132132
'foo': props['foo'],
@@ -145,7 +145,7 @@ class _ContextWrapper extends react.Component with LifecycleTestHelper {
145145
Iterable<String> get childContextKeys => const ['foo', 'extraContext'];
146146

147147
@override
148-
Map<String, dynamic> getChildContext() {
148+
getChildContext() {
149149
lifecycleCall('getChildContext');
150150
return {
151151
'foo': props['foo'],
@@ -169,40 +169,40 @@ final LifecycleTest = react.registerComponent(() => _LifecycleTest()) as ReactDa
169169

170170
class _LifecycleTest extends react.Component with LifecycleTestHelper {
171171
@override
172-
void componentWillMount() => lifecycleCall('componentWillMount');
172+
componentWillMount() => lifecycleCall('componentWillMount');
173173
@override
174-
void componentDidMount() => lifecycleCall('componentDidMount');
174+
componentDidMount() => lifecycleCall('componentDidMount');
175175
@override
176-
void componentWillUnmount() => lifecycleCall('componentWillUnmount');
176+
componentWillUnmount() => lifecycleCall('componentWillUnmount');
177177

178178
@override
179-
void componentWillReceiveProps(newProps) =>
179+
componentWillReceiveProps(newProps) =>
180180
lifecycleCall('componentWillReceiveProps', arguments: [Map.from(newProps)]);
181181

182182
@override
183-
void componentWillReceivePropsWithContext(newProps, newContext) =>
183+
componentWillReceivePropsWithContext(newProps, newContext) =>
184184
lifecycleCall('componentWillReceivePropsWithContext',
185185
arguments: [Map.from(newProps), Map.from(newContext as Map)]);
186186

187187
@override
188-
void componentWillUpdate(nextProps, nextState) =>
188+
componentWillUpdate(nextProps, nextState) =>
189189
lifecycleCall('componentWillUpdate', arguments: [Map.from(nextProps), Map.from(nextState)]);
190190

191191
@override
192-
void componentWillUpdateWithContext(nextProps, nextState, nextContext) =>
192+
componentWillUpdateWithContext(nextProps, nextState, nextContext) =>
193193
lifecycleCall('componentWillUpdateWithContext',
194194
arguments: [Map.from(nextProps), Map.from(nextState), Map.from(nextContext)]);
195195

196196
@override
197-
void componentDidUpdate(prevProps, prevState) =>
197+
componentDidUpdate(prevProps, prevState) =>
198198
lifecycleCall('componentDidUpdate', arguments: [Map.from(prevProps), Map.from(prevState)]);
199199

200200
@override
201-
bool shouldComponentUpdate(nextProps, nextState) => lifecycleCall('shouldComponentUpdate',
201+
shouldComponentUpdate(nextProps, nextState) => lifecycleCall('shouldComponentUpdate',
202202
arguments: [Map.from(nextProps), Map.from(nextState)], defaultReturnValue: () => true);
203203

204204
@override
205-
bool shouldComponentUpdateWithContext(nextProps, nextState, nextContext) =>
205+
shouldComponentUpdateWithContext(nextProps, nextState, nextContext) =>
206206
lifecycleCall('shouldComponentUpdateWithContext',
207207
arguments: [Map.from(nextProps), Map.from(nextState), Map.from(nextContext)], defaultReturnValue: () => true);
208208

test/lifecycle_test/component2.dart

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class _SetStateTest extends react.Component2 with LifecycleTestHelper {
2828
};
2929

3030
@override
31-
Map getDerivedStateFromProps(_, __) {
31+
getDerivedStateFromProps(_, __) {
3232
lifecycleCall('getDerivedStateFromProps');
3333
return {};
3434
}
@@ -56,7 +56,7 @@ class _SetStateTest extends react.Component2 with LifecycleTestHelper {
5656
}
5757

5858
@override
59-
Map getDerivedStateFromError(error) {
59+
getDerivedStateFromError(error) {
6060
lifecycleCall('getDerivedStateFromError', arguments: [error]);
6161
return {'shouldThrow': false, 'errorFromGetDerivedState': error};
6262
}
@@ -176,7 +176,7 @@ final ContextConsumerWrapper = react.registerComponent2(() => _ContextConsumerWr
176176

177177
class _ContextConsumerWrapper extends react.Component2 with LifecycleTestHelper {
178178
@override
179-
dynamic render() {
179+
render() {
180180
return LifecycleTestContext.Consumer({}, props['children'].first);
181181
}
182182
}
@@ -185,7 +185,7 @@ final ContextWrapper = react.registerComponent2(() => _ContextWrapper());
185185

186186
class _ContextWrapper extends react.Component2 with LifecycleTestHelper {
187187
@override
188-
dynamic render() {
188+
render() {
189189
return LifecycleTestContext.Provider(
190190
{
191191
'value': {'foo': props['foo']}
@@ -233,34 +233,34 @@ final LifecycleTest = react.registerComponent2(() => _LifecycleTest());
233233

234234
class _LifecycleTest extends react.Component2 with LifecycleTestHelper {
235235
@override
236-
void componentDidMount() => lifecycleCall('componentDidMount');
236+
componentDidMount() => lifecycleCall('componentDidMount');
237237
@override
238-
void componentWillUnmount() => lifecycleCall('componentWillUnmount');
238+
componentWillUnmount() => lifecycleCall('componentWillUnmount');
239239

240240
@override
241-
Map getDerivedStateFromProps(nextProps, prevState) => lifecycleCall('getDerivedStateFromProps',
241+
getDerivedStateFromProps(nextProps, prevState) => lifecycleCall('getDerivedStateFromProps',
242242
arguments: [Map.from(nextProps), Map.from(prevState)], staticProps: nextProps);
243243

244244
@override
245-
dynamic getSnapshotBeforeUpdate(prevProps, prevState) =>
245+
getSnapshotBeforeUpdate(prevProps, prevState) =>
246246
lifecycleCall('getSnapshotBeforeUpdate', arguments: [Map.from(prevProps), Map.from(prevState)]);
247247

248248
@override
249-
void componentDidUpdate(prevProps, prevState, [snapshot]) =>
249+
componentDidUpdate(prevProps, prevState, [snapshot]) =>
250250
lifecycleCall('componentDidUpdate', arguments: [Map.from(prevProps), Map.from(prevState), snapshot]);
251251

252252
@override
253-
void componentDidCatch(error, info) => lifecycleCall('componentDidCatch', arguments: [error, info]);
253+
componentDidCatch(error, info) => lifecycleCall('componentDidCatch', arguments: [error, info]);
254254

255255
@override
256-
Map getDerivedStateFromError(error) => lifecycleCall('getDerivedStateFromError', arguments: [error]);
256+
getDerivedStateFromError(error) => lifecycleCall('getDerivedStateFromError', arguments: [error]);
257257

258258
@override
259-
bool shouldComponentUpdate(nextProps, nextState) => lifecycleCall('shouldComponentUpdate',
259+
shouldComponentUpdate(nextProps, nextState) => lifecycleCall('shouldComponentUpdate',
260260
arguments: [Map.from(nextProps), Map.from(nextState)], defaultReturnValue: () => true);
261261

262262
@override
263-
dynamic render() => lifecycleCall('render', defaultReturnValue: () => react.div({}));
263+
render() => lifecycleCall('render', defaultReturnValue: () => react.div({}));
264264

265265
@override
266266
Map get initialState => lifecycleCall('initialState', defaultReturnValue: () => {});
@@ -274,31 +274,31 @@ final NoGetDerivedStateFromErrorLifecycleTest =
274274

275275
class _NoGetDerivedStateFromErrorLifecycleTest extends react.Component2 with LifecycleTestHelper {
276276
@override
277-
void componentDidMount() => lifecycleCall('componentDidMount');
277+
componentDidMount() => lifecycleCall('componentDidMount');
278278
@override
279-
void componentWillUnmount() => lifecycleCall('componentWillUnmount');
279+
componentWillUnmount() => lifecycleCall('componentWillUnmount');
280280

281281
@override
282-
Map getDerivedStateFromProps(nextProps, prevState) => lifecycleCall('getDerivedStateFromProps',
282+
getDerivedStateFromProps(nextProps, prevState) => lifecycleCall('getDerivedStateFromProps',
283283
arguments: [Map.from(nextProps), Map.from(prevState)], staticProps: nextProps);
284284

285285
@override
286-
dynamic getSnapshotBeforeUpdate(prevProps, prevState) =>
286+
getSnapshotBeforeUpdate(prevProps, prevState) =>
287287
lifecycleCall('getSnapshotBeforeUpdate', arguments: [Map.from(prevProps), Map.from(prevState)]);
288288

289289
@override
290-
void componentDidUpdate(prevProps, prevState, [snapshot]) =>
290+
componentDidUpdate(prevProps, prevState, [snapshot]) =>
291291
lifecycleCall('componentDidUpdate', arguments: [Map.from(prevProps), Map.from(prevState), snapshot]);
292292

293293
@override
294-
void componentDidCatch(error, info) => lifecycleCall('componentDidCatch', arguments: [error, info]);
294+
componentDidCatch(error, info) => lifecycleCall('componentDidCatch', arguments: [error, info]);
295295

296296
@override
297-
bool shouldComponentUpdate(nextProps, nextState) => lifecycleCall('shouldComponentUpdate',
297+
shouldComponentUpdate(nextProps, nextState) => lifecycleCall('shouldComponentUpdate',
298298
arguments: [Map.from(nextProps), Map.from(nextState)], defaultReturnValue: () => true);
299299

300300
@override
301-
dynamic render() => lifecycleCall('render', defaultReturnValue: () => react.div({}));
301+
render() => lifecycleCall('render', defaultReturnValue: () => react.div({}));
302302

303303
@override
304304
Map get initialState => lifecycleCall('initialState', defaultReturnValue: () => {});

test/react_client_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ final testJsComponentFactory = (() {
217217

218218
class ThrowsInDefaultPropsComponent extends Component {
219219
@override
220-
Map getDefaultProps() => throw StateError('bad default props');
220+
getDefaultProps() => throw StateError('bad default props');
221221

222222
@override
223223
render() {

test/react_memo_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class _MemoTestWrapperComponent extends react.Component2 {
182182
};
183183

184184
@override
185-
void componentDidUpdate(Map prevProps, Map prevState, [dynamic snapshot]) {
185+
componentDidUpdate(Map prevProps, Map prevState, [dynamic snapshot]) {
186186
redrawCount++;
187187
}
188188

0 commit comments

Comments
 (0)