Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable stricter linter rules. #1238

Merged
merged 6 commits into from
May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
include: package:flutter_lints/flutter.yaml

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
errors:
close_sinks: ignore
missing_required_param: error
missing_return: error

linter:
rules:
library_private_types_in_public_api: false
prefer_final_locals: true
prefer_final_in_for_each: true
avoid_dynamic_calls: true
always_use_package_imports: true
type_annotate_public_apis: true
prefer_int_literals: true
use_named_constants: true
13 changes: 10 additions & 3 deletions lib/flutter_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import 'dart:async';
import 'dart:math';

import 'package:flutter/widgets.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map/src/core/center_zoom.dart';
import 'package:flutter_map/src/geo/crs/crs.dart';
import 'package:flutter_map/src/geo/latlng_bounds.dart';
import 'package:flutter_map/src/gestures/interactive_flag.dart';
import 'package:flutter_map/src/gestures/map_events.dart';
import 'package:flutter_map/src/gestures/multi_finger_gesture.dart';
import 'package:flutter_map/src/layer/layer.dart';
import 'package:flutter_map/src/map/flutter_map_state.dart';
import 'package:flutter_map/src/map/map.dart';
import 'package:flutter_map/src/plugins/plugin.dart';
import 'package:latlong2/latlong.dart';
import 'package:positioned_tap_detector_2/positioned_tap_detector_2.dart';

Expand Down Expand Up @@ -384,7 +391,7 @@ class FitBoundsOptions {
final bool inside;

const FitBoundsOptions({
this.padding = const EdgeInsets.all(0.0),
this.padding = EdgeInsets.zero,
this.maxZoom = 17.0,
this.zoom,
this.inside = false,
Expand Down Expand Up @@ -421,7 +428,7 @@ class _SafeArea {
isLatitudeBlocked = southWest.latitude > northEast.latitude,
isLongitudeBlocked = southWest.longitude > northEast.longitude;

bool contains(point) =>
bool contains(LatLng? point) =>
isLatitudeBlocked || isLongitudeBlocked ? false : bounds.contains(point);

LatLng containPoint(LatLng point, LatLng fallback) => LatLng(
Expand Down
8 changes: 4 additions & 4 deletions lib/src/core/bounds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Bounds<T extends num> {
final CustomPoint<T> max;

factory Bounds(CustomPoint<T> a, CustomPoint<T> b) {
var bounds1 = Bounds._(a, b);
var bounds2 = bounds1.extend(a);
final bounds1 = Bounds._(a, b);
final bounds2 = bounds1.extend(a);
return bounds2.extend(b);
}

Expand Down Expand Up @@ -55,8 +55,8 @@ class Bounds<T extends num> {
}

bool contains(CustomPoint<T> point) {
var min = point;
var max = point;
final min = point;
final max = point;
return containsBounds(Bounds(min, max));
}

Expand Down
10 changes: 5 additions & 5 deletions lib/src/core/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ var _templateRe = RegExp(r'\{ *([\w_-]+) *\}');
/// Throws an [Exception] if any placeholder remains unresolved.
String template(String str, Map<String, String> data) {
return str.replaceAllMapped(_templateRe, (Match match) {
var firstMatch = match.group(1);
final firstMatch = match.group(1);
if (firstMatch == null) {
throw Exception('incorrect URL template: $str');
}
var value = data[firstMatch];
final value = data[firstMatch];
if (value == null) {
throw Exception('No value provided for variable ${match.group(1)}');
} else {
Expand All @@ -25,9 +25,9 @@ String template(String str, Map<String, String> data) {
}

double wrapNum(double x, Tuple2<double, double> range, [bool? includeMax]) {
var max = range.item2;
var min = range.item1;
var d = max - min;
final max = range.item2;
final min = range.item1;
final d = max - min;
return x == max && includeMax != null ? x : ((x - min) % d + d) % d + min;
}

Expand Down
92 changes: 46 additions & 46 deletions lib/src/geo/crs/crs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ abstract class Crs {
/// map point.
CustomPoint latLngToPoint(LatLng latlng, double zoom) {
try {
var projectedPoint = projection.project(latlng);
var scale = this.scale(zoom);
final projectedPoint = projection.project(latlng);
final scale = this.scale(zoom);
return transformation.transform(projectedPoint, scale.toDouble());
} catch (e) {
return const CustomPoint(0.0, 0.0);
Expand All @@ -35,8 +35,8 @@ abstract class Crs {

/// Converts a map point to the sphere coordinate (at a certain zoom).
LatLng? pointToLatLng(CustomPoint point, double zoom) {
var scale = this.scale(zoom);
var untransformedPoint =
final scale = this.scale(zoom);
final untransformedPoint =
transformation.untransform(point, scale.toDouble());
try {
return projection.unproject(untransformedPoint);
Expand All @@ -59,10 +59,10 @@ abstract class Crs {
Bounds? getProjectedBounds(double zoom) {
if (infinite) return null;

var b = projection.bounds!;
var s = scale(zoom);
var min = transformation.transform(b.min, s.toDouble());
var max = transformation.transform(b.max, s.toDouble());
final b = projection.bounds!;
final s = scale(zoom);
final min = transformation.transform(b.min, s.toDouble());
final max = transformation.transform(b.max, s.toDouble());
return Bounds(min, max);
}

Expand Down Expand Up @@ -104,7 +104,7 @@ abstract class Earth extends Crs {
bool get infinite => false;

@override
final Tuple2<double, double> wrapLng = const Tuple2(-180.0, 180.0);
final Tuple2<double, double> wrapLng = const Tuple2(-180, 180);
pablojimpas marked this conversation as resolved.
Show resolved Hide resolved

@override
final Tuple2<double, double>? wrapLat = null;
Expand Down Expand Up @@ -198,7 +198,7 @@ class Proj4Crs extends Crs {
final projection =
_Proj4Projection(proj4Projection: proj4Projection, bounds: bounds);
List<Transformation>? transformations;
var infinite = null == bounds;
final infinite = null == bounds;
List<double> finalScales;

if (null != scales && scales.isNotEmpty) {
Expand All @@ -214,7 +214,7 @@ class Proj4Crs extends Crs {
transformation ??= const Transformation(1, 0, -1, 0);
} else {
if (origins.length == 1) {
var origin = origins[0];
final origin = origins[0];
transformation = Transformation(1, -origin.x, -1, origin.y);
} else {
transformations =
Expand All @@ -238,9 +238,9 @@ class Proj4Crs extends Crs {
@override
CustomPoint latLngToPoint(LatLng latlng, double zoom) {
try {
var projectedPoint = projection.project(latlng);
var scale = this.scale(zoom);
var transformation = _getTransformationByZoom(zoom);
final projectedPoint = projection.project(latlng);
final scale = this.scale(zoom);
final transformation = _getTransformationByZoom(zoom);

return transformation.transform(projectedPoint, scale.toDouble());
} catch (e) {
Expand All @@ -251,10 +251,10 @@ class Proj4Crs extends Crs {
/// Converts a map point to the sphere coordinate (at a certain zoom).
@override
LatLng? pointToLatLng(CustomPoint point, double zoom) {
var scale = this.scale(zoom);
var transformation = _getTransformationByZoom(zoom);
final scale = this.scale(zoom);
final transformation = _getTransformationByZoom(zoom);

var untransformedPoint =
final untransformedPoint =
transformation.untransform(point, scale.toDouble());
try {
return projection.unproject(untransformedPoint);
Expand All @@ -268,28 +268,28 @@ class Proj4Crs extends Crs {
Bounds? getProjectedBounds(double zoom) {
if (infinite) return null;

var b = projection.bounds!;
var s = scale(zoom);
final b = projection.bounds!;
final s = scale(zoom);

var transformation = _getTransformationByZoom(zoom);
final transformation = _getTransformationByZoom(zoom);

var min = transformation.transform(b.min, s.toDouble());
var max = transformation.transform(b.max, s.toDouble());
final min = transformation.transform(b.min, s.toDouble());
final max = transformation.transform(b.max, s.toDouble());
return Bounds(min, max);
}

/// Zoom to Scale function.
@override
num scale(double zoom) {
var iZoom = zoom.floor();
final iZoom = zoom.floor();
if (zoom == iZoom) {
return _scales[iZoom];
} else {
// Non-integer zoom, interpolate
var baseScale = _scales[iZoom];
var nextScale = _scales[iZoom + 1];
var scaleDiff = nextScale - baseScale;
var zDiff = (zoom - iZoom);
final baseScale = _scales[iZoom];
final nextScale = _scales[iZoom + 1];
final scaleDiff = nextScale - baseScale;
final zDiff = (zoom - iZoom);
return baseScale + scaleDiff * zDiff;
}
}
Expand All @@ -298,28 +298,28 @@ class Proj4Crs extends Crs {
@override
num zoom(double scale) {
// Find closest number in _scales, down
var downScale = _closestElement(_scales, scale);
final downScale = _closestElement(_scales, scale);
if (downScale == null) {
return double.negativeInfinity;
}
var downZoom = _scales.indexOf(downScale);
final downZoom = _scales.indexOf(downScale);
// Check if scale is downScale => return array index
if (scale == downScale) {
return downZoom;
}
// Interpolate
var nextZoom = downZoom + 1;
var nextScale = _scales[nextZoom];
final nextZoom = downZoom + 1;
final nextScale = _scales[nextZoom];

var scaleDiff = nextScale - downScale;
final scaleDiff = nextScale - downScale;
return (scale - downScale) / scaleDiff + downZoom;
}

/// Get the closest lowest element in an array
double? _closestElement(List<double> array, double element) {
double? low;
for (var i = array.length - 1; i >= 0; i--) {
var curr = array[i];
final curr = array[i];

if (curr <= element && (null == low || low < curr)) {
low = curr;
Expand All @@ -334,8 +334,8 @@ class Proj4Crs extends Crs {
return transformation;
}

var iZoom = zoom.round();
var lastIdx = _transformations!.length - 1;
final iZoom = zoom.round();
final lastIdx = _transformations!.length - 1;

return _transformations![iZoom > lastIdx ? lastIdx : iZoom];
}
Expand Down Expand Up @@ -406,18 +406,18 @@ class SphericalMercator extends Projection {

@override
CustomPoint project(LatLng latlng) {
var d = math.pi / 180;
var max = maxLatitude;
var lat = math.max(math.min(max, latlng.latitude), -max);
var sin = math.sin(lat * d);
const d = math.pi / 180;
const max = maxLatitude;
final lat = math.max(math.min(max, latlng.latitude), -max);
final sin = math.sin(lat * d);

return CustomPoint(
r * latlng.longitude * d, r * math.log((1 + sin) / (1 - sin)) / 2);
}

@override
LatLng unproject(CustomPoint point) {
var d = 180 / math.pi;
const d = 180 / math.pi;
return LatLng(
inclusiveLat(
(2 * math.atan(math.exp(point.y / r)) - (math.pi / 2)) * d),
Expand All @@ -440,15 +440,15 @@ class _Proj4Projection extends Projection {

@override
CustomPoint project(LatLng latlng) {
var point = epsg4326.transform(
final point = epsg4326.transform(
proj4Projection, proj4.Point(x: latlng.longitude, y: latlng.latitude));

return CustomPoint(point.x, point.y);
}

@override
LatLng unproject(CustomPoint point) {
var point2 = proj4Projection.transform(
final point2 = proj4Projection.transform(
epsg4326, proj4.Point(x: point.x as double, y: point.y as double));

return LatLng(inclusiveLat(point2.y), inclusiveLng(point2.x));
Expand All @@ -465,15 +465,15 @@ class Transformation {

CustomPoint transform(CustomPoint<num> point, double? scale) {
scale ??= 1.0;
var x = scale * (a * point.x + b);
var y = scale * (c * point.y + d);
final x = scale * (a * point.x + b);
final y = scale * (c * point.y + d);
return CustomPoint(x, y);
}

CustomPoint untransform(CustomPoint point, double? scale) {
scale ??= 1.0;
var x = (point.x / scale - b) / a;
var y = (point.y / scale - d) / c;
final x = (point.x / scale - b) / a;
final y = (point.y / scale - d) / c;
return CustomPoint(x, y);
}
}
Loading