Skip to content

Commit

Permalink
Clean up todos
Browse files Browse the repository at this point in the history
  • Loading branch information
sydneyjodon-wk committed Mar 20, 2024
1 parent 4f0ae6b commit 1660c92
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,27 @@ final _log = Logger('CallbackRefHintSuggestor');

/// Suggestor to add nullability hints to ref types.
///
/// todo doc comment examples
/// (1) For ref prop param types:
/// ```
/// - (ButtonToolbar()..ref = (ButtonElement r) => ref = r)();
/// + (ButtonToolbar()..ref = (ButtonElement /*?*/ r) => ref = r)();
/// ```
///
/// (2) For ref variable declarations:
/// ```
/// - ButtonElement ref;
/// + ButtonElement /*?*/ ref;
/// (ButtonToolbar()..ref = (r) => ref = r)();
/// ```
///
/// (3) For ref prop type casts:
/// ```
/// - (ButtonToolbar()..ref = (r) => ref = r as ButtonElement)();
/// + (ButtonToolbar()..ref = (r) => ref = r as ButtonElement /*?*/)();
/// ```
///
/// These hints are needed because the null-safety migration tool does not do
/// well at inferring that ref types should be nullable.
class CallbackRefHintSuggestor extends RecursiveAstVisitor<void>
with ClassSuggestor {
CallbackRefHintSuggestor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import '../../mui_suggestors/components/shared.dart';
import '../../resolved_file_context.dart';
import '../../util.dart';

// todo add block function, and other test cases, non-ref prop names, mui/dom usages

void main() {
final resolvedContext = SharedAnalysisContext.wsd;

Expand All @@ -41,15 +39,15 @@ void main() {
content() {
var ref;
(ButtonToolbar()..ref = (ButtonElement r) => ref = r)();
(ButtonToolbar()..ref = (ButtonElement r) { ref = r; })();
(Dom.div()..ref = (ButtonElement r) { ref = r; })();
ref;
}
'''),
expectedOutput: withOverReactAndWsdImports(/*language=dart*/ '''
content() {
var ref;
(ButtonToolbar()..ref = (ButtonElement /*?*/ r) => ref = r)();
(ButtonToolbar()..ref = (ButtonElement /*?*/ r) { ref = r; })();
(Dom.div()..ref = (ButtonElement /*?*/ r) { ref = r; })();
ref;
}
'''),
Expand All @@ -62,15 +60,15 @@ void main() {
content() {
var ref;
(ButtonToolbar()..ref = (ButtonElement r) => ref = r);
(ButtonToolbar()..ref = (ButtonElement r) { ref = r; });
(Dom.div()..ref = (ButtonElement r) { ref = r; });
ref;
}
'''),
expectedOutput: withOverReactAndWsdImports(/*language=dart*/ '''
content() {
var ref;
(ButtonToolbar()..ref = (ButtonElement /*?*/ r) => ref = r);
(ButtonToolbar()..ref = (ButtonElement /*?*/ r) { ref = r; });
(Dom.div()..ref = (ButtonElement /*?*/ r) { ref = r; });
ref;
}
'''),
Expand All @@ -85,15 +83,15 @@ void main() {
content() {
var ref;
(ButtonToolbar()..ref = (r) => ref = r as ButtonElement)();
(ButtonToolbar()..ref = (r) { ref = r as ButtonElement; })();
(Dom.div()..ref = (r) { ref = r as ButtonElement; })();
ref;
}
'''),
expectedOutput: withOverReactAndWsdImports(/*language=dart*/ '''
content() {
var ref;
(ButtonToolbar()..ref = (r) => ref = r as ButtonElement /*?*/)();
(ButtonToolbar()..ref = (r) { ref = r as ButtonElement /*?*/; })();
(Dom.div()..ref = (r) { ref = r as ButtonElement /*?*/; })();
ref;
}
'''),
Expand All @@ -106,15 +104,15 @@ void main() {
content() {
var ref;
(ButtonToolbar()..ref = (r) => ref = r as ButtonElement);
(ButtonToolbar()..ref = (r) { ref = r as ButtonElement; });
(Dom.div()..ref = (r) { ref = r as ButtonElement; });
ref;
}
'''),
expectedOutput: withOverReactAndWsdImports(/*language=dart*/ '''
content() {
var ref;
(ButtonToolbar()..ref = (r) => ref = r as ButtonElement /*?*/);
(ButtonToolbar()..ref = (r) { ref = r as ButtonElement /*?*/; });
(Dom.div()..ref = (r) { ref = r as ButtonElement /*?*/; });
ref;
}
'''),
Expand All @@ -134,7 +132,7 @@ void main() {
ref as int;
ref = r as ButtonElement;
})();
(ButtonToolbar()
(Dom.div()
..ref = (ButtonElement r) {
ref = r as int;
ref = a as ButtonElement;
Expand All @@ -155,7 +153,7 @@ void main() {
ref as int;
ref = r as ButtonElement /*?*/;
})();
(ButtonToolbar()
(Dom.div()
..ref = (ButtonElement /*?*/ r) {
ref = r as int /*?*/;
ref = a as ButtonElement;
Expand All @@ -178,7 +176,7 @@ void main() {
ButtonElement ref2;
ButtonElement ref3;
(ButtonToolbar()..ref = (r) => ref1 = r)();
(ButtonToolbar()..ref = (r) {
(Dom.div()..ref = (r) {
ButtonElement ref4;
ref2 = r;
final a = ButtonElement();
Expand All @@ -197,7 +195,7 @@ void main() {
ButtonElement /*?*/ ref2;
ButtonElement ref3;
(ButtonToolbar()..ref = (r) => ref1 = r)();
(ButtonToolbar()..ref = (r) {
(Dom.div()..ref = (r) {
ButtonElement /*?*/ ref4;
ref2 = r;
final a = ButtonElement();
Expand Down Expand Up @@ -249,15 +247,34 @@ void main() {
content() {
ButtonElement /*?*/ ref;
(ButtonToolbar()..ref = (ButtonElement /*?*/ r) => ref = r)();
(ButtonToolbar()..ref = (r) { ref = r as ButtonElement /*?*/; })();
(Dom.div()..ref = (r) { ref = r as ButtonElement /*?*/; })();
ref;
}
'''),
expectedOutput: withOverReactAndWsdImports(/*language=dart*/ '''
content() {
ButtonElement /*?*/ ref;
(ButtonToolbar()..ref = (ButtonElement /*?*/ r) => ref = r)();
(ButtonToolbar()..ref = (r) { ref = r as ButtonElement /*?*/; })();
(Dom.div()..ref = (r) { ref = r as ButtonElement /*?*/; })();
ref;
}
'''),
);
});

test('does not add hints for non-ref props', () async {
await testSuggestor(
input: withOverReactAndWsdImports(/*language=dart*/ '''
content() {
ButtonElement ref;
(ButtonToolbar()..onClick = (r) { ref = r as ButtonElement; })();
ref;
}
'''),
expectedOutput: withOverReactAndWsdImports(/*language=dart*/ '''
content() {
ButtonElement ref;
(ButtonToolbar()..onClick = (r) { ref = r as ButtonElement; })();
ref;
}
'''),
Expand Down

0 comments on commit 1660c92

Please sign in to comment.