From 938f8df8b6b35919facccf38e2f8d36432372215 Mon Sep 17 00:00:00 2001 From: Sergey Penkovsky Date: Mon, 22 May 2023 15:58:03 +0300 Subject: [PATCH] supported Dart 3.0 and fixed lint warnings --- CHANGELOG.md | 4 ++++ analysis_options.yaml | 31 ++++++++++++++++++++++++++++++- lib/src/binding.dart | 10 +++++----- lib/src/scope.dart | 10 ++++++---- pubspec.yaml | 7 ++++--- test/src/binding_test.dart | 12 ++++++------ 6 files changed, 55 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6a9088..de7d899 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog +2.0.0 supported Dart 3.0 + +--- + 1.1.0 cheked support Dart 3.0 --- diff --git a/analysis_options.yaml b/analysis_options.yaml index d4fcc1a..55c7822 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1 +1,30 @@ -include: package:pedantic/analysis_options.yaml \ No newline at end of file +# This file configures the static analysis results for your project (errors, +# warnings, and lints). +# +# This enables the 'recommended' set of lints from `package:lints`. +# This set helps identify many issues that may lead to problems when running +# or consuming Dart code, and enforces writing Dart using a single, idiomatic +# style and format. +# +# If you want a smaller set of lints you can change this to specify +# 'package:lints/core.yaml'. These are just the most critical lints +# (the recommended set includes the core lints). +# The core lints are also what is used by pub.dev for scoring packages. + +include: package:lints/recommended.yaml + +# Uncomment the following section to specify additional rules. + +# linter: +# rules: +# - camel_case_types + +# analyzer: +# exclude: +# - path/to/excluded/files/** + +# For more information about the core and recommended set of lints, see +# https://dart.dev/go/core-lints + +# For additional information about configuring this file, see +# https://dart.dev/guides/language/analysis-options \ No newline at end of file diff --git a/lib/src/binding.dart b/lib/src/binding.dart index c1d98ce..278d133 100644 --- a/lib/src/binding.dart +++ b/lib/src/binding.dart @@ -11,7 +11,7 @@ /// limitations under the License. /// -enum Mode { SIMPLE, INSTANCE, PROVIDER_INSTANCE, PROVIDER_WITH_PARAMS_INSTANCE } +enum Mode { simple, instance, providerInstance, providerInstanceWithParams } typedef ProviderWithParams = T Function(dynamic params); @@ -29,7 +29,7 @@ class Binding { late bool _isNamed = false; Binding() { - _mode = Mode.SIMPLE; + _mode = Mode.simple; _key = T; } @@ -78,7 +78,7 @@ class Binding { /// /// return [Binding] Binding toInstance(T value) { - _mode = Mode.INSTANCE; + _mode = Mode.instance; _instance = value; _isSingleton = true; return this; @@ -89,7 +89,7 @@ class Binding { /// /// return [Binding] Binding toProvide(T Function() value) { - _mode = Mode.PROVIDER_INSTANCE; + _mode = Mode.providerInstance; _provider = value; return this; } @@ -99,7 +99,7 @@ class Binding { /// /// return [Binding] Binding toProvideWithParams(ProviderWithParams value) { - _mode = Mode.PROVIDER_WITH_PARAMS_INSTANCE; + _mode = Mode.providerInstanceWithParams; _providerWithParams = value; return this; } diff --git a/lib/src/scope.dart b/lib/src/scope.dart index 46eeaf7..bdcdc43 100644 --- a/lib/src/scope.dart +++ b/lib/src/scope.dart @@ -61,7 +61,9 @@ class Scope { /// return [Scope] Scope installModules(List modules) { _modulesList.addAll(modules); - modules.forEach((module) => module.builder(this)); + for (var module in modules) { + module.builder(this); + } return this; } @@ -110,11 +112,11 @@ class Scope { ((!binding.isNamed && named == null) || (binding.isNamed && named == binding.name))) { switch (binding.mode) { - case Mode.INSTANCE: + case Mode.instance: return binding.instance; - case Mode.PROVIDER_INSTANCE: + case Mode.providerInstance: return binding.provider; - case Mode.PROVIDER_WITH_PARAMS_INSTANCE: + case Mode.providerInstanceWithParams: if (params == null) { throw StateError('Param is null. Maybe you forget pass it'); } diff --git a/pubspec.yaml b/pubspec.yaml index 21645c4..3874e61 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,20 +1,21 @@ name: cherrypick description: Cherrypick is a small dependency injection (DI) library for dart/flutter projects. -version: 1.1.0 +version: 2.0.0 homepage: https://pese-git.github.io/cherrypick-site/ documentation: https://github.com/pese-git/cherrypick/wiki repository: https://github.com/pese-git/cherrypick issue_tracker: https://github.com/pese-git/cherrypick/issues environment: - sdk: ">=2.12.0 <4.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: meta: ^1.3.0 dev_dependencies: - pedantic: ^1.11.0 + #pedantic: ^1.11.0 test: ^1.17.2 mockito: ^5.0.6 + lints: ^2.1.0 diff --git a/test/src/binding_test.dart b/test/src/binding_test.dart index cf78791..34d6c60 100644 --- a/test/src/binding_test.dart +++ b/test/src/binding_test.dart @@ -13,7 +13,7 @@ void main() { final expectedValue = 5; final binding = Binding().toInstance(expectedValue); - expect(binding.mode, Mode.INSTANCE); + expect(binding.mode, Mode.instance); }); test('Binding check singleton', () { @@ -48,7 +48,7 @@ void main() { final binding = Binding().withName('expectedValue').toInstance(expectedValue); - expect(binding.mode, Mode.INSTANCE); + expect(binding.mode, Mode.instance); }); test('Binding check key', () { @@ -103,7 +103,7 @@ void main() { final expectedValue = 5; final binding = Binding().toProvide(() => expectedValue); - expect(binding.mode, Mode.PROVIDER_INSTANCE); + expect(binding.mode, Mode.providerInstance); }); test('Binding check singleton', () { @@ -139,7 +139,7 @@ void main() { .withName('expectedValue') .toProvide(() => expectedValue); - expect(binding.mode, Mode.PROVIDER_INSTANCE); + expect(binding.mode, Mode.providerInstance); }); test('Binding check key', () { @@ -200,7 +200,7 @@ void main() { final binding = Binding().toProvide(() => expectedValue).singleton(); - expect(binding.mode, Mode.PROVIDER_INSTANCE); + expect(binding.mode, Mode.providerInstance); }); test('Binding check singleton', () { @@ -240,7 +240,7 @@ void main() { .toProvide(() => expectedValue) .singleton(); - expect(binding.mode, Mode.PROVIDER_INSTANCE); + expect(binding.mode, Mode.providerInstance); }); test('Binding check key', () {