From 0e37d7f2228dd68ea3164a395559e99b325f94d5 Mon Sep 17 00:00:00 2001 From: Sergey Penkovsky Date: Thu, 29 Apr 2021 10:02:32 +0300 Subject: [PATCH] fixed cide analizer warnings --- analysis_options.yaml | 1 - analysis_options.yaml | 1 + example/bin/main.dart | 14 ++--- lib/binding.dart | 4 +- lib/di.dart | 6 +- lib/scope.dart | 4 +- pubspec.yaml | 2 +- test/binding_test.dart | 138 ++++++++++++++++++++--------------------- test/scope_test.dart | 22 +++---- 9 files changed, 95 insertions(+), 97 deletions(-) delete mode 100644 analysis_options.yaml create mode 100644 analysis_options.yaml diff --git a/ analysis_options.yaml b/ analysis_options.yaml deleted file mode 100644 index d63af85..0000000 --- a/ analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: package:effective_dart/analysis_options.yaml \ No newline at end of file diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..d4fcc1a --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1 @@ +include: package:pedantic/analysis_options.yaml \ No newline at end of file diff --git a/example/bin/main.dart b/example/bin/main.dart index 966a05f..f356716 100644 --- a/example/bin/main.dart +++ b/example/bin/main.dart @@ -6,8 +6,8 @@ import 'package:cherrypick/module.dart'; class AppModule extends Module { @override void builder(Scope currentScope) { - bind().withName("apiClientMock").toInstance(ApiClientMock()); - bind().withName("apiClientImpl").toInstance(ApiClientImpl()); + bind().withName('apiClientMock').toInstance(ApiClientMock()); + bind().withName('apiClientImpl').toInstance(ApiClientImpl()); } } @@ -19,18 +19,18 @@ class FeatureModule extends Module { @override void builder(Scope currentScope) { bind() - .withName("networkRepo") + .withName('networkRepo') .toProvide( () => NetworkDataRepository( currentScope.resolve( - named: isMock ? "apiClientMock" : "apiClientImpl", + named: isMock ? 'apiClientMock' : 'apiClientImpl', ), ), ) .singeltone(); bind().toProvide( () => DataBloc( - currentScope.resolve(named: "networkRepo"), + currentScope.resolve(named: 'networkRepo'), ), ); } @@ -42,7 +42,7 @@ void main() async { ]); final subScope = scope - .openSubScope("featureScope") + .openSubScope('featureScope') .installModules([FeatureModule(isMock: true)]); final dataBloc = subScope.resolve(); @@ -56,7 +56,7 @@ class DataBloc { final DataRepository _dataRepository; Stream get data => _dataController.stream; - StreamController _dataController = new StreamController.broadcast(); + final StreamController _dataController = StreamController.broadcast(); DataBloc(this._dataRepository); diff --git a/lib/binding.dart b/lib/binding.dart index edc668d..927ed01 100644 --- a/lib/binding.dart +++ b/lib/binding.dart @@ -20,8 +20,8 @@ class Binding { late Mode _mode; late Type _key; late String _name; - T? _instance = null; - T? Function()? _provider = null; + T? _instance; + T? Function()? _provider; late bool _isSingeltone = false; late bool _isNamed = false; diff --git a/lib/di.dart b/lib/di.dart index a14e640..fd31fa1 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -13,7 +13,7 @@ import 'package:cherrypick/scope.dart'; -Scope? _rootScope = null; +Scope? _rootScope; class CherryPick { /// RU: Метод открывает главный [Scope]. @@ -21,9 +21,7 @@ class CherryPick { /// /// return static Scope openRootScope() { - if (_rootScope == null) { - _rootScope = Scope(null); - } + _rootScope ??= Scope(null); return _rootScope!; } diff --git a/lib/scope.dart b/lib/scope.dart index 460993c..44c11c3 100644 --- a/lib/scope.dart +++ b/lib/scope.dart @@ -103,8 +103,8 @@ class Scope { T? tryResolve({String? named}) { // 1 Поиск зависимости по всем модулям текущего скоупа if (_modulesList.isNotEmpty) { - for (Module module in _modulesList) { - for (Binding binding in module.bindingSet) { + for (var module in _modulesList) { + for (var binding in module.bindingSet) { if (binding.key == T && ((!binding.isNamed && named == null) || (binding.isNamed && named == binding.name))) { diff --git a/pubspec.yaml b/pubspec.yaml index d8d7149..e095148 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: meta: ^1.3.0 dev_dependencies: - effective_dart: ^1.3.1 + pedantic: ^1.11.0 test: ^1.17.2 diff --git a/test/binding_test.dart b/test/binding_test.dart index f8b972f..9f18da5 100644 --- a/test/binding_test.dart +++ b/test/binding_test.dart @@ -2,200 +2,200 @@ import 'package:cherrypick/binding.dart'; import 'package:test/test.dart'; void main() { - group("Check instance.", () { - group("Without name.", () { - test("Binding resolves null", () { + group('Check instance.', () { + group('Without name.', () { + test('Binding resolves null', () { final binding = Binding(); expect(binding.instance, null); }); - test("Binding check mode", () { + test('Binding check mode', () { final expectedValue = 5; final binding = Binding().toInstance(expectedValue); expect(binding.mode, Mode.INSTANCE); }); - test("Binding check singeltone", () { + test('Binding check singeltone', () { final expectedValue = 5; final binding = Binding().toInstance(expectedValue); expect(binding.isSingeltone, true); }); - test("Binding check value", () { + test('Binding check value', () { final expectedValue = 5; final binding = Binding().toInstance(expectedValue); expect(binding.instance, expectedValue); }); - test("Binding resolves value", () { + test('Binding resolves value', () { final expectedValue = 5; final binding = Binding().toInstance(expectedValue); expect(binding.instance, expectedValue); }); }); - group("With name.", () { - test("Binding resolves null", () { - final binding = Binding().withName("expectedValue"); + group('With name.', () { + test('Binding resolves null', () { + final binding = Binding().withName('expectedValue'); expect(binding.instance, null); }); - test("Binding check mode", () { + test('Binding check mode', () { final expectedValue = 5; final binding = - Binding().withName("expectedValue").toInstance(expectedValue); + Binding().withName('expectedValue').toInstance(expectedValue); expect(binding.mode, Mode.INSTANCE); }); - test("Binding check key", () { + test('Binding check key', () { final expectedValue = 5; final binding = - Binding().withName("expectedValue").toInstance(expectedValue); + Binding().withName('expectedValue').toInstance(expectedValue); expect(binding.key, int); }); - test("Binding check singeltone", () { + test('Binding check singeltone', () { final expectedValue = 5; final binding = - Binding().withName("expectedValue").toInstance(expectedValue); + Binding().withName('expectedValue').toInstance(expectedValue); expect(binding.isSingeltone, true); }); - test("Binding check value", () { + test('Binding check value', () { final expectedValue = 5; final binding = - Binding().withName("expectedValue").toInstance(expectedValue); + Binding().withName('expectedValue').toInstance(expectedValue); expect(binding.instance, expectedValue); }); - test("Binding check value", () { + test('Binding check value', () { final expectedValue = 5; final binding = - Binding().withName("expectedValue").toInstance(expectedValue); + Binding().withName('expectedValue').toInstance(expectedValue); - expect(binding.name, "expectedValue"); + expect(binding.name, 'expectedValue'); }); - test("Binding resolves value", () { + test('Binding resolves value', () { final expectedValue = 5; final binding = - Binding().withName("expectedValue").toInstance(expectedValue); + Binding().withName('expectedValue').toInstance(expectedValue); expect(binding.instance, expectedValue); }); }); }); - group("Check provide.", () { - group("Without name.", () { - test("Binding resolves null", () { + group('Check provide.', () { + group('Without name.', () { + test('Binding resolves null', () { final binding = Binding(); expect(binding.provider, null); }); - test("Binding check mode", () { + test('Binding check mode', () { final expectedValue = 5; final binding = Binding().toProvide(() => expectedValue); expect(binding.mode, Mode.PROVIDER_INSTANCE); }); - test("Binding check singeltone", () { + test('Binding check singeltone', () { final expectedValue = 5; final binding = Binding().toProvide(() => expectedValue); expect(binding.isSingeltone, false); }); - test("Binding check value", () { + test('Binding check value', () { final expectedValue = 5; final binding = Binding().toProvide(() => expectedValue); expect(binding.provider, expectedValue); }); - test("Binding resolves value", () { + test('Binding resolves value', () { final expectedValue = 5; final binding = Binding().toProvide(() => expectedValue); expect(binding.provider, expectedValue); }); }); - group("With name.", () { - test("Binding resolves null", () { - final binding = Binding().withName("expectedValue"); + group('With name.', () { + test('Binding resolves null', () { + final binding = Binding().withName('expectedValue'); expect(binding.provider, null); }); - test("Binding check mode", () { + test('Binding check mode', () { final expectedValue = 5; final binding = Binding() - .withName("expectedValue") + .withName('expectedValue') .toProvide(() => expectedValue); expect(binding.mode, Mode.PROVIDER_INSTANCE); }); - test("Binding check key", () { + test('Binding check key', () { final expectedValue = 5; final binding = Binding() - .withName("expectedValue") + .withName('expectedValue') .toProvide(() => expectedValue); expect(binding.key, int); }); - test("Binding check singeltone", () { + test('Binding check singeltone', () { final expectedValue = 5; final binding = Binding() - .withName("expectedValue") + .withName('expectedValue') .toProvide(() => expectedValue); expect(binding.isSingeltone, false); }); - test("Binding check value", () { + test('Binding check value', () { final expectedValue = 5; final binding = Binding() - .withName("expectedValue") + .withName('expectedValue') .toProvide(() => expectedValue); expect(binding.provider, expectedValue); }); - test("Binding check value", () { + test('Binding check value', () { final expectedValue = 5; final binding = Binding() - .withName("expectedValue") + .withName('expectedValue') .toProvide(() => expectedValue); - expect(binding.name, "expectedValue"); + expect(binding.name, 'expectedValue'); }); - test("Binding resolves value", () { + test('Binding resolves value', () { final expectedValue = 5; final binding = Binding() - .withName("expectedValue") + .withName('expectedValue') .toProvide(() => expectedValue); expect(binding.provider, expectedValue); }); }); }); - group("Check singeltone provide.", () { - group("Without name.", () { - test("Binding resolves null", () { + group('Check singeltone provide.', () { + group('Without name.', () { + test('Binding resolves null', () { final binding = Binding().singeltone(); expect(binding.provider, null); }); - test("Binding check mode", () { + test('Binding check mode', () { final expectedValue = 5; final binding = Binding().toProvide(() => expectedValue).singeltone(); @@ -203,7 +203,7 @@ void main() { expect(binding.mode, Mode.PROVIDER_INSTANCE); }); - test("Binding check singeltone", () { + test('Binding check singeltone', () { final expectedValue = 5; final binding = Binding().toProvide(() => expectedValue).singeltone(); @@ -211,7 +211,7 @@ void main() { expect(binding.isSingeltone, true); }); - test("Binding check value", () { + test('Binding check value', () { final expectedValue = 5; final binding = Binding().toProvide(() => expectedValue).singeltone(); @@ -219,7 +219,7 @@ void main() { expect(binding.provider, expectedValue); }); - test("Binding resolves value", () { + test('Binding resolves value', () { final expectedValue = 5; final binding = Binding().toProvide(() => expectedValue).singeltone(); @@ -227,66 +227,66 @@ void main() { }); }); - group("With name.", () { - test("Binding resolves null", () { - final binding = Binding().withName("expectedValue").singeltone(); + group('With name.', () { + test('Binding resolves null', () { + final binding = Binding().withName('expectedValue').singeltone(); expect(binding.provider, null); }); - test("Binding check mode", () { + test('Binding check mode', () { final expectedValue = 5; final binding = Binding() - .withName("expectedValue") + .withName('expectedValue') .toProvide(() => expectedValue) .singeltone(); expect(binding.mode, Mode.PROVIDER_INSTANCE); }); - test("Binding check key", () { + test('Binding check key', () { final expectedValue = 5; final binding = Binding() - .withName("expectedValue") + .withName('expectedValue') .toProvide(() => expectedValue) .singeltone(); expect(binding.key, int); }); - test("Binding check singeltone", () { + test('Binding check singeltone', () { final expectedValue = 5; final binding = Binding() - .withName("expectedValue") + .withName('expectedValue') .toProvide(() => expectedValue) .singeltone(); expect(binding.isSingeltone, true); }); - test("Binding check value", () { + test('Binding check value', () { final expectedValue = 5; final binding = Binding() - .withName("expectedValue") + .withName('expectedValue') .toProvide(() => expectedValue) .singeltone(); expect(binding.provider, expectedValue); }); - test("Binding check value", () { + test('Binding check value', () { final expectedValue = 5; final binding = Binding() - .withName("expectedValue") + .withName('expectedValue') .toProvide(() => expectedValue) .singeltone(); - expect(binding.name, "expectedValue"); + expect(binding.name, 'expectedValue'); }); - test("Binding resolves value", () { + test('Binding resolves value', () { final expectedValue = 5; final binding = Binding() - .withName("expectedValue") + .withName('expectedValue') .toProvide(() => expectedValue) .singeltone(); expect(binding.provider, expectedValue); diff --git a/test/scope_test.dart b/test/scope_test.dart index 1fdf724..51f1530 100644 --- a/test/scope_test.dart +++ b/test/scope_test.dart @@ -3,26 +3,26 @@ import 'package:cherrypick/scope.dart'; import 'package:test/test.dart'; void main() { - group("Without parent scope.", () { + group('Without parent scope.', () { test('Parent scope is null.', () { - final scope = new Scope(null); + final scope = Scope(null); expect(scope.parentScope, null); }); test('Open sub scope.', () { - final scope = new Scope(null); - final subScope = scope.openSubScope("subScope"); - expect(scope.openSubScope("subScope"), subScope); + final scope = Scope(null); + final subScope = scope.openSubScope('subScope'); + expect(scope.openSubScope('subScope'), subScope); }); test("Container throws state error if the value can't be resolved", () { - final scope = new Scope(null); + final scope = Scope(null); expect(() => scope.resolve(), throwsA(isA())); }); test('Container resolves value after adding a dependency', () { - final expectedValue = "test string"; - final scope = new Scope(null) + final expectedValue = 'test string'; + final scope = Scope(null) .installModules([TestModule(value: expectedValue)]); expect(scope.resolve(), expectedValue); }); @@ -42,7 +42,7 @@ void main() { throwsA(isA())); }); */ - test("Container resolve() returns a value from parent container.", () { + test('Container resolve() returns a value from parent container.', () { final expectedValue = 5; final parentScope = Scope(null); final scope = Scope(parentScope); @@ -52,10 +52,10 @@ void main() { expect(scope.resolve(), 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 expectedStringValue = "Hello world"; + final expectedStringValue = 'Hello world'; final parentScope = Scope(null).installModules([ TestModule(value: expectedIntValue), TestModule(value: expectedStringValue)