Skip to content

Commit

Permalink
added lint package
Browse files Browse the repository at this point in the history
  • Loading branch information
escamoteur committed Feb 13, 2020
1 parent 23c9726 commit b40b6d1
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 33 deletions.
16 changes: 16 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include: package:lint/analysis_options_package.yaml

# analyzer:
# exclude:

linter:
rules:
# ------ Disable individual rules ----- #
# --- #
# Turn off what you don't like. #
# ------------------------------------- #

# avoid_print: false
# unnecessary_await_in_return: false
# type_annotate_public_apis: false
# avoid_function_literals_in_foreach_calls: false
4 changes: 2 additions & 2 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\Entwicklung\flutter"
export "FLUTTER_ROOT=C:\Entwicklung\Flutter"
export "FLUTTER_APPLICATION_PATH=C:\Entwicklung\packages\get_it\example"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "FLUTTER_FRAMEWORK_DIR=C:\Entwicklung\flutter\bin\cache\artifacts\engine\ios"
export "FLUTTER_FRAMEWORK_DIR=C:\Entwicklung\Flutter\bin\cache\artifacts\engine\ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
File renamed without changes.
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ packages:
path: ".."
relative: true
source: path
version: "4.0.0-beta2"
version: "4.0.0-release-candidate"
glob:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies:
flutter:
sdk: flutter
get_it:
path: ..\
path: ../
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
Expand Down
4 changes: 2 additions & 2 deletions lib/get_it.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ abstract class GetIt {
/// were ready in the given time. The Exception contains details on which Singletons are not ready yet.
/// if [allReady] should not wait for the completion of async Signletons set
/// [ignorePendingAsyncCreation==true]
Future<void> allReady({Duration timeout, ignorePendingAsyncCreation = false});
Future<void> allReady({Duration timeout, bool ignorePendingAsyncCreation = false});

/// Returns a Future that completes if the instance of an Singleton, defined by Type [T] or
/// by name [instanceName] or by passing the an existing [instance], is ready
Expand All @@ -297,7 +297,7 @@ abstract class GetIt {
/// Returns if all async Singletons are ready without waiting
/// if [allReady] should not wait for the completion of async Signletons set
/// [ignorePendingAsyncCreation==true]
bool allReadySync([ignorePendingAsyncCreation = false]);
bool allReadySync([bool ignorePendingAsyncCreation = false]);

/// Used to manually signal the ready state of a Singleton.
/// If you want to use this mechanism you have to pass [signalsReady==true] when registering
Expand Down
46 changes: 23 additions & 23 deletions lib/get_it_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class _ServiceFactory<T, P1, P2> {
param2 == null || param2.runtimeType == param2Type,
'Incompatible Type passed as param2\n'
'expected: $param2Type actual: ${param2.runtimeType}');
return creationFunctionParam(param1, param2);
return creationFunctionParam(param1 as P1, param2 as P2);
} else {
return creationFunction();
}
Expand All @@ -138,7 +138,7 @@ class _ServiceFactory<T, P1, P2> {
}

/// returns an async instance depending on the type of the registration if [async==true] or if [dependsOn.isnoEmpty].
Future<T> getObjectAsync(dynamic param1, dynamic param2) async {
Future<R> getObjectAsync<R>(dynamic param1, dynamic param2) async {
assert(
!(factoryType != _ServiceFactoryType.alwaysNew &&
(param1 != null || param2 != null)),
Expand All @@ -160,28 +160,28 @@ class _ServiceFactory<T, P1, P2> {
param2 == null || param2.runtimeType == param2Type,
'Incompatible Type passed a param2\n'
'expected: $param2Type actual: ${param2.runtimeType}');
return asyncCreationFunctionParam(param1, param2);
return asyncCreationFunctionParam(param1 as P1, param2 as P2) as R;
} else {
return asyncCreationFunction();
return asyncCreationFunction() as R;
}
break;
case _ServiceFactoryType.constant:
if (instance != null) {
return Future<T>.value(instance);
return Future<R>.value(instance as R);
} else {
assert(pendingResult != null);
return pendingResult;
return pendingResult as Future<R>;
}
break;
case _ServiceFactoryType.lazy:
if (instance != null) {
// We already have a finished instance
return Future<T>.value(instance);
return Future<R>.value(instance as R);
} else {
if (pendingResult !=
null) // an async creation is already in progress
{
return pendingResult;
return pendingResult as Future<R>;
}

/// Seems this is really the first access to this async Signleton
Expand All @@ -195,7 +195,7 @@ class _ServiceFactory<T, P1, P2> {
instance = newInstance;
return newInstance;
});
return pendingResult;
return pendingResult as Future<R>;
}
break;
default:
Expand Down Expand Up @@ -238,11 +238,11 @@ class _GetItImplementation implements GetIt {

_ServiceFactory<T, dynamic, dynamic> instanceFactory;
if (instanceName != null) {
instanceFactory = _factoriesByName[instanceName];
instanceFactory = _factoriesByName[instanceName] as _ServiceFactory<T, dynamic, dynamic>;
assert(instanceFactory != null,
"Object/factory with name $instanceName is not registered inside GetIt");
} else {
instanceFactory = _factories[T];
instanceFactory = _factories[T] as _ServiceFactory<T, dynamic, dynamic>;
assert(instanceFactory != null,
"No type ${T.toString()} is registered inside GetIt.\n Did you forget to pass an instance name? \n(Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;)");
}
Expand Down Expand Up @@ -274,7 +274,7 @@ class _GetItImplementation implements GetIt {
assert(instance is T,
"Object with name $instanceName has a different type (${instanceFactory.registrationType.toString()}) than the one that is inferred (${T.toString()}) where you call it");

return instance;
return instance as T;
}

/// Callable class so that you can write `GetIt.instance<MyType>` instead of
Expand All @@ -290,7 +290,7 @@ class _GetItImplementation implements GetIt {
@override
Future<T> getAsync<T>({String instanceName, dynamic param1, dynamic param2}) {
final factoryToGet = _findFactoryByNameOrType<T>(instanceName);
return factoryToGet.getObjectAsync(param1, param2);
return factoryToGet.getObjectAsync<T>(param1, param2);
}

/// registers a type so that a new instance will be created on each call of [get] on that type
Expand Down Expand Up @@ -431,7 +431,7 @@ class _GetItImplementation implements GetIt {
/// [instanceName] if you provide a value here your instance gets registered with that
/// name instead of a type. This should only be necessary if you need to register more
/// than one instance of one type. Its highly not recommended
/// [dependsOn] if this instance depends on other registered Singletons before it can be initilaized
/// [dependsOn] if this instance depends on other registered Singletons before it can be initialized
/// you can either orchestrate this manually using [isReady()] or pass a list of the types that the
/// instance depends on here. [factoryFunc] won't get executed till this types are ready.
/// [func] is called
Expand Down Expand Up @@ -463,7 +463,7 @@ class _GetItImplementation implements GetIt {
/// [instanceName] if you provide a value here your instance gets registered with that
/// name instead of a type. This should only be necessary if you need to register more
/// than one instance of one type. Its highly not recommended
/// [dependsOn] if this instance depends on other registered Singletons before it can be initilaized
/// [dependsOn] if this instance depends on other registered Singletons before it can be initialized
/// you can either orchestrate this manually using [isReady()] or pass a list of the types that the
/// instance depends on here. [factoryFunc] won't get executed till this types are ready.
/// If [signalsReady] is set to `true` it means that the future you can get from `allReady()` cannot complete until this
Expand Down Expand Up @@ -549,8 +549,8 @@ class _GetItImplementation implements GetIt {
final serviceFactory = _ServiceFactory<T, P1, P2>(
type,
creationFunction: factoryFunc,
creationFunctionParam: factoryFuncParam,
asyncCreationFunctionParam: factoryFuncParamAsync,
creationFunctionParam: factoryFuncParam as FactoryFuncParam<T, P1, P2>,
asyncCreationFunctionParam: factoryFuncParamAsync ,
asyncCreationFunction: factoryFuncAsync,
instance: instance,
isAsync: isAsync,
Expand Down Expand Up @@ -619,7 +619,7 @@ class _GetItImplementation implements GetIt {
if (!isAsync) {
/// SingletonWithDepencencies
serviceFactory.instance = factoryFunc();
isReadyFuture = Future.value(serviceFactory.instance);
isReadyFuture = Future<T>.value(serviceFactory.instance as T);
if (!serviceFactory.shouldSignalReady) {
/// As this isn't an asnc function we declare it as ready here
/// if is wasn't marked that it will signalReady
Expand Down Expand Up @@ -647,7 +647,7 @@ class _GetItImplementation implements GetIt {
/// we just use that one
serviceFactory.pendingResult =
outerFutureGroup.future.then((completedFutures) {
return completedFutures.last;
return completedFutures.last as Future<T>;
});
}
}
Expand Down Expand Up @@ -698,7 +698,7 @@ class _GetItImplementation implements GetIt {
}

if (factoryToRemove.instance != null) {
disposingFunction?.call(factoryToRemove.instance);
disposingFunction?.call(factoryToRemove.instance as T);
}
}

Expand Down Expand Up @@ -730,7 +730,7 @@ class _GetItImplementation implements GetIt {
instanceFactory._readyCompleter = Completer();

if (instanceFactory.instance != null) {
disposingFunction?.call(instanceFactory.instance);
disposingFunction?.call(instanceFactory.instance as T);
}
}

Expand Down Expand Up @@ -827,7 +827,7 @@ class _GetItImplementation implements GetIt {
/// were ready in the given time. The Exception contains details on which Singletons are not ready yet.
@override
Future<void> allReady(
{Duration timeout, ignorePendingAsyncCreation = false}) {
{Duration timeout, bool ignorePendingAsyncCreation = false}) {
FutureGroup futures = FutureGroup();
_factories.values
.followedBy(_factoriesByName.values)
Expand All @@ -852,7 +852,7 @@ class _GetItImplementation implements GetIt {
/// if [allReady] should not wait for the completion of async Signletons set
/// [ignorePendingAsyncCreation==true]
@override
bool allReadySync([ignorePendingAsyncCreation = false]) {
bool allReadySync([bool ignorePendingAsyncCreation = false]) {
final notReadyTypes = _factories.values
.followedBy(_factoriesByName.values)
.where((x) => ((x.isAsync && !ignorePendingAsyncCreation ||
Expand Down
9 changes: 8 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.13"
lint:
dependency: "direct dev"
description:
name: lint
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
logging:
dependency: transitive
description:
Expand Down Expand Up @@ -366,4 +373,4 @@ packages:
source: hosted
version: "2.1.15"
sdks:
dart: ">=2.1.1-dev.0.0 <3.0.0"
dart: ">=2.7.0 <3.0.0"
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: get_it
description: Simple direct Service Locator that allows to decouple the interface from a concrete implementation and to access the concrete implementation from everywhere in your App"
version: 4.0.0-beta3
version: 4.0.0-release-candidate
maintainer: Thomas Burkhart (@escamoteur)
authors:
- Flutter Community <[email protected]>
Expand All @@ -17,3 +17,4 @@ dependencies:

dev_dependencies:
test:
lint: 1.1.1
2 changes: 1 addition & 1 deletion test/async_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void main() {
// this are async calls fire and forget
getIt<TestClass>().initWithSignal();
getIt<TestClass2>().initWithSignal();
TestClass2 instance = getIt(instanceName:'Second Instance');
TestClass2 instance = getIt<TestClass2>(instanceName:'Second Instance');
instance.initWithSignal();

expect(getIt.allReady(), completes);
Expand Down
2 changes: 1 addition & 1 deletion test/get_it_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void main() {

expect(instance1 is TestClass, true);

TestClass instance2 = getIt(instanceName:'ConstantByName');
TestClass instance2 = getIt(instanceName:'ConstantByName') as TestClass;

expect(instance1, instance2);

Expand Down

0 comments on commit b40b6d1

Please sign in to comment.