Skip to content

Commit

Permalink
enable strict-inference, strict-raw-types
Browse files Browse the repository at this point in the history
  • Loading branch information
devoncarew committed May 5, 2023
1 parent 47ca147 commit 405d2fa
Show file tree
Hide file tree
Showing 31 changed files with 125 additions and 110 deletions.
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ include: package:dart_flutter_team_lints/analysis_options.yaml
analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true
exclude:
- "build/**"
- "doc/api/**"
Expand Down
6 changes: 3 additions & 3 deletions lib/completion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DartCompleter extends CodeCompleter {
final ds.DartservicesApi servicesApi;
final Document document;

CancelableCompleter? _lastCompleter;
CancelableCompleter<CompletionResult>? _lastCompleter;

DartCompleter(this.servicesApi, this.document);

Expand Down Expand Up @@ -169,8 +169,8 @@ class DartCompleter extends CodeCompleter {
replaceOffset: replaceOffset,
replaceLength: replaceLength,
));
}).catchError((e) {
completer.completeError(e as Object);
}).catchError((Object e) {
completer.completeError(e);
});
}

Expand Down
8 changes: 4 additions & 4 deletions lib/core/keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final bool _isMac =
/// Map key events into commands.
class Keys {
final _bindings = <String, Action>{};
late StreamSubscription _sub;
late StreamSubscription<KeyboardEvent> _sub;
bool _loggedException = false;

Keys() {
Expand Down Expand Up @@ -124,7 +124,7 @@ String? makeKeyPresentable(String key) {
}
keyAsList = keyAsList.map<String?>((s) {
if (_unicodeMac.containsKey(s)) {
return _unicodeMac[s] as String?;
return _unicodeMac[s];
} else {
return capitalize(s);
}
Expand All @@ -141,7 +141,7 @@ String? makeKeyPresentable(String key) {

bool isMac() => _isMac;

const Map _codeMap = {
const Map<int, String> _codeMap = {
KeyCode.ZERO: '0',
KeyCode.ONE: '1',
KeyCode.TWO: '2',
Expand Down Expand Up @@ -234,7 +234,7 @@ const Map _codeMap = {
KeyCode.SHIFT: '', //
};

const Map _unicodeMac = {
const Map<String, String> _unicodeMac = {
'macctrl': '\u2303',
'alt': '\u2325',
'shift': '\u21E7',
Expand Down
8 changes: 3 additions & 5 deletions lib/core/modules.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

library core.modules;

// TODO: test

export 'dart:async' show Future;

abstract class Module {
Future init();
Future<void> init();
}

/// Maintains a list of active modules.
Expand All @@ -31,15 +29,15 @@ class ModuleManager {

bool get started => _started;

Future start() {
Future<void> start() {
if (_started) return Future.value();

_started = true;

return Future.forEach(modules, _startModule);
}

Future _startModule(Module module) {
Future<void> _startModule(Module module) {
// TODO: log errors
return module.init().catchError(print).whenComplete(() {
_inited.add(module);
Expand Down
2 changes: 1 addition & 1 deletion lib/editing/codemirror_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const codeMirrorOptions = {
'whenOpening': true,
'whenClosing': true,
'indentTags':
[] // Android Studio/VSCode do not auto indent/add newlines for any completed tags
<String>[], // Android Studio/VSCode do not auto indent/add newlines for any completed tags
// The default (below) would be the following tags cause indenting and blank line inserted
// ['applet', 'blockquote', 'body', 'button', 'div', 'dl', 'fieldset',
// 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head',
Expand Down
4 changes: 2 additions & 2 deletions lib/editing/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ abstract class Editor {
Stream<html.MouseEvent> get onMouseDown;

/// Fired when the current current vim mode changes.
Stream get onVimModeChange;
Stream<void> get onVimModeChange;

void resize();

Expand Down Expand Up @@ -162,7 +162,7 @@ abstract class Document<E extends Editor> {

void applyEdit(SourceEdit edit);

Stream get onChange;
Stream<void> get onChange;
}

class Annotation implements Comparable<Annotation> {
Expand Down
10 changes: 6 additions & 4 deletions lib/editing/editor_codemirror.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ class CodeMirrorFactory extends EditorFactory {
List<String> get themes => CodeMirror.themes;

@override
Editor createFromElement(html.Element element,
{Map options = codeMirrorOptions}) {
Editor createFromElement(
html.Element element, {
Map<String, Object> options = codeMirrorOptions,
}) {
final editor = CodeMirror.fromElement(element, options: options);
CodeMirror.addCommand('goLineLeft', _handleGoLineLeft);
CodeMirror.addCommand('indentIfMultiLineSelectionElseInsertSoftTab',
Expand Down Expand Up @@ -347,7 +349,7 @@ class _CodeMirrorEditor extends Editor {
Stream<html.MouseEvent> get onMouseDown => cm.onMouseDown;

@override
Stream get onVimModeChange => cm.onEvent('vim-mode-change');
Stream<void> get onVimModeChange => cm.onEvent('vim-mode-change');

@override
Point getCursorCoords({ed.Position? position}) {
Expand Down Expand Up @@ -516,7 +518,7 @@ class _CodeMirrorDocument extends Document<_CodeMirrorEditor> {
ed.Position(position.line!, position.ch!);

@override
Stream get onChange {
Stream<void> get onChange {
return doc.onChange.where((_) {
if (value != _lastSetValue) {
_lastSetValue = null;
Expand Down
20 changes: 10 additions & 10 deletions lib/elements/bind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ library dart_pad.bind;
import 'dart:async';

/// Bind changes from `from` to the target `to`.
Binding bind(Property from, Property to) {
Binding bind<T>(Property<T> from, Property<T> to) {
return _PropertyBinding(from, to);
}

Expand All @@ -16,13 +16,13 @@ Binding bind(Property from, Property to) {
abstract class Property<T> {
T get();
void set(T value);
Stream<T?>? get onChanged;
Stream<T>? get onChanged;
}

/// An object that can own a set of properties.
abstract class PropertyOwner {
abstract class PropertyOwner<T> {
List<String> get propertyNames;
Property property(String name);
Property<T> property(String name);
}

/// An instantiation of a binding from one element to another. [Binding]s can be
Expand All @@ -38,11 +38,11 @@ abstract class Binding {
void cancel();
}

class _PropertyBinding implements Binding {
final Property property;
final Property target;
class _PropertyBinding<T> implements Binding {
final Property<T> property;
final Property<T> target;

StreamSubscription? _sub;
StreamSubscription<T>? _sub;

_PropertyBinding(this.property, this.target) {
final stream = property.onChanged;
Expand All @@ -57,9 +57,9 @@ class _PropertyBinding implements Binding {
if (_sub != null) _sub!.cancel();
}

void _handleEvent(e) => _sendTo(target, e);
void _handleEvent(T e) => _sendTo(target, e);
}

void _sendTo(Property target, e) {
void _sendTo<T>(Property<T> target, T e) {
if (e != target.get()) target.set(e);
}
2 changes: 1 addition & 1 deletion lib/elements/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Dialog {
_rightButton!.text = rightButtonText;

final completer = Completer<DialogResult>();
StreamSubscription? leftSub;
StreamSubscription<MouseEvent>? leftSub;

if (showLeftButton) {
_leftButton!.text = leftButtonText;
Expand Down
6 changes: 3 additions & 3 deletions lib/elements/elements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DElement {
element.text = value;
}

Property get textProperty => _ElementTextProperty(element);
Property<String?> get textProperty => _ElementTextProperty(element);

void layoutHorizontal() {
setAttr('layout');
Expand Down Expand Up @@ -267,7 +267,7 @@ class DToast extends DElement {
}

class GlassPane extends DElement {
final _controller = StreamController.broadcast();
final _controller = StreamController<void>.broadcast();

GlassPane() : super.tag('div') {
element.classes.toggle('glass-pane', true);
Expand All @@ -293,7 +293,7 @@ class GlassPane extends DElement {

bool get isShowing => document.body!.children.contains(element);

Stream get onCancel => _controller.stream;
Stream<void> get onCancel => _controller.stream;
}

abstract class DDialog extends DElement {
Expand Down
14 changes: 9 additions & 5 deletions lib/embed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1213,9 +1213,9 @@ class EmbedContext extends Context {
solutionSource = value;
}

final _dartDirtyController = StreamController.broadcast();
final _dartDirtyController = StreamController<void>.broadcast();

final _dartReconcileController = StreamController.broadcast();
final _dartReconcileController = StreamController<void>.broadcast();

EmbedContext(this.editor, this._testAndSolutionReadOnly)
: _dartDoc = editor.document,
Expand Down Expand Up @@ -1339,16 +1339,20 @@ class EmbedContext extends Context {
@override
String get activeMode => editor.mode;

Stream get onDartDirty => _dartDirtyController.stream;
Stream<void> get onDartDirty => _dartDirtyController.stream;

Stream get onDartReconcile => _dartReconcileController.stream;
Stream<void> get onDartReconcile => _dartReconcileController.stream;

void markDartClean() => _dartDoc.markClean();

/// Restore the focus to the last focused editor.
void focus() => editor.focus();

void _createReconciler(Document doc, StreamController controller, int delay) {
void _createReconciler(
Document doc,
StreamController<void> controller,
int delay,
) {
Timer? timer;
doc.onChange.listen((_) {
timer?.cancel();
Expand Down
23 changes: 14 additions & 9 deletions lib/github.dart
Original file line number Diff line number Diff line change
Expand Up @@ -625,17 +625,18 @@ class GitHubAuthenticationController {

final _authenticatedStateChangeController =
StreamController<bool>.broadcast();
final _myGistListUpdateController = StreamController.broadcast();
final _starredGistListUpdateController = StreamController.broadcast();
final _gistStarredCheckerReportController = StreamController.broadcast();
final _myGistListUpdateController = StreamController<void>.broadcast();
final _starredGistListUpdateController = StreamController<void>.broadcast();
final _gistStarredCheckerReportController =
StreamController<void>.broadcast();

Stream<bool> get onAuthStateChanged =>
_authenticatedStateChangeController.stream;

Stream get onMyGistListChanged => _myGistListUpdateController.stream;
Stream get onStarredGistListChanged =>
Stream<void> get onMyGistListChanged => _myGistListUpdateController.stream;
Stream<void> get onStarredGistListChanged =>
_starredGistListUpdateController.stream;
Stream get onGistStarredCheckerReport =>
Stream<void> get onGistStarredCheckerReport =>
_gistStarredCheckerReportController.stream;

final List<Gist> _myGistList = [];
Expand All @@ -648,8 +649,11 @@ class GitHubAuthenticationController {
String? _pendingUserGistRequest;
String? _pendingUserStarredGistRequest;

GitHubAuthenticationController(this.launchUri, this.snackbar,
{http.Client? client}) {
GitHubAuthenticationController(
this.launchUri,
this.snackbar, {
http.Client? client,
}) {
// Check for parameters in query uri.
_client = client ?? http.Client();

Expand All @@ -676,7 +680,8 @@ class GitHubAuthenticationController {
json.decode(perAuthParamsJson) as Map<dynamic, dynamic>);

final restoredUrl = launchUri.replace(queryParameters: restoreParams);
window.history.replaceState({}, 'DartPad', restoredUrl.toString());
window.history.replaceState(
<String, dynamic>{}, 'DartPad', restoredUrl.toString());
} catch (e) {
window.console.log(
'Caught exception doing restoreParams : exception ${e.toString()}');
Expand Down
2 changes: 1 addition & 1 deletion lib/inject/inject_embed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class InjectedEmbed {
_init();
}

Future _init() async {
Future<void> _init() async {
host.children.clear();

final iframe = IFrameElement()..attributes = {'src': iframeSrc(options)};
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/codemirror_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CodeMirrorModule extends Module {
static String? get version => codeMirrorFactory.version;

@override
Future init() async {
Future<void> init() async {
deps[EditorFactory] = codeMirrorFactory;
}
}
2 changes: 1 addition & 1 deletion lib/modules/dart_pad_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '../elements/state.dart';

class DartPadModule extends Module {
@override
Future init() {
Future<void> init() {
Dependencies.setGlobalInstance(Dependencies());

deps[Keys] = Keys();
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/dartservices_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SanitizingBrowserClient extends BrowserClient {

class DartServicesModule extends Module {
@override
Future init() {
Future<void> init() {
final client = SanitizingBrowserClient();
deps[BrowserClient] = client;
deps[DartservicesApi] = DartservicesApi(client, rootUrl: serverUrl);
Expand Down
Loading

0 comments on commit 405d2fa

Please sign in to comment.