fixed cide analizer warnings

This commit is contained in:
Sergey Penkovsky
2021-04-29 10:02:32 +03:00
parent 5ea3744961
commit 0e37d7f222
9 changed files with 95 additions and 97 deletions

View File

@@ -1 +0,0 @@
include: package:effective_dart/analysis_options.yaml

1
analysis_options.yaml Normal file
View File

@@ -0,0 +1 @@
include: package:pedantic/analysis_options.yaml

View File

@@ -6,8 +6,8 @@ import 'package:cherrypick/module.dart';
class AppModule extends Module { class AppModule extends Module {
@override @override
void builder(Scope currentScope) { void builder(Scope currentScope) {
bind<ApiClient>().withName("apiClientMock").toInstance(ApiClientMock()); bind<ApiClient>().withName('apiClientMock').toInstance(ApiClientMock());
bind<ApiClient>().withName("apiClientImpl").toInstance(ApiClientImpl()); bind<ApiClient>().withName('apiClientImpl').toInstance(ApiClientImpl());
} }
} }
@@ -19,18 +19,18 @@ class FeatureModule extends Module {
@override @override
void builder(Scope currentScope) { void builder(Scope currentScope) {
bind<DataRepository>() bind<DataRepository>()
.withName("networkRepo") .withName('networkRepo')
.toProvide( .toProvide(
() => NetworkDataRepository( () => NetworkDataRepository(
currentScope.resolve<ApiClient>( currentScope.resolve<ApiClient>(
named: isMock ? "apiClientMock" : "apiClientImpl", named: isMock ? 'apiClientMock' : 'apiClientImpl',
), ),
), ),
) )
.singeltone(); .singeltone();
bind<DataBloc>().toProvide( bind<DataBloc>().toProvide(
() => DataBloc( () => DataBloc(
currentScope.resolve<DataRepository>(named: "networkRepo"), currentScope.resolve<DataRepository>(named: 'networkRepo'),
), ),
); );
} }
@@ -42,7 +42,7 @@ void main() async {
]); ]);
final subScope = scope final subScope = scope
.openSubScope("featureScope") .openSubScope('featureScope')
.installModules([FeatureModule(isMock: true)]); .installModules([FeatureModule(isMock: true)]);
final dataBloc = subScope.resolve<DataBloc>(); final dataBloc = subScope.resolve<DataBloc>();
@@ -56,7 +56,7 @@ class DataBloc {
final DataRepository _dataRepository; final DataRepository _dataRepository;
Stream<String> get data => _dataController.stream; Stream<String> get data => _dataController.stream;
StreamController<String> _dataController = new StreamController.broadcast(); final StreamController<String> _dataController = StreamController.broadcast();
DataBloc(this._dataRepository); DataBloc(this._dataRepository);

View File

@@ -20,8 +20,8 @@ class Binding<T> {
late Mode _mode; late Mode _mode;
late Type _key; late Type _key;
late String _name; late String _name;
T? _instance = null; T? _instance;
T? Function()? _provider = null; T? Function()? _provider;
late bool _isSingeltone = false; late bool _isSingeltone = false;
late bool _isNamed = false; late bool _isNamed = false;

View File

@@ -13,7 +13,7 @@
import 'package:cherrypick/scope.dart'; import 'package:cherrypick/scope.dart';
Scope? _rootScope = null; Scope? _rootScope;
class CherryPick { class CherryPick {
/// RU: Метод открывает главный [Scope]. /// RU: Метод открывает главный [Scope].
@@ -21,9 +21,7 @@ class CherryPick {
/// ///
/// return /// return
static Scope openRootScope() { static Scope openRootScope() {
if (_rootScope == null) { _rootScope ??= Scope(null);
_rootScope = Scope(null);
}
return _rootScope!; return _rootScope!;
} }

View File

@@ -103,8 +103,8 @@ class Scope {
T? tryResolve<T>({String? named}) { T? tryResolve<T>({String? named}) {
// 1 Поиск зависимости по всем модулям текущего скоупа // 1 Поиск зависимости по всем модулям текущего скоупа
if (_modulesList.isNotEmpty) { if (_modulesList.isNotEmpty) {
for (Module module in _modulesList) { for (var module in _modulesList) {
for (Binding binding in module.bindingSet) { for (var binding in module.bindingSet) {
if (binding.key == T && if (binding.key == T &&
((!binding.isNamed && named == null) || ((!binding.isNamed && named == null) ||
(binding.isNamed && named == binding.name))) { (binding.isNamed && named == binding.name))) {

View File

@@ -13,7 +13,7 @@ dependencies:
meta: ^1.3.0 meta: ^1.3.0
dev_dependencies: dev_dependencies:
effective_dart: ^1.3.1 pedantic: ^1.11.0
test: ^1.17.2 test: ^1.17.2

View File

@@ -2,200 +2,200 @@ import 'package:cherrypick/binding.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
void main() { void main() {
group("Check instance.", () { group('Check instance.', () {
group("Without name.", () { group('Without name.', () {
test("Binding resolves null", () { test('Binding resolves null', () {
final binding = Binding<int>(); final binding = Binding<int>();
expect(binding.instance, null); expect(binding.instance, null);
}); });
test("Binding check mode", () { test('Binding check mode', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toInstance(expectedValue); final binding = Binding<int>().toInstance(expectedValue);
expect(binding.mode, Mode.INSTANCE); expect(binding.mode, Mode.INSTANCE);
}); });
test("Binding check singeltone", () { test('Binding check singeltone', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toInstance(expectedValue); final binding = Binding<int>().toInstance(expectedValue);
expect(binding.isSingeltone, true); expect(binding.isSingeltone, true);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toInstance(expectedValue); final binding = Binding<int>().toInstance(expectedValue);
expect(binding.instance, expectedValue); expect(binding.instance, expectedValue);
}); });
test("Binding resolves value", () { test('Binding resolves value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toInstance(expectedValue); final binding = Binding<int>().toInstance(expectedValue);
expect(binding.instance, expectedValue); expect(binding.instance, expectedValue);
}); });
}); });
group("With name.", () { group('With name.', () {
test("Binding resolves null", () { test('Binding resolves null', () {
final binding = Binding<int>().withName("expectedValue"); final binding = Binding<int>().withName('expectedValue');
expect(binding.instance, null); expect(binding.instance, null);
}); });
test("Binding check mode", () { test('Binding check mode', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().withName("expectedValue").toInstance(expectedValue); Binding<int>().withName('expectedValue').toInstance(expectedValue);
expect(binding.mode, Mode.INSTANCE); expect(binding.mode, Mode.INSTANCE);
}); });
test("Binding check key", () { test('Binding check key', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().withName("expectedValue").toInstance(expectedValue); Binding<int>().withName('expectedValue').toInstance(expectedValue);
expect(binding.key, int); expect(binding.key, int);
}); });
test("Binding check singeltone", () { test('Binding check singeltone', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().withName("expectedValue").toInstance(expectedValue); Binding<int>().withName('expectedValue').toInstance(expectedValue);
expect(binding.isSingeltone, true); expect(binding.isSingeltone, true);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().withName("expectedValue").toInstance(expectedValue); Binding<int>().withName('expectedValue').toInstance(expectedValue);
expect(binding.instance, expectedValue); expect(binding.instance, expectedValue);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().withName("expectedValue").toInstance(expectedValue); Binding<int>().withName('expectedValue').toInstance(expectedValue);
expect(binding.name, "expectedValue"); expect(binding.name, 'expectedValue');
}); });
test("Binding resolves value", () { test('Binding resolves value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().withName("expectedValue").toInstance(expectedValue); Binding<int>().withName('expectedValue').toInstance(expectedValue);
expect(binding.instance, expectedValue); expect(binding.instance, expectedValue);
}); });
}); });
}); });
group("Check provide.", () { group('Check provide.', () {
group("Without name.", () { group('Without name.', () {
test("Binding resolves null", () { test('Binding resolves null', () {
final binding = Binding<int>(); final binding = Binding<int>();
expect(binding.provider, null); expect(binding.provider, null);
}); });
test("Binding check mode", () { test('Binding check mode', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toProvide(() => expectedValue); final binding = Binding<int>().toProvide(() => expectedValue);
expect(binding.mode, Mode.PROVIDER_INSTANCE); expect(binding.mode, Mode.PROVIDER_INSTANCE);
}); });
test("Binding check singeltone", () { test('Binding check singeltone', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toProvide(() => expectedValue); final binding = Binding<int>().toProvide(() => expectedValue);
expect(binding.isSingeltone, false); expect(binding.isSingeltone, false);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toProvide(() => expectedValue); final binding = Binding<int>().toProvide(() => expectedValue);
expect(binding.provider, expectedValue); expect(binding.provider, expectedValue);
}); });
test("Binding resolves value", () { test('Binding resolves value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>().toProvide(() => expectedValue); final binding = Binding<int>().toProvide(() => expectedValue);
expect(binding.provider, expectedValue); expect(binding.provider, expectedValue);
}); });
}); });
group("With name.", () { group('With name.', () {
test("Binding resolves null", () { test('Binding resolves null', () {
final binding = Binding<int>().withName("expectedValue"); final binding = Binding<int>().withName('expectedValue');
expect(binding.provider, null); expect(binding.provider, null);
}); });
test("Binding check mode", () { test('Binding check mode', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue); .toProvide(() => expectedValue);
expect(binding.mode, Mode.PROVIDER_INSTANCE); expect(binding.mode, Mode.PROVIDER_INSTANCE);
}); });
test("Binding check key", () { test('Binding check key', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue); .toProvide(() => expectedValue);
expect(binding.key, int); expect(binding.key, int);
}); });
test("Binding check singeltone", () { test('Binding check singeltone', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue); .toProvide(() => expectedValue);
expect(binding.isSingeltone, false); expect(binding.isSingeltone, false);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue); .toProvide(() => expectedValue);
expect(binding.provider, expectedValue); expect(binding.provider, expectedValue);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue); .toProvide(() => expectedValue);
expect(binding.name, "expectedValue"); expect(binding.name, 'expectedValue');
}); });
test("Binding resolves value", () { test('Binding resolves value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue); .toProvide(() => expectedValue);
expect(binding.provider, expectedValue); expect(binding.provider, expectedValue);
}); });
}); });
}); });
group("Check singeltone provide.", () { group('Check singeltone provide.', () {
group("Without name.", () { group('Without name.', () {
test("Binding resolves null", () { test('Binding resolves null', () {
final binding = Binding<int>().singeltone(); final binding = Binding<int>().singeltone();
expect(binding.provider, null); expect(binding.provider, null);
}); });
test("Binding check mode", () { test('Binding check mode', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().toProvide(() => expectedValue).singeltone(); Binding<int>().toProvide(() => expectedValue).singeltone();
@@ -203,7 +203,7 @@ void main() {
expect(binding.mode, Mode.PROVIDER_INSTANCE); expect(binding.mode, Mode.PROVIDER_INSTANCE);
}); });
test("Binding check singeltone", () { test('Binding check singeltone', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().toProvide(() => expectedValue).singeltone(); Binding<int>().toProvide(() => expectedValue).singeltone();
@@ -211,7 +211,7 @@ void main() {
expect(binding.isSingeltone, true); expect(binding.isSingeltone, true);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().toProvide(() => expectedValue).singeltone(); Binding<int>().toProvide(() => expectedValue).singeltone();
@@ -219,7 +219,7 @@ void main() {
expect(binding.provider, expectedValue); expect(binding.provider, expectedValue);
}); });
test("Binding resolves value", () { test('Binding resolves value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = final binding =
Binding<int>().toProvide(() => expectedValue).singeltone(); Binding<int>().toProvide(() => expectedValue).singeltone();
@@ -227,66 +227,66 @@ void main() {
}); });
}); });
group("With name.", () { group('With name.', () {
test("Binding resolves null", () { test('Binding resolves null', () {
final binding = Binding<int>().withName("expectedValue").singeltone(); final binding = Binding<int>().withName('expectedValue').singeltone();
expect(binding.provider, null); expect(binding.provider, null);
}); });
test("Binding check mode", () { test('Binding check mode', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue) .toProvide(() => expectedValue)
.singeltone(); .singeltone();
expect(binding.mode, Mode.PROVIDER_INSTANCE); expect(binding.mode, Mode.PROVIDER_INSTANCE);
}); });
test("Binding check key", () { test('Binding check key', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue) .toProvide(() => expectedValue)
.singeltone(); .singeltone();
expect(binding.key, int); expect(binding.key, int);
}); });
test("Binding check singeltone", () { test('Binding check singeltone', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue) .toProvide(() => expectedValue)
.singeltone(); .singeltone();
expect(binding.isSingeltone, true); expect(binding.isSingeltone, true);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue) .toProvide(() => expectedValue)
.singeltone(); .singeltone();
expect(binding.provider, expectedValue); expect(binding.provider, expectedValue);
}); });
test("Binding check value", () { test('Binding check value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue) .toProvide(() => expectedValue)
.singeltone(); .singeltone();
expect(binding.name, "expectedValue"); expect(binding.name, 'expectedValue');
}); });
test("Binding resolves value", () { test('Binding resolves value', () {
final expectedValue = 5; final expectedValue = 5;
final binding = Binding<int>() final binding = Binding<int>()
.withName("expectedValue") .withName('expectedValue')
.toProvide(() => expectedValue) .toProvide(() => expectedValue)
.singeltone(); .singeltone();
expect(binding.provider, expectedValue); expect(binding.provider, expectedValue);

View File

@@ -3,26 +3,26 @@ import 'package:cherrypick/scope.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
void main() { void main() {
group("Without parent scope.", () { group('Without parent scope.', () {
test('Parent scope is null.', () { test('Parent scope is null.', () {
final scope = new Scope(null); final scope = Scope(null);
expect(scope.parentScope, null); expect(scope.parentScope, null);
}); });
test('Open sub scope.', () { test('Open sub scope.', () {
final scope = new Scope(null); final scope = Scope(null);
final subScope = scope.openSubScope("subScope"); final subScope = scope.openSubScope('subScope');
expect(scope.openSubScope("subScope"), subScope); expect(scope.openSubScope('subScope'), subScope);
}); });
test("Container throws state error if the value can't be resolved", () { test("Container throws state error if the value can't be resolved", () {
final scope = new Scope(null); final scope = Scope(null);
expect(() => scope.resolve<String>(), throwsA(isA<StateError>())); expect(() => scope.resolve<String>(), throwsA(isA<StateError>()));
}); });
test('Container resolves value after adding a dependency', () { test('Container resolves value after adding a dependency', () {
final expectedValue = "test string"; final expectedValue = 'test string';
final scope = new Scope(null) final scope = Scope(null)
.installModules([TestModule<String>(value: expectedValue)]); .installModules([TestModule<String>(value: expectedValue)]);
expect(scope.resolve<String>(), expectedValue); expect(scope.resolve<String>(), expectedValue);
}); });
@@ -42,7 +42,7 @@ void main() {
throwsA(isA<StateError>())); throwsA(isA<StateError>()));
}); });
*/ */
test("Container resolve() returns a value from parent container.", () { test('Container resolve() returns a value from parent container.', () {
final expectedValue = 5; final expectedValue = 5;
final parentScope = Scope(null); final parentScope = Scope(null);
final scope = Scope(parentScope); final scope = Scope(parentScope);
@@ -52,10 +52,10 @@ void main() {
expect(scope.resolve<int>(), expectedValue); expect(scope.resolve<int>(), expectedValue);
}); });
test("Container resolve() returns a several value from parent container.", test('Container resolve() returns a several value from parent container.',
() { () {
final expectedIntValue = 5; final expectedIntValue = 5;
final expectedStringValue = "Hello world"; final expectedStringValue = 'Hello world';
final parentScope = Scope(null).installModules([ final parentScope = Scope(null).installModules([
TestModule<int>(value: expectedIntValue), TestModule<int>(value: expectedIntValue),
TestModule<String>(value: expectedStringValue) TestModule<String>(value: expectedStringValue)