Skip to content

Commit 2713188

Browse files
test: checking version number is matching one in pubspec.yaml
1 parent 3f30632 commit 2713188

File tree

4 files changed

+42
-58
lines changed

4 files changed

+42
-58
lines changed

analysis_options.yaml

+2-54
Original file line numberDiff line numberDiff line change
@@ -23,81 +23,48 @@ analyzer:
2323

2424
linter:
2525
rules:
26-
# these rules are documented on and in the same order as
27-
# the Dart Lint rules page to make maintenance easier
26+
# See all available options here
2827
# https://github.com/dart-lang/linter/blob/master/example/all.yaml
2928
- always_declare_return_types
3029
- always_put_control_body_on_new_line
31-
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
30+
3231
- always_require_non_null_named_parameters
3332
- annotate_overrides
34-
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
35-
# - avoid_bool_literals_in_conditional_expressions # not yet tested
36-
# - avoid_catches_without_on_clauses # we do this commonly
37-
# - avoid_catching_errors # we do this commonly
38-
- avoid_classes_with_only_static_members
39-
# - avoid_double_and_int_checks # only useful when targeting JS runtime
4033
- avoid_empty_else
4134
- avoid_field_initializers_in_const_classes
4235
- avoid_function_literals_in_foreach_calls
43-
# - avoid_implementing_value_types # not yet tested
4436
- avoid_init_to_null
45-
# - avoid_js_rounded_ints # only useful when targeting JS runtime
4637
- avoid_null_checks_in_equality_operators
47-
# - avoid_positional_boolean_parameters # not yet tested
48-
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
4938
- avoid_relative_lib_imports
5039
- avoid_renaming_method_parameters
5140
- avoid_return_types_on_setters
52-
# - avoid_returning_null # there are plenty of valid reasons to return null
53-
# - avoid_returning_null_for_future # not yet tested
5441
- avoid_returning_null_for_void
55-
# - avoid_returning_this # there are plenty of valid reasons to return this
56-
# - avoid_setters_without_getters # not yet tested
57-
# - avoid_shadowing_type_parameters # not yet tested
58-
# - avoid_single_cascade_in_expression_statements # not yet tested
5942
- avoid_slow_async_io
6043
- avoid_types_as_parameter_names
61-
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
6244
- avoid_unused_constructor_parameters
6345
- avoid_void_async
6446
- await_only_futures
6547
- camel_case_types
6648
- cancel_subscriptions
67-
# - cascade_invocations # not yet tested
68-
# - close_sinks # not reliable enough
69-
# - comment_references # blocked on https://github.com/flutter/flutter/issues/20765
70-
# - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
7149
- control_flow_in_finally
72-
# - curly_braces_in_flow_control_structures # not yet tested
7350
- directives_ordering
7451
- empty_catches
7552
- empty_constructor_bodies
7653
- empty_statements
77-
# - file_names # not yet tested
7854
- flutter_style_todos
7955
- hash_and_equals
8056
- implementation_imports
81-
# - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
8257
- iterable_contains_unrelated_type
83-
# - join_return_with_assignment # not yet tested
8458
- library_names
8559
- library_prefixes
86-
# - lines_longer_than_80_chars # not yet tested
8760
- list_remove_unrelated_type
88-
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
8961
- no_adjacent_strings_in_list
9062
- no_duplicate_case_values
9163
- non_constant_identifier_names
92-
# - null_closures # not yet tested
93-
# - omit_local_variable_types # opposite of always_specify_types
94-
# - one_member_abstracts # too many false positives
95-
# - only_throw_errors # https://github.com/flutter/flutter/issues/5792
9664
- overridden_fields
9765
- package_api_docs
9866
- package_names
9967
- package_prefixed_library_names
100-
# - parameter_assignments # we do this commonly
10168
- prefer_adjacent_string_concatenation
10269
- prefer_asserts_in_initializer_lists
10370
- prefer_collection_literals
@@ -106,43 +73,29 @@ linter:
10673
- prefer_const_constructors_in_immutables
10774
- prefer_const_declarations
10875
- prefer_const_literals_to_create_immutables
109-
# - prefer_constructors_over_static_methods # not yet tested
11076
- prefer_contains
11177
- prefer_equal_for_default_values
112-
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
11378
- prefer_final_fields
11479
- prefer_final_locals
11580
- prefer_foreach
116-
# - prefer_function_declarations_over_variables # not yet tested
11781
- prefer_generic_function_type_aliases
11882
- prefer_initializing_formals
119-
# - prefer_int_literals # not yet tested
120-
# - prefer_interpolation_to_compose_strings # not yet tested
12183
- prefer_is_empty
12284
- prefer_is_not_empty
12385
- prefer_iterable_whereType
124-
# - prefer_mixin # https://github.com/dart-lang/language/issues/32
125-
# - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932
12686
- prefer_single_quotes
12787
- prefer_typing_uninitialized_variables
12888
- prefer_void_to_null
129-
# - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
13089
- recursive_getters
13190
- slash_for_doc_comments
132-
# - sort_constructors_first: vscode's command "dart:sort members" does not follow this
13391
- sort_pub_dependencies
13492
- sort_unnamed_constructors_first
135-
# - super_goes_last # no longer needed w/ Dart 2
13693
- test_types_in_equals
13794
- throw_in_finally
138-
# - type_annotate_public_apis # subset of always_specify_types
13995
- type_init_formals
140-
# - unawaited_futures # too many false positives
141-
# - unnecessary_await_in_return # not yet tested
14296
- unnecessary_brace_in_string_interps
14397
- unnecessary_const
14498
- unnecessary_getters_setters
145-
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
14699
- unnecessary_new
147100
- unnecessary_null_aware_assignments
148101
- unnecessary_null_in_if_null_operators
@@ -151,12 +104,7 @@ linter:
151104
- unnecessary_statements
152105
- unnecessary_this
153106
- unrelated_type_equality_checks
154-
# - use_function_type_syntax_for_parameters # not yet tested
155107
- use_rethrow_when_possible
156-
# - use_setters_to_change_properties # not yet tested
157-
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
158-
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
159108
- valid_regexps
160-
# - void_checks # not yet tested
161109
- public_member_api_docs
162110
- require_trailing_commas

lib/main.dart

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:flutter_launcher_icons/custom_exceptions.dart';
99
import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart';
1010
import 'package:flutter_launcher_icons/ios.dart' as ios_launcher_icons;
1111
import 'package:flutter_launcher_icons/logger.dart';
12+
import 'package:flutter_launcher_icons/pubspec_parser.dart';
1213
import 'package:flutter_launcher_icons/web/web_icon_generator.dart';
1314
import 'package:flutter_launcher_icons/windows/windows_icon_generator.dart';
1415
import 'package:path/path.dart' as path;
@@ -197,10 +198,7 @@ Map<String, dynamic>? loadConfigFileFromArgResults(ArgResults argResults, {bool
197198
}
198199

199200
Map<String, dynamic> loadConfigFile(String path, String? fileOptionResult) {
200-
final File file = File(path);
201-
final String yamlString = file.readAsStringSync();
202-
// ignore: always_specify_types
203-
final Map yamlMap = loadYaml(yamlString);
201+
final yamlMap = PubspecParser.toMap(path);
204202

205203
if (!(yamlMap['flutter_icons'] is Map)) {
206204
stderr.writeln(NoConfigFoundException('Check that your config file '

lib/pubspec_parser.dart

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import 'dart:io';
2+
3+
import 'package:yaml/yaml.dart';
4+
5+
/// helper class for parsing the contents of pubspec file
6+
class PubspecParser {
7+
8+
/// ensures unnamed constructor cannot be used as this class should only have
9+
/// static methods
10+
PubspecParser._();
11+
12+
/// parses the pubspec located at [path] to map
13+
static Map toMap(String path) {
14+
final File file = File(path);
15+
final String yamlString = file.readAsStringSync();
16+
final Map yamlMap = loadYaml(yamlString);
17+
return yamlMap;
18+
}
19+
}

test/package_version_test.dart

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import 'package:flutter_launcher_icons/pubspec_parser.dart';
2+
import 'package:flutter_launcher_icons/src/version.dart';
3+
import 'package:test/test.dart';
4+
5+
void main() {
6+
/// this helps avoid an issue where the pubspec version has been increased but
7+
/// build runner has not been run to up the version which is displayed
8+
/// when flutter_launcher_icons is run
9+
test('package version is correct', () {
10+
final yamlMap = PubspecParser.toMap('pubspec.yaml');
11+
final yamlVersion = yamlMap['version'] as String;
12+
expect(
13+
yamlVersion,
14+
packageVersion,
15+
reason: 'Versions are not matching. Solution: Run build runner to '
16+
'updated generated version value.',
17+
);
18+
});
19+
}

0 commit comments

Comments
 (0)