Skip to content

Commit

Permalink
[web] Code cleanup (flutter#27741)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatb authored Jul 27, 2021
1 parent 247334f commit 29790e3
Show file tree
Hide file tree
Showing 54 changed files with 153 additions and 163 deletions.
10 changes: 0 additions & 10 deletions lib/web_ui/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ linter:
prefer_conditional_assignment: false
prefer_const_constructors: false
prefer_const_constructors_in_immutables: false
prefer_const_declarations: false
prefer_const_literals_to_create_immutables: false
prefer_foreach: false
prefer_generic_function_type_aliases: false
prefer_initializing_formals: false
Expand All @@ -37,14 +35,6 @@ linter:
recursive_getters: false
slash_for_doc_comments: false
sort_unnamed_constructors_first: false
test_types_in_equals: false
throw_in_finally: false
type_init_formals: false
unnecessary_getters_setters: false
use_rethrow_when_possible: false
valid_regexps: false
use_function_type_syntax_for_parameters: false
avoid_single_cascade_in_expression_statements: false
flutter_style_todos: false

# We have some legitimate use-cases for this (preserve tear-off identity)
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/dev/browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ abstract class Browser {
/// which asynchronously returns the browser process. Any errors in
/// [startBrowser] (even those raised asynchronously after it returns) are
/// piped to [onExit] and will cause the browser to be killed.
Browser(Future<Process> startBrowser()) {
Browser(Future<Process> Function() startBrowser) {
// Don't return a Future here because there's no need for the caller to wait
// for the process to actually start. They should just wait for the HTTP
// request instead.
Expand Down
3 changes: 1 addition & 2 deletions lib/web_ui/dev/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import 'watcher.dart';

class BuildCommand extends Command<bool> with ArgUtils<bool> {
BuildCommand() {
argParser
..addFlag(
argParser.addFlag(
'watch',
defaultsTo: false,
abbr: 'w',
Expand Down
7 changes: 4 additions & 3 deletions lib/web_ui/dev/chrome.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Chrome extends Browser {
}, remoteDebuggerCompleter.future);
}

Chrome._(Future<Process> startBrowser(), this.remoteDebuggerUrl)
Chrome._(Future<Process> Function() startBrowser, this.remoteDebuggerUrl)
: super(startBrowser);
}

Expand Down Expand Up @@ -157,8 +157,9 @@ Future<Process> _spawnChromiumProcess(String executable, List<String> args, { St
})
.firstWhere((String line) => line.startsWith('DevTools listening'), orElse: () {
if (hitGlibcBug) {
final String message = 'Encountered glibc bug https://sourceware.org/bugzilla/show_bug.cgi?id=19329. '
'Will try launching browser again.';
const String message = 'Encountered glibc bug '
'https://sourceware.org/bugzilla/show_bug.cgi?id=19329. '
'Will try launching browser again.';
print(message);
return message;
}
Expand Down
7 changes: 3 additions & 4 deletions lib/web_ui/dev/chrome_installer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ class ChromeArgParser extends BrowserArgParser {
_pinnedChromeBuildNumber =
PlatformBinding.instance.getChromeBuild(browserLock);

argParser
..addOption(
argParser.addOption(
'chrome-version',
defaultsTo: pinnedChromeBuildNumber,
help: 'The Chrome version to use while running tests. If the requested '
Expand Down Expand Up @@ -234,8 +233,8 @@ class ChromeInstaller {
..createSync(recursive: true)
..writeAsBytesSync(data);
} else {
io.Directory(path.join(versionDir.path, filename))
..create(recursive: true);
io.Directory(path.join(versionDir.path, filename)).create(
recursive: true);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/dev/create_simulator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CreateSimulatorCommand extends Command<bool> with ArgUtils<bool> {
CreateSimulatorCommand() {
IosSafariArgParser.instance.populateOptions(argParser);
argParser
..addOption(
.addOption(
'type',
defaultsTo: _defaultType,
help: 'Type of the mobile simulator. Currently the only iOS '
Expand All @@ -24,7 +24,7 @@ class CreateSimulatorCommand extends Command<bool> with ArgUtils<bool> {
}

/// Currently the only iOS Simulators are supported.
static final String _defaultType = 'iOS';
static const String _defaultType = 'iOS';

@override
String get name => 'create_simulator';
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/dev/edge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ class Edge extends Browser {
});
}

Edge._(Future<Process> startBrowser()) : super(startBrowser);
Edge._(Future<Process> Function() startBrowser) : super(startBrowser);
}
3 changes: 1 addition & 2 deletions lib/web_ui/dev/edge_installation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class EdgeArgParser extends BrowserArgParser {

@override
void populateOptions(ArgParser argParser) {
argParser
..addOption(
argParser.addOption(
'edge-version',
defaultsTo: 'system',
help: 'The Edge version to use while running tests. The Edge '
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/dev/firefox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Firefox extends Browser {
);

// Using a profile on opening will prevent popups related to profiles.
final String _profile = '''
const String _profile = '''
user_pref("browser.shell.checkDefaultBrowser", false);
user_pref("dom.disable_open_during_load", false);
user_pref("dom.max_script_run_time", 0);
Expand Down Expand Up @@ -111,6 +111,6 @@ user_pref("dom.max_script_run_time", 0);
}, remoteDebuggerCompleter.future);
}

Firefox._(Future<Process> startBrowser(), this.remoteDebuggerUrl)
Firefox._(Future<Process> Function() startBrowser, this.remoteDebuggerUrl)
: super(startBrowser);
}
3 changes: 1 addition & 2 deletions lib/web_ui/dev/firefox_installer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class FirefoxArgParser extends BrowserArgParser {
final YamlMap browserLock = BrowserLock.instance.configuration;
final String firefoxVersion = browserLock['firefox']['version'] as String;

argParser
..addOption(
argParser.addOption(
'firefox-version',
defaultsTo: firefoxVersion,
help: 'The Firefox version to use while running tests. If the requested '
Expand Down
3 changes: 1 addition & 2 deletions lib/web_ui/dev/safari_installation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class SafariArgParser extends BrowserArgParser {

@override
void populateOptions(ArgParser argParser) {
argParser
..addOption(
argParser.addOption(
'safari-version',
defaultsTo: 'system',
help: 'The Safari version to use while running tests. The Safari '
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/dev/safari_ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SafariIos extends Browser {
});
}

SafariIos._(Future<io.Process> startBrowser()) : super(startBrowser);
SafariIos._(Future<io.Process> Function() startBrowser) : super(startBrowser);
}

/// [ScreenshotManager] implementation for Safari.
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/dev/safari_macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ class SafariMacOs extends Browser {
});
}

SafariMacOs._(Future<Process> startBrowser()) : super(startBrowser);
SafariMacOs._(Future<Process> Function() startBrowser) : super(startBrowser);
}
3 changes: 1 addition & 2 deletions lib/web_ui/dev/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ class GeneralTestsArgumentParser {
bool verbose = false;

void populateOptions(ArgParser argParser) {
argParser
..addFlag(
argParser.addFlag(
'verbose',
defaultsTo: false,
help: 'Flag to indicate extra logs should also be printed.',
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/canvaskit/initialization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ const String canvasKitBaseUrl = String.fromEnvironment(
'FLUTTER_WEB_CANVASKIT_URL',
defaultValue: 'https://unpkg.com/[email protected]/bin/',
);
final String canvasKitBuildUrl =
const String canvasKitBuildUrl =
canvasKitBaseUrl + (kProfileMode ? 'profiling/' : '');
final String canvasKitJavaScriptBindingsUrl =
const String canvasKitJavaScriptBindingsUrl =
canvasKitBuildUrl + 'canvaskit.js';
String canvasKitWasmModuleUrl(String file) => _currentCanvasKitBase! + file;

Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/canvaskit/surface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class Surface {
final int surfaceHeight = _currentSurfaceSize!.height.ceil();
final double offset =
(_pixelHeight - surfaceHeight) / window.devicePixelRatio;
htmlCanvas!.style..transform = 'translate(0, -${offset}px)';
htmlCanvas!.style.transform = 'translate(0, -${offset}px)';
}

void _contextRestoredListener(html.Event event) {
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/frame_reference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CrossFrameCache<T> {

void _addToCache(String key, _CrossFrameCacheItem<T> item) {
_cache ??= <String, List<_CrossFrameCacheItem<T>>>{};
(_cache![key] ??= <_CrossFrameCacheItem<T>>[])..add(item);
(_cache![key] ??= <_CrossFrameCacheItem<T>>[]).add(item);
}

/// Given a key, consumes an item that has been cached in a prior frame.
Expand Down
6 changes: 3 additions & 3 deletions lib/web_ui/lib/src/engine/html/path/conic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@ class Conic {
// Map conic to 3D.
final double tx0 = p0x;
final double ty0 = p0y;
final double tz0 = 1;
const double tz0 = 1;
final double tx1 = p1x * fW;
final double ty1 = p1y * fW;
final double tz1 = fW;
final double tx2 = p2x;
final double ty2 = p2y;
final double tz2 = 1;
const double tz2 = 1;
// Now interpolate each dimension.
final double dx0 = tx0 + (tx1 - tx0) * t;
final double dx2 = tx1 + (tx2 - tx1) * t;
Expand Down Expand Up @@ -335,7 +335,7 @@ class Conic {

static double evalDenominator(double w, double t) {
final double B = 2 * (w - 1);
final double C = 1;
const double C = 1;
final double A = -B;
return polyEval(A, B, C, t);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/html/path/cubic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ double? chopMonoAtY(Float32List _buffer, int bufferStartPos, double y) {
}

// Bisection / linear convergance.
final double tolerance = 1.0 / 65536;
const double tolerance = 1.0 / 65536;
do {
final double tMid = (tPos + tNeg) / 2.0;
final double y01 = ycrv0 + (ycrv1 - ycrv0) * tMid;
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/html/path/path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ class SurfacePath implements ui.Path {
assert(direction != SPathDirection.kUnknown);
final bool isOval = _hasOnlyMoveTos();

final double weight = SPath.scalarRoot2Over2;
const double weight = SPath.scalarRoot2Over2;
final double left = oval.left;
final double right = oval.right;
final double centerX = (left + right) / 2.0;
Expand Down Expand Up @@ -1018,7 +1018,7 @@ class SurfacePath implements ui.Path {
// degenerate(oval) => line points are collapsing.
_addOval(bounds, direction, startIndex ~/ 2);
} else {
final double weight = SPath.scalarRoot2Over2;
const double weight = SPath.scalarRoot2Over2;
final double left = bounds.left;
final double right = bounds.right;
final double top = bounds.top;
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/html/path/path_ref.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class PathRef {
if (other.runtimeType != runtimeType) {
return false;
}
return equals(other as PathRef);
return other is PathRef && equals(other);
}

@override
Expand Down Expand Up @@ -876,7 +876,7 @@ class PathRef {
for (int i = 0; i < len; i += 2) {
final double pointX = fPoints[i];
final double pointY = fPoints[i + 1];
final double tolerance = 0.0001;
const double tolerance = 0.0001;
final bool pointIsFinite = pointX.isFinite && pointY.isFinite;
if (pointIsFinite &&
(pointX + tolerance < boundsLeft ||
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/html/path/path_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class Convexicator {
math.max(curVecX, math.max(curVecY, math.max(lastX, lastY))),
-smallest);
if (SPath.nearlyEqual(largest, largest + cross)) {
final double nearlyZeroSquared =
const double nearlyZeroSquared =
SPath.scalarNearlyZero * SPath.scalarNearlyZero;
if (SPath.nearlyEqual(lengthSquared(lastX, lastY), nearlyZeroSquared) ||
SPath.nearlyEqual(lengthSquared(curVecX, curVecY), nearlyZeroSquared)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/html/shader_mask.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class PersistedShaderMask extends PersistedContainerSurface
html.Element createElement() {
final html.Element element = defaultCreateElement('flt-shader-mask');
final html.Element container = html.Element.tag('flt-mask-interior');
container.style..position = 'absolute';
container.style.position = 'absolute';
_childContainer = container;
element.append(_childContainer!);
return element;
Expand Down
10 changes: 3 additions & 7 deletions lib/web_ui/lib/src/engine/html/surface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,7 @@ abstract class PersistedSurface implements ui.EngineLayer {
/// transforms as well as this layer's transform (if any).
///
/// The value is update by [recomputeTransformAndClip].
Matrix4? get transform => _transform;
set transform(Matrix4? value) {
_transform = value;
}
Matrix4? _transform;
Matrix4? transform;

/// The intersection at this surface level.
///
Expand All @@ -555,7 +551,7 @@ abstract class PersistedSurface implements ui.EngineLayer {
///
/// This method is called by the [preroll] method.
void recomputeTransformAndClip() {
_transform = parent!._transform;
transform = parent!.transform;
localClipBounds = null;
projectedClip = null;
}
Expand Down Expand Up @@ -661,7 +657,7 @@ abstract class PersistedContainerSurface extends PersistedSurface {

@override
void recomputeTransformAndClip() {
_transform = parent!._transform;
transform = parent!.transform;
localClipBounds = null;
projectedClip = null;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ bool _handleWebTestEnd2EndMessage(MethodCodec codec, ByteData? data) {
}

/// Invokes [callback] inside the given [zone].
void invoke(void callback()?, Zone? zone) {
void invoke(void Function()? callback, Zone? zone) {
if (callback == null) {
return;
}
Expand All @@ -1027,7 +1027,7 @@ void invoke(void callback()?, Zone? zone) {
}

/// Invokes [callback] inside the given [zone] passing it [arg].
void invoke1<A>(void callback(A a)?, Zone? zone, A arg) {
void invoke1<A>(void Function(A a)? callback, Zone? zone, A arg) {
if (callback == null) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/text/measurement.dart
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ class CanvasTextMeasurementService extends TextMeasurementService {
maxIntrinsicWidth: maxIntrinsicCalculator.value,
width: constraints.width,
lines: linesCalculator.lines,
placeholderBoxes: <ui.TextBox>[],
placeholderBoxes: const <ui.TextBox>[],
textAlign: paragraph.textAlign,
textDirection: paragraph.textDirection,
);
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/test/canvas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void testMain() {
}

testCanvas('draws laid out paragraph', (EngineCanvas canvas) {
final ui.Rect screenRect = const ui.Rect.fromLTWH(0, 0, 100, 100);
const ui.Rect screenRect = ui.Rect.fromLTWH(0, 0, 100, 100);
final RecordingCanvas recordingCanvas = RecordingCanvas(screenRect);
final ui.ParagraphBuilder builder =
ui.ParagraphBuilder(ui.ParagraphStyle());
Expand All @@ -63,7 +63,7 @@ void testMain() {

testCanvas('ignores paragraphs that were not laid out',
(EngineCanvas canvas) {
final ui.Rect screenRect = const ui.Rect.fromLTWH(0, 0, 100, 100);
const ui.Rect screenRect = ui.Rect.fromLTWH(0, 0, 100, 100);
final RecordingCanvas recordingCanvas = RecordingCanvas(screenRect);
final ui.ParagraphBuilder builder =
ui.ParagraphBuilder(ui.ParagraphStyle());
Expand Down
Loading

0 comments on commit 29790e3

Please sign in to comment.