Skip to content

Commit

Permalink
[web] Analysis cleanup (flutter#27730)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatb authored Jul 27, 2021
1 parent f63cbef commit 66ae7a3
Show file tree
Hide file tree
Showing 49 changed files with 109 additions and 99 deletions.
7 changes: 0 additions & 7 deletions lib/web_ui/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ analyzer:

linter:
rules:
empty_statements: false
hash_and_equals: false
implementation_imports: false
iterable_contains_unrelated_type: false
library_names: false
library_prefixes: false
list_remove_unrelated_type: false
Expand Down Expand Up @@ -47,9 +43,6 @@ linter:
unnecessary_getters_setters: false
unnecessary_null_aware_assignments: false
unnecessary_null_in_if_null_operators: false
unnecessary_overrides: false
unnecessary_parenthesis: false
unnecessary_this: false
unrelated_type_equality_checks: false
use_rethrow_when_possible: false
valid_regexps: false
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/dev/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class BrowserLock {
BrowserLock._() {
final io.File lockFile = io.File(
path.join(environment.webUiRootDir.path, 'dev', 'browser_lock.yaml'));
this._configuration = loadYaml(lockFile.readAsStringSync()) as YamlMap;
_configuration = loadYaml(lockFile.readAsStringSync()) as YamlMap;
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/web_ui/dev/safari_installation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SafariArgParser extends BrowserArgParser {
_version = argResults['safari-version'] as String;
assert(_version == 'system');
final String browser = argResults['browser'] as String;
_isMobileBrowser = (browser == 'ios-safari');
_isMobileBrowser = browser == 'ios-safari';
}

@override
Expand Down Expand Up @@ -85,9 +85,9 @@ class IosSafariArgParser extends BrowserArgParser {
required int pinnedIosMinorVersion,
required String pinnedIosDevice,
}) :
this._pinnedIosMajorVersion = pinnedIosMajorVersion,
this._pinnedIosMinorVersion = pinnedIosMinorVersion,
this._pinnedIosDevice = pinnedIosDevice;
_pinnedIosMajorVersion = pinnedIosMajorVersion,
_pinnedIosMinorVersion = pinnedIosMinorVersion,
_pinnedIosDevice = pinnedIosDevice;

/// Returns [IosSimulator] if the [Platform] is `macOS` and simulator
/// is started.
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/dev/test_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {
String get browser => stringArg('browser')!;

/// The browser environment for the [browser].
BrowserEnvironment get browserEnvironment => (_browserEnvironment ??= _createBrowserEnvironment(browser));
BrowserEnvironment get browserEnvironment => _browserEnvironment ??= _createBrowserEnvironment(browser);
BrowserEnvironment? _browserEnvironment;

/// Whether [browser] is set to "chrome".
Expand Down
3 changes: 3 additions & 0 deletions lib/web_ui/dev/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class FilePath {
return other is FilePath && other._absolutePath == _absolutePath;
}

@override
int get hashCode => _absolutePath.hashCode;

@override
String toString() => _absolutePath;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/canvas_pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class CanvasPool extends _SaveStackTracking {
_canvas = null;
return;
}
_contextHandle = ContextStateHandle(this, _context!, this._density);
_contextHandle = ContextStateHandle(this, _context!, _density);
_initializeViewport(requiresClearRect);
_replayClipStack();
}
Expand Down
12 changes: 6 additions & 6 deletions lib/web_ui/lib/src/engine/canvaskit/canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,8 @@ class CkDrawImageCommand extends CkPaintCommand {
final ui.Offset offset;
final CkPaint paint;

CkDrawImageCommand(CkImage image, this.offset, this.paint)
: this.image = image.clone();
CkDrawImageCommand(CkImage ckImage, this.offset, this.paint)
: image = ckImage.clone();

@override
void apply(SkCanvas canvas) {
Expand Down Expand Up @@ -1017,8 +1017,8 @@ class CkDrawImageRectCommand extends CkPaintCommand {
final ui.Rect dst;
final CkPaint paint;

CkDrawImageRectCommand(CkImage image, this.src, this.dst, this.paint)
: this.image = image.clone();
CkDrawImageRectCommand(CkImage ckImage, this.src, this.dst, this.paint)
: image = ckImage.clone();

@override
void apply(SkCanvas canvas) {
Expand Down Expand Up @@ -1051,8 +1051,8 @@ class CkDrawImageRectCommand extends CkPaintCommand {
}

class CkDrawImageNineCommand extends CkPaintCommand {
CkDrawImageNineCommand(CkImage image, this.center, this.dst, this.paint)
: this.image = image.clone();
CkDrawImageNineCommand(CkImage ckImage, this.center, this.dst, this.paint)
: image = ckImage.clone();

final CkImage image;
final ui.Rect center;
Expand Down
20 changes: 13 additions & 7 deletions lib/web_ui/lib/src/engine/canvaskit/color_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,35 @@ import 'skia_object_cache.dart';
/// the lifecycle of its [SkColorFilter].
class ManagedSkColorFilter extends ManagedSkiaObject<SkColorFilter> {
ManagedSkColorFilter(CkColorFilter ckColorFilter)
: this.ckColorFilter = ckColorFilter;
: colorFilter = ckColorFilter;

final CkColorFilter ckColorFilter;
final CkColorFilter colorFilter;

@override
SkColorFilter createDefault() => ckColorFilter._initRawColorFilter();
SkColorFilter createDefault() => colorFilter._initRawColorFilter();

@override
SkColorFilter resurrect() => ckColorFilter._initRawColorFilter();
SkColorFilter resurrect() => colorFilter._initRawColorFilter();

@override
void delete() {
rawSkiaObject?.delete();
}

@override
int get hashCode => ckColorFilter.hashCode;
int get hashCode => colorFilter.hashCode;

@override
bool operator ==(Object other) {
if (runtimeType != other.runtimeType) {
return false;
}
return other is ManagedSkColorFilter &&
other.ckColorFilter == ckColorFilter;
other.colorFilter == colorFilter;
}

@override
String toString() => ckColorFilter.toString();
String toString() => colorFilter.toString();
}

/// A [ui.ColorFilter] backed by Skia's [SkColorFilter].
Expand Down Expand Up @@ -151,6 +151,9 @@ class CkLinearToSrgbGammaColorFilter extends CkColorFilter {
@override
bool operator ==(Object other) => runtimeType == other.runtimeType;

@override
int get hashCode => runtimeType.hashCode;

@override
String toString() => 'ColorFilter.linearToSrgbGamma()';
}
Expand All @@ -164,6 +167,9 @@ class CkSrgbToLinearGammaColorFilter extends CkColorFilter {
@override
bool operator ==(Object other) => runtimeType == other.runtimeType;

@override
int get hashCode => runtimeType.hashCode;

@override
String toString() => 'ColorFilter.srgbToLinearGamma()';
}
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ class ViewClipChain {
int _clipCount = -1;

ViewClipChain({required html.Element view})
: this._root = view,
this._slot = view;
: _root = view,
_slot = view;

html.Element get root => _root;
html.Element get slot => _slot;
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/canvaskit/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Future<ui.Codec> skiaInstantiateWebImageCodec(

try {
final Uint8List list =
Uint8List.view((request.response as ByteBuffer));
Uint8List.view(request.response as ByteBuffer);
final CkAnimatedImage codec = CkAnimatedImage.decodeFromBytes(list, url);
completer.complete(codec);
} catch (error, stackTrace) {
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/canvaskit/image_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class _CkBlurImageFilter extends CkImageFilter {

class _CkMatrixImageFilter extends CkImageFilter {
_CkMatrixImageFilter({ required Float64List matrix, required this.filterQuality })
: this.matrix = Float64List.fromList(matrix),
: this.matrix = Float64List.fromList(matrix), // ignore: unnecessary_this
super._();

final Float64List matrix;
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/canvaskit/interval_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class IntervalTreeNode<T> {
// Don't bother checking intervals.
return false;
}
if (this.containsShallow(x)) {
if (containsShallow(x)) {
return true;
}
if (left?.containsDeep(x) == true) {
Expand All @@ -146,7 +146,7 @@ class IntervalTreeNode<T> {
return;
}
left?.searchForPoint(x, result);
if (this.containsShallow(x)) {
if (containsShallow(x)) {
result.add(value);
}
if (x < low) {
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/canvaskit/painting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class CkPaint extends ManagedSkiaObject<SkPaint> implements ui.Paint {
ui.FilterQuality _filterQuality = ui.FilterQuality.none;

@override
ui.ColorFilter? get colorFilter => _managedColorFilter?.ckColorFilter;
ui.ColorFilter? get colorFilter => _managedColorFilter?.colorFilter;
@override
set colorFilter(ui.ColorFilter? value) {
if (colorFilter == value) {
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/canvaskit/shader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class CkGradientLinear extends CkShader implements ui.Gradient {
assert(offsetIsValid(to)),
assert(colors != null), // ignore: unnecessary_null_comparison
assert(tileMode != null), // ignore: unnecessary_null_comparison
this.matrix4 = matrix {
matrix4 = matrix {
if (assertionsEnabled) {
assert(matrix4 == null || matrix4IsValid(matrix4!));
validateColorStops(colors, colorStops);
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 @@ -235,7 +235,7 @@ class Surface {
}

void _contextLostListener(html.Event event) {
assert(event.target == this.htmlCanvas,
assert(event.target == htmlCanvas,
'Received a context lost event for a disposed canvas');
final SurfaceFactory factory = SurfaceFactory.instance;
_contextLost = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/html/bitmap_canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ class BitmapCanvas extends EngineCanvas {
math.min(rect.left, rect.right), math.min(rect.top, rect.bottom)),
paint);
element.style.borderRadius =
'${(rect.width / 2.0)}px / ${(rect.height / 2.0)}px';
'${rect.width / 2.0}px / ${rect.height / 2.0}px';
} else {
setUpPaint(paint, rect);
_canvasPool.drawOval(rect, paint.style);
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/html/offscreen_canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class OffScreenCanvas {
/// Returns CanvasRenderContext2D or OffscreenCanvasRenderingContext2D to
/// paint into.
Object? getContext2d() {
return (offScreenCanvas != null
return offScreenCanvas != null
? offScreenCanvas!.getContext('2d')
: canvasElement!.getContext('2d'));
: canvasElement!.getContext('2d');
}

/// Feature detection for transferToImageBitmap on OffscreenCanvas.
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 @@ -180,7 +180,7 @@ double? chopMonoAtY(Float32List _buffer, int bufferStartPos, double y) {
} else {
tPos = tMid;
}
} while (((tPos - tNeg).abs() > tolerance));
} while ((tPos - tNeg).abs() > tolerance);
return (tNeg + tPos) / 2;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/web_ui/lib/src/engine/html/path/path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ class SurfacePath implements ui.Path {
// to start outside their marks. A round rect may lose convexity as a
// result. If the input values are on integers, place the conic on
// integers as well.
final bool expectIntegers = SPath.nearlyEqual((math.pi / 2 - thetaWidth.abs()), 0) &&
final bool expectIntegers = SPath.nearlyEqual(math.pi / 2 - thetaWidth.abs(), 0) &&
SPath.isInteger(rx) &&
SPath.isInteger(ry) &&
SPath.isInteger(x) &&
Expand Down Expand Up @@ -1175,7 +1175,7 @@ class SurfacePath implements ui.Path {
} else {
final double x = offsetX + points[p];
final double y = offsetY + points[p + 1];
points[p] = (matrix4[0] * (x)) + (matrix4[4] * y) + matrix4[12];
points[p] = (matrix4[0] * x) + (matrix4[4] * y) + matrix4[12];
points[p + 1] = (matrix4[1] * x) + (matrix4[5] * y) + matrix4[13];
}
}
Expand Down Expand Up @@ -1432,7 +1432,7 @@ class SurfacePath implements ui.Path {
}
}

if (this._firstDirection == SPathDirection.kUnknown) {
if (_firstDirection == SPathDirection.kUnknown) {
if (state.firstDirection == SPathDirection.kUnknown &&
!pathRef.getBounds().isEmpty) {
return _setComputedConvexity(state.reversals < 3
Expand Down Expand Up @@ -1540,7 +1540,7 @@ class SurfacePath implements ui.Path {
/// as if they had been closed, even if they were not explicitly closed.
@override
SurfacePathMetrics computeMetrics({bool forceClosed = false}) {
return SurfacePathMetrics(this.pathRef, forceClosed);
return SurfacePathMetrics(pathRef, forceClosed);
}

/// Detects if path is rounded rectangle.
Expand Down
6 changes: 5 additions & 1 deletion lib/web_ui/lib/src/engine/html/path/path_ref.dart
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ class PathRef {
return equals(other as PathRef);
}

@override
int get hashCode => ui.hashValues(fSegmentMask,
fPoints, _conicWeights, _fVerbs);

bool equals(PathRef ref) {
// We explicitly check fSegmentMask as a quick-reject. We could skip it,
// since it is only a cache of info in the fVerbs, but its a fast way to
Expand Down Expand Up @@ -583,7 +587,7 @@ class PathRef {
maxX = math.max(maxX, x);
maxY = math.max(maxY, y);
}
final bool allFinite = (accum * 0 == 0);
final bool allFinite = accum * 0 == 0;
if (allFinite) {
fBounds = ui.Rect.fromLTRB(minX, minY, maxX, maxY);
fIsFinite = true;
Expand Down
6 changes: 3 additions & 3 deletions lib/web_ui/lib/src/engine/html/picture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,8 @@ class PersistedPicture extends PersistedLeafSurface {

_computeOptimalCullRect(oldSurface);
if (identical(picture, oldSurface.picture)) {
final bool densityChanged = (_canvas is BitmapCanvas &&
_density != (_canvas! as BitmapCanvas).density);
final bool densityChanged = _canvas is BitmapCanvas &&
_density != (_canvas! as BitmapCanvas).density;

// The picture is the same. Attempt to avoid repaint.
if (_requiresRepaint || densityChanged) {
Expand Down Expand Up @@ -720,7 +720,7 @@ double _computePixelDensity(Matrix4? transform, double width, double height) {
//
// On a fullscreen high dpi device dpi*density*resolution will demand
// too much memory, so clamp at 4.
scale = math.min(4.0, ((scale / 2.0).ceil() * 2.0));
scale = math.min(4.0, (scale / 2.0).ceil() * 2.0);
// Guard against webkit absolute limit.
const double kPixelLimit = 1024 * 1024 * 4;
if ((width * height * scale * scale) > kPixelLimit && scale > 2) {
Expand Down
3 changes: 3 additions & 0 deletions lib/web_ui/lib/src/engine/html/render_vertices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ class SurfaceVertices implements ui.Vertices {
List<int>? indices,
}) : assert(mode != null), // ignore: unnecessary_null_comparison
assert(positions != null), // ignore: unnecessary_null_comparison
// ignore: unnecessary_this
this.colors = colors != null ? _int32ListFromColors(colors) : null,
// ignore: unnecessary_this
this.indices = indices != null ? Uint16List.fromList(indices) : null,
// ignore: unnecessary_this
this.positions = offsetListToFloat32List(positions) {
initWebGl();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/html/shaders/image_shader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import 'webgl_context.dart';
class EngineImageShader implements ui.ImageShader {
EngineImageShader(ui.Image image, this.tileModeX, this.tileModeY,
Float64List matrix4, this.filterQuality)
: this.image = image as HtmlImage,
this.matrix4 = Float32List.fromList(matrix4);
: this.image = image as HtmlImage, // ignore: unnecessary_this
this.matrix4 = Float32List.fromList(matrix4); // ignore: unnecessary_this

final ui.TileMode tileModeX;
final ui.TileMode tileModeY;
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/html/shaders/shader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class GradientLinear extends EngineGradient {
assert(offsetIsValid(to)),
assert(colors != null), // ignore: unnecessary_null_comparison
assert(tileMode != null), // ignore: unnecessary_null_comparison
this.matrix4 = matrix == null ? null : FastMatrix32(matrix),
matrix4 = matrix == null ? null : FastMatrix32(matrix),
super._() {
if (assertionsEnabled) {
validateColorStops(colors, colorStops);
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/platform_views/message_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class PlatformViewMessageHandler {
PlatformViewMessageHandler({
required PlatformViewManager contentManager,
PlatformViewContentHandler? contentHandler,
}) : this._contentManager = contentManager,
this._contentHandler = contentHandler;
}) : _contentManager = contentManager,
_contentHandler = contentHandler;

/// Handle a `create` Platform View message.
///
Expand Down
Loading

0 comments on commit 66ae7a3

Please sign in to comment.