From 5386722df399c18bcd87dae367efd22c95a80a44 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sat, 12 Oct 2019 09:34:15 -0400 Subject: [PATCH] Pedantic lints --- angel_container/analysis_options.yaml | 1 + angel_container/example/main.dart | 2 +- angel_container/lib/src/container.dart | 19 ++++---- angel_container/lib/src/empty/empty.dart | 14 +++--- .../lib/src/mirrors/reflector.dart | 46 +++++++++---------- angel_container/lib/src/reflector.dart | 2 +- angel_container/lib/src/static/static.dart | 16 +++---- angel_container/pubspec.yaml | 5 +- angel_container/test/common.dart | 6 +-- .../test/empty_reflector_test.dart | 4 +- angel_container/test/has_test.dart | 6 +-- angel_container/test/lazy_test.dart | 4 +- angel_container/test/named_test.dart | 6 +-- 13 files changed, 66 insertions(+), 65 deletions(-) diff --git a/angel_container/analysis_options.yaml b/angel_container/analysis_options.yaml index eae1e42a..c230cee7 100644 --- a/angel_container/analysis_options.yaml +++ b/angel_container/analysis_options.yaml @@ -1,3 +1,4 @@ +include: package:pedantic/analysis_options.yaml analyzer: strong-mode: implicit-casts: false \ No newline at end of file diff --git a/angel_container/example/main.dart b/angel_container/example/main.dart index fb831581..3ee5106b 100644 --- a/angel_container/example/main.dart +++ b/angel_container/example/main.dart @@ -5,7 +5,7 @@ import 'package:angel_container/mirrors.dart'; Future main() async { // Create a container instance. - var container = new Container(const MirrorsReflector()); + var container = Container(const MirrorsReflector()); // Register a singleton. container.registerSingleton(Engine(40)); diff --git a/angel_container/lib/src/container.dart b/angel_container/lib/src/container.dart index b6bbe2c0..a80b7f48 100644 --- a/angel_container/lib/src/container.dart +++ b/angel_container/lib/src/container.dart @@ -19,7 +19,7 @@ class Container { /// /// Use this to create children of a global "scope." Container createChild() { - return new Container._child(this); + return Container._child(this); } /// Determines if the container has an injection of the given type. @@ -61,7 +61,7 @@ class Container { /// `Future` or `T`. Future makeAsync([Type type]) { type ??= T; - Type futureType = null; //.Future.value(null).runtimeType; + Type futureType; //.Future.value(null).runtimeType; if (T == dynamic) { try { @@ -78,7 +78,7 @@ class Container { } else if (futureType != null) { return make(futureType); } else { - throw new ReflectionException( + throw ReflectionException( 'No injection for Future<$type> or $type was found.'); } } @@ -115,7 +115,7 @@ class Container { var constructor = reflectedType.constructors.firstWhere( (c) => isDefault(c.name), - orElse: () => throw new ReflectionException( + orElse: () => throw ReflectionException( '${reflectedType.name} has no default constructor, and therefore cannot be instantiated.')); for (var param in constructor.parameters) { @@ -133,7 +133,7 @@ class Container { positional, named, []).reflectee as T; } else { - throw new ReflectionException( + throw ReflectionException( '$type is not a class, and therefore cannot be instantiated.'); } } @@ -156,7 +156,7 @@ class Container { as ??= T; if (_factories.containsKey(as)) { - throw new StateError('This container already has a factory for $as.'); + throw StateError('This container already has a factory for $as.'); } _factories[as] = f; @@ -166,7 +166,7 @@ class Container { as ??= T == dynamic ? as : T; if (_singletons.containsKey(as ?? object.runtimeType)) { - throw new StateError( + throw StateError( 'This container already has a singleton for ${as ?? object.runtimeType}.'); } @@ -185,7 +185,7 @@ class Container { } else if (_parent != null) { return _parent.findByName(name); } else { - throw new StateError( + throw StateError( 'This container does not have a singleton named "$name".'); } } @@ -196,8 +196,7 @@ class Container { /// to enable injecting multiple instances of a type within the same container hierarchy. void registerNamedSingleton(String name, T object) { if (_namedSingletons.containsKey(name)) { - throw new StateError( - 'This container already has a singleton named "$name".'); + throw StateError('This container already has a singleton named "$name".'); } _namedSingletons[name] = object; diff --git a/angel_container/lib/src/empty/empty.dart b/angel_container/lib/src/empty/empty.dart index fd0f18e0..71826adc 100644 --- a/angel_container/lib/src/empty/empty.dart +++ b/angel_container/lib/src/empty/empty.dart @@ -8,7 +8,7 @@ final Map _symbolNames = {}; /// Use this in contexts where you know you won't need any reflective capabilities. class EmptyReflector extends Reflector { /// A [RegExp] that can be used to extract the name of a symbol without reflection. - static final RegExp symbolRegex = new RegExp(r'Symbol\("([^"]+)"\)'); + static final RegExp symbolRegex = RegExp(r'Symbol\("([^"]+)"\)'); const EmptyReflector(); @@ -47,13 +47,13 @@ class _EmptyReflectedClass extends ReflectedClass { const [], const [], const [], - dynamic); + Object); @override ReflectedInstance newInstance( String constructorName, List positionalArguments, [Map namedArguments, List typeArguments]) { - throw new UnsupportedError( + throw UnsupportedError( 'Classes reflected via an EmptyReflector cannot be instantiated.'); } @@ -70,13 +70,13 @@ class _EmptyReflectedClass extends ReflectedClass { class _EmptyReflectedType extends ReflectedType { const _EmptyReflectedType() - : super('(empty)', const [], dynamic); + : super('(empty)', const [], Object); @override ReflectedInstance newInstance( String constructorName, List positionalArguments, [Map namedArguments, List typeArguments]) { - throw new UnsupportedError( + throw UnsupportedError( 'Types reflected via an EmptyReflector cannot be instantiated.'); } @@ -102,7 +102,7 @@ class _EmptyReflectedInstance extends ReflectedInstance { @override ReflectedInstance getField(String name) { - throw new UnsupportedError( + throw UnsupportedError( 'Instances reflected via an EmptyReflector cannot call getField().'); } } @@ -120,7 +120,7 @@ class _EmptyReflectedFunction extends ReflectedFunction { @override ReflectedInstance invoke(Invocation invocation) { - throw new UnsupportedError( + throw UnsupportedError( 'Instances reflected via an EmptyReflector cannot call invoke().'); } } diff --git a/angel_container/lib/src/mirrors/reflector.dart b/angel_container/lib/src/mirrors/reflector.dart index ca9c006e..53373549 100644 --- a/angel_container/lib/src/mirrors/reflector.dart +++ b/angel_container/lib/src/mirrors/reflector.dart @@ -17,16 +17,16 @@ class MirrorsReflector extends Reflector { var mirror = dart.reflectType(clazz); if (mirror is dart.ClassMirror) { - return new _ReflectedClassMirror(mirror); + return _ReflectedClassMirror(mirror); } else { - throw new ArgumentError('$clazz is not a class.'); + throw ArgumentError('$clazz is not a class.'); } } @override ReflectedFunction reflectFunction(Function function) { var closure = dart.reflect(function) as dart.ClosureMirror; - return new _ReflectedMethodMirror(closure.function, closure); + return _ReflectedMethodMirror(closure.function, closure); } @override @@ -37,9 +37,9 @@ class MirrorsReflector extends Reflector { return reflectType(dynamic); } else { if (mirror is dart.ClassMirror) { - return new _ReflectedClassMirror(mirror); + return _ReflectedClassMirror(mirror); } else { - return new _ReflectedTypeMirror(mirror); + return _ReflectedTypeMirror(mirror); } } } @@ -62,7 +62,7 @@ class MirrorsReflector extends Reflector { @override ReflectedInstance reflectInstance(Object object) { - return new _ReflectedInstanceMirror(dart.reflect(object)); + return _ReflectedInstanceMirror(dart.reflect(object)); } } @@ -80,7 +80,7 @@ class _ReflectedTypeMirror extends ReflectedType { : super( dart.MirrorSystem.getName(mirror.simpleName), mirror.typeVariables - .map((m) => new _ReflectedTypeParameter(m)) + .map((m) => _ReflectedTypeParameter(m)) .toList(), mirror.reflectedType, ); @@ -100,7 +100,7 @@ class _ReflectedTypeMirror extends ReflectedType { ReflectedInstance newInstance( String constructorName, List positionalArguments, [Map namedArguments, List typeArguments]) { - throw new ReflectionException( + throw ReflectionException( '$name is not a class, and therefore cannot be instantiated.'); } } @@ -112,7 +112,7 @@ class _ReflectedClassMirror extends ReflectedClass { : super( dart.MirrorSystem.getName(mirror.simpleName), mirror.typeVariables - .map((m) => new _ReflectedTypeParameter(m)) + .map((m) => _ReflectedTypeParameter(m)) .toList(), [], [], @@ -127,7 +127,7 @@ class _ReflectedClassMirror extends ReflectedClass { var value = mirror.declarations[key]; if (value is dart.MethodMirror && value.isConstructor) { - out.add(new _ReflectedMethodMirror(value)); + out.add(_ReflectedMethodMirror(value)); } } @@ -141,7 +141,7 @@ class _ReflectedClassMirror extends ReflectedClass { var value = mirror.declarations[key]; if (value is dart.MethodMirror && !value.isConstructor) { - out.add(new _ReflectedDeclarationMirror( + out.add(_ReflectedDeclarationMirror( dart.MirrorSystem.getName(key), value)); } } @@ -151,7 +151,7 @@ class _ReflectedClassMirror extends ReflectedClass { @override List get annotations => - mirror.metadata.map((m) => new _ReflectedInstanceMirror(m)).toList(); + mirror.metadata.map((m) => _ReflectedInstanceMirror(m)).toList(); @override List get constructors => _constructorsOf(mirror); @@ -171,8 +171,8 @@ class _ReflectedClassMirror extends ReflectedClass { ReflectedInstance newInstance( String constructorName, List positionalArguments, [Map namedArguments, List typeArguments]) { - return new _ReflectedInstanceMirror( - mirror.newInstance(new Symbol(constructorName), positionalArguments)); + return _ReflectedInstanceMirror( + mirror.newInstance(Symbol(constructorName), positionalArguments)); } @override @@ -192,19 +192,19 @@ class _ReflectedDeclarationMirror extends ReflectedDeclaration { bool get isStatic => mirror.isStatic; @override - ReflectedFunction get function => new _ReflectedMethodMirror(mirror); + ReflectedFunction get function => _ReflectedMethodMirror(mirror); } class _ReflectedInstanceMirror extends ReflectedInstance { final dart.InstanceMirror mirror; _ReflectedInstanceMirror(this.mirror) - : super(new _ReflectedClassMirror(mirror.type), - new _ReflectedClassMirror(mirror.type), mirror.reflectee); + : super(_ReflectedClassMirror(mirror.type), + _ReflectedClassMirror(mirror.type), mirror.reflectee); @override ReflectedInstance getField(String name) { - return new _ReflectedInstanceMirror(mirror.getField(new Symbol(name))); + return _ReflectedInstanceMirror(mirror.getField(Symbol(name))); } } @@ -217,7 +217,7 @@ class _ReflectedMethodMirror extends ReflectedFunction { dart.MirrorSystem.getName(mirror.simpleName), [], mirror.metadata - .map((mirror) => new _ReflectedInstanceMirror(mirror)) + .map((mirror) => _ReflectedInstanceMirror(mirror)) .toList(), !mirror.returnType.hasReflectedType ? const MirrorsReflector().reflectType(dynamic) @@ -228,10 +228,10 @@ class _ReflectedMethodMirror extends ReflectedFunction { mirror.isSetter); static ReflectedParameter _reflectParameter(dart.ParameterMirror mirror) { - return new ReflectedParameter( + return ReflectedParameter( dart.MirrorSystem.getName(mirror.simpleName), mirror.metadata - .map((mirror) => new _ReflectedInstanceMirror(mirror)) + .map((mirror) => _ReflectedInstanceMirror(mirror)) .toList(), const MirrorsReflector().reflectType(mirror.type.reflectedType), !mirror.isOptional, @@ -241,11 +241,11 @@ class _ReflectedMethodMirror extends ReflectedFunction { @override ReflectedInstance invoke(Invocation invocation) { if (closureMirror == null) { - throw new StateError( + throw StateError( 'This object was reflected without a ClosureMirror, and therefore cannot be directly invoked.'); } - return new _ReflectedInstanceMirror(closureMirror.invoke( + return _ReflectedInstanceMirror(closureMirror.invoke( invocation.memberName, invocation.positionalArguments, invocation.namedArguments)); diff --git a/angel_container/lib/src/reflector.dart b/angel_container/lib/src/reflector.dart index b11a1569..1220a5ab 100644 --- a/angel_container/lib/src/reflector.dart +++ b/angel_container/lib/src/reflector.dart @@ -15,7 +15,7 @@ abstract class Reflector { ReflectedInstance reflectInstance(Object object); ReflectedType reflectFutureOf(Type type) { - throw new UnsupportedError('`reflectFutureOf` requires `dart:mirrors`.'); + throw UnsupportedError('`reflectFutureOf` requires `dart:mirrors`.'); } } diff --git a/angel_container/lib/src/static/static.dart b/angel_container/lib/src/static/static.dart index 4d031515..09e042a3 100644 --- a/angel_container/lib/src/static/static.dart +++ b/angel_container/lib/src/static/static.dart @@ -10,15 +10,15 @@ class StaticReflector extends Reflector { final Map instances; const StaticReflector( - {this.names: const {}, - this.types: const {}, - this.functions: const {}, - this.instances: const {}}); + {this.names = const {}, + this.types = const {}, + this.functions = const {}, + this.instances = const {}}); @override String getName(Symbol symbol) { if (!names.containsKey(symbol)) { - throw new ArgumentError( + throw ArgumentError( 'The value of $symbol is unknown - it was not generated.'); } @@ -32,7 +32,7 @@ class StaticReflector extends Reflector { @override ReflectedFunction reflectFunction(Function function) { if (!functions.containsKey(function)) { - throw new ArgumentError( + throw ArgumentError( 'There is no reflection information available about $function.'); } @@ -42,7 +42,7 @@ class StaticReflector extends Reflector { @override ReflectedInstance reflectInstance(Object object) { if (!instances.containsKey(object)) { - throw new ArgumentError( + throw ArgumentError( 'There is no reflection information available about $object.'); } @@ -52,7 +52,7 @@ class StaticReflector extends Reflector { @override ReflectedType reflectType(Type type) { if (!types.containsKey(type)) { - throw new ArgumentError( + throw ArgumentError( 'There is no reflection information available about $type.'); } diff --git a/angel_container/pubspec.yaml b/angel_container/pubspec.yaml index 4a2e8544..c723d65b 100644 --- a/angel_container/pubspec.yaml +++ b/angel_container/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_container -version: 1.0.4 +version: 1.1.0 author: Tobe O description: "A better IoC container and dependency injector for Angel, ultimately allowing Angel to be used without dart:mirrors." homepage: https://github.com/angel-dart/container.git @@ -9,4 +9,5 @@ dependencies: collection: ^1.0.0 quiver: ^2.0.0 dev_dependencies: - test: \ No newline at end of file + pedantic: ^1.0.0 + test: ^1.0.0 \ No newline at end of file diff --git a/angel_container/test/common.dart b/angel_container/test/common.dart index 9ffc38c7..b638ac9c 100644 --- a/angel_container/test/common.dart +++ b/angel_container/test/common.dart @@ -6,11 +6,11 @@ import 'package:test/test.dart'; void returnVoidFromAFunction(int x) {} void testReflector(Reflector reflector) { - var blaziken = new Pokemon('Blaziken', PokemonType.fire); + var blaziken = Pokemon('Blaziken', PokemonType.fire); Container container; setUp(() { - container = new Container(reflector); + container = Container(reflector); container.registerSingleton(blaziken); container.registerFactory>((_) async => 46); }); @@ -108,7 +108,7 @@ class Pokemon { Pokemon(this.name, this.type); factory Pokemon.changeName(Pokemon other, String name) { - return new Pokemon(name, other.type); + return Pokemon(name, other.type); } @override diff --git a/angel_container/test/empty_reflector_test.dart b/angel_container/test/empty_reflector_test.dart index ba314590..86c6c38a 100644 --- a/angel_container/test/empty_reflector_test.dart +++ b/angel_container/test/empty_reflector_test.dart @@ -103,13 +103,13 @@ void main() { }); test('cannot invoke', () { - var invocation = new Invocation.method(#drive, []); + var invocation = Invocation.method(#drive, []); expect(() => mirror.invoke(invocation), throwsUnsupportedError); }); }); group('reflectInstance', () { - var mirror = reflector.reflectInstance(new Truck()); + var mirror = reflector.reflectInstance(Truck()); test('reflectee returns null', () { expect(mirror.reflectee, null); diff --git a/angel_container/test/has_test.dart b/angel_container/test/has_test.dart index 309c6ce7..bd5d21cb 100644 --- a/angel_container/test/has_test.dart +++ b/angel_container/test/has_test.dart @@ -5,11 +5,11 @@ void main() { Container container; setUp(() { - container = new Container(const EmptyReflector()) - ..registerSingleton(new Song(title: 'I Wish')) + container = Container(const EmptyReflector()) + ..registerSingleton(Song(title: 'I Wish')) ..registerNamedSingleton('foo', 1) ..registerFactory((container) { - return new Artist( + return Artist( name: 'Stevie Wonder', song: container.make(), ); diff --git a/angel_container/test/lazy_test.dart b/angel_container/test/lazy_test.dart index f52c54fc..c5260702 100644 --- a/angel_container/test/lazy_test.dart +++ b/angel_container/test/lazy_test.dart @@ -3,8 +3,8 @@ import 'package:test/test.dart'; void main() { test('returns the same instance', () { - var container = new Container(const EmptyReflector()) - ..registerLazySingleton((_) => new Dummy('a')); + var container = Container(const EmptyReflector()) + ..registerLazySingleton((_) => Dummy('a')); var first = container.make(); expect(container.make(), first); diff --git a/angel_container/test/named_test.dart b/angel_container/test/named_test.dart index 2e30965c..e4c80079 100644 --- a/angel_container/test/named_test.dart +++ b/angel_container/test/named_test.dart @@ -5,8 +5,8 @@ void main() { Container container; setUp(() { - container = new Container(const EmptyReflector()); - container.registerNamedSingleton('foo', new Foo(bar: 'baz')); + container = Container(const EmptyReflector()); + container.registerNamedSingleton('foo', Foo(bar: 'baz')); }); test('fetch by name', () { @@ -14,7 +14,7 @@ void main() { }); test('cannot redefine', () { - expect(() => container.registerNamedSingleton('foo', new Foo(bar: 'quux')), + expect(() => container.registerNamedSingleton('foo', Foo(bar: 'quux')), throwsStateError); });