Pedantic lints
This commit is contained in:
parent
ad7939b904
commit
5386722df3
13 changed files with 66 additions and 65 deletions
|
@ -1,3 +1,4 @@
|
|||
include: package:pedantic/analysis_options.yaml
|
||||
analyzer:
|
||||
strong-mode:
|
||||
implicit-casts: false
|
|
@ -5,7 +5,7 @@ import 'package:angel_container/mirrors.dart';
|
|||
|
||||
Future<void> main() async {
|
||||
// Create a container instance.
|
||||
var container = new Container(const MirrorsReflector());
|
||||
var container = Container(const MirrorsReflector());
|
||||
|
||||
// Register a singleton.
|
||||
container.registerSingleton<Engine>(Engine(40));
|
||||
|
|
|
@ -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<T>` or `T`.
|
||||
Future<T> makeAsync<T>([Type type]) {
|
||||
type ??= T;
|
||||
Type futureType = null; //.Future<T>.value(null).runtimeType;
|
||||
Type futureType; //.Future<T>.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<T>(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<T>(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;
|
||||
|
|
|
@ -8,7 +8,7 @@ final Map<Symbol, String> _symbolNames = <Symbol, String>{};
|
|||
/// 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 <ReflectedInstance>[],
|
||||
const <ReflectedFunction>[],
|
||||
const <ReflectedDeclaration>[],
|
||||
dynamic);
|
||||
Object);
|
||||
|
||||
@override
|
||||
ReflectedInstance newInstance(
|
||||
String constructorName, List positionalArguments,
|
||||
[Map<String, dynamic> namedArguments, List<Type> 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 <ReflectedTypeParameter>[], dynamic);
|
||||
: super('(empty)', const <ReflectedTypeParameter>[], Object);
|
||||
|
||||
@override
|
||||
ReflectedInstance newInstance(
|
||||
String constructorName, List positionalArguments,
|
||||
[Map<String, dynamic> namedArguments, List<Type> 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().');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String, dynamic> namedArguments, List<Type> 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<ReflectedInstance> get annotations =>
|
||||
mirror.metadata.map((m) => new _ReflectedInstanceMirror(m)).toList();
|
||||
mirror.metadata.map((m) => _ReflectedInstanceMirror(m)).toList();
|
||||
|
||||
@override
|
||||
List<ReflectedFunction> get constructors => _constructorsOf(mirror);
|
||||
|
@ -171,8 +171,8 @@ class _ReflectedClassMirror extends ReflectedClass {
|
|||
ReflectedInstance newInstance(
|
||||
String constructorName, List positionalArguments,
|
||||
[Map<String, dynamic> namedArguments, List<Type> 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),
|
||||
<ReflectedTypeParameter>[],
|
||||
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));
|
||||
|
|
|
@ -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`.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,15 +10,15 @@ class StaticReflector extends Reflector {
|
|||
final Map<Object, ReflectedInstance> 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.');
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel_container
|
||||
version: 1.0.4
|
||||
version: 1.1.0
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
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:
|
||||
pedantic: ^1.0.0
|
||||
test: ^1.0.0
|
|
@ -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<Future<int>>((_) 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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -5,11 +5,11 @@ void main() {
|
|||
Container container;
|
||||
|
||||
setUp(() {
|
||||
container = new Container(const EmptyReflector())
|
||||
..registerSingleton<Song>(new Song(title: 'I Wish'))
|
||||
container = Container(const EmptyReflector())
|
||||
..registerSingleton<Song>(Song(title: 'I Wish'))
|
||||
..registerNamedSingleton('foo', 1)
|
||||
..registerFactory<Artist>((container) {
|
||||
return new Artist(
|
||||
return Artist(
|
||||
name: 'Stevie Wonder',
|
||||
song: container.make<Song>(),
|
||||
);
|
||||
|
|
|
@ -3,8 +3,8 @@ import 'package:test/test.dart';
|
|||
|
||||
void main() {
|
||||
test('returns the same instance', () {
|
||||
var container = new Container(const EmptyReflector())
|
||||
..registerLazySingleton<Dummy>((_) => new Dummy('a'));
|
||||
var container = Container(const EmptyReflector())
|
||||
..registerLazySingleton<Dummy>((_) => Dummy('a'));
|
||||
|
||||
var first = container.make<Dummy>();
|
||||
expect(container.make<Dummy>(), first);
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue