Skip to content

Commit

Permalink
2.0.0 (#17)
Browse files Browse the repository at this point in the history
* Add new lints from the past ~1 year

* Bump license date

* Add 2.0.0 CHANGELOG and bump min sdk to 3.1.0

* Add CODEOWNERS

* Add missing `strict-inference`
  • Loading branch information
matuella authored Dec 29, 2023
1 parent 4da53bd commit 45f3973
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 31 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @matuella
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## 2.0.0

Breaking changes:
- Bumped Dart sdk min version from `2.16.1` to `3.1.0`.
- Updated the deprecated `analyzer.strong-mode` in favor of the `analyzer.language` new options. All three
new options were set to `true`.

- Added and enabled: `collection_methods_unrelated_type`, `combinators_ordering`, `dangling_library_doc_comments`,
`deprecated_member_use_from_same_package`, `discarded_futures`, `implicit_call_tearoffs`, `invalid_case_patterns`,
`library_annotations`, `matching_super_parameters`, `no_literal_bool_comparisons`, `no_self_assignments`,
`no_wildcard_variable_uses`, `type_literal_in_constant_pattern`, `unnecessary_breaks`, `unnecessary_library_directive`,
`unnecessary_null_aware_operator_on_extension_on_nullable`, `unnecessary_to_list_in_spreads`, `unreachable_from_main`,
`use_colored_box`, `use_enums`, `use_string_in_part_of_directives` and `use_super_parameters`.
- Added and disabled: `implicit_reopen`.
- Disabled and removed: `always_require_non_null_named_parameters`, `invariant_booleans`,
`iterable_contains_unrelated_type`, `list_remove_unrelated_type`, `prefer_equal_for_default_values`,
`invariant_booleans` and `iterable_contains_unrelated_type`.
- Removed: `avoid_returning_null` and `avoid_returning_null_for_future`.

## 1.4.0

- Added and enabled: `conditional_uri_does_not_exist` and `unnecessary_late`.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Olympus
Copyright (c) 2023 Olympus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Add this package to your `dev_dependencies` in your `pubspec.yaml`:

```yaml
dev_dependencies:
strict: ^1.4.0
strict: ^2.0.0
```
and the following to your `analysis_options.yaml` (create one in the root of your project if you don't
Expand Down
32 changes: 24 additions & 8 deletions lib/all_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
#
# It's also important to keep updating this list based on the `yaml` above.
#
# Last updated version: 1.18.0 | 10/02/2022 (DD/MM/YYYY)
# Last updated version: 1.35.0 | 29/12/2023 (DD/MM/YYYY)
linter:
rules:
- always_declare_return_types
- always_put_control_body_on_new_line
- always_put_required_named_parameters_first
- always_require_non_null_named_parameters
- always_specify_types
- always_use_package_imports
- annotate_overrides
Expand Down Expand Up @@ -39,8 +38,6 @@ linter:
- avoid_relative_lib_imports
- avoid_renaming_method_parameters
- avoid_return_types_on_setters
- avoid_returning_null
- avoid_returning_null_for_future
- avoid_returning_null_for_void
- avoid_returning_this
- avoid_setters_without_getters
Expand All @@ -61,15 +58,20 @@ linter:
- cascade_invocations
- cast_nullable_to_non_nullable
- close_sinks
- collection_methods_unrelated_type
- combinators_ordering
- comment_references
- conditional_uri_does_not_exist
- constant_identifier_names
- control_flow_in_finally
- curly_braces_in_flow_control_structures
- dangling_library_doc_comments
- depend_on_referenced_packages
- deprecated_consistency
- deprecated_member_use_from_same_package
- diagnostic_describe_all_properties
- directives_ordering
- discarded_futures
- do_not_use_environment
- empty_catches
- empty_constructor_bodies
Expand All @@ -80,24 +82,29 @@ linter:
- flutter_style_todos
- hash_and_equals
- implementation_imports
- invariant_booleans
- iterable_contains_unrelated_type
- implicit_call_tearoffs
- implicit_reopen
- invalid_case_patterns
- join_return_with_assignment
- leading_newlines_in_multiline_strings
- library_annotations
- library_names
- library_prefixes
- library_private_types_in_public_api
- lines_longer_than_80_chars
- list_remove_unrelated_type
- literal_only_boolean_expressions
- matching_super_parameters
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- no_default_cases
- no_duplicate_case_values
- no_leading_underscores_for_library_prefixes
- no_leading_underscores_for_local_identifiers
- no_literal_bool_comparisons
- no_logic_in_create_state
- no_runtimeType_toString
- no_self_assignments
- no_wildcard_variable_uses
- non_constant_identifier_names
- noop_primitive_operations
- null_check_on_nullable_type_parameter
Expand All @@ -122,7 +129,6 @@ linter:
- prefer_constructors_over_static_methods
- prefer_contains
- prefer_double_quotes
- prefer_equal_for_default_values
- prefer_expression_function_bodies
- prefer_final_fields
- prefer_final_in_for_each
Expand Down Expand Up @@ -167,17 +173,21 @@ linter:
- tighten_type_of_initializing_formals
- type_annotate_public_apis
- type_init_formals
- type_literal_in_constant_pattern
- unawaited_futures
- unnecessary_await_in_return
- unnecessary_brace_in_string_interps
- unnecessary_breaks
- unnecessary_const
- unnecessary_constructor_name
- unnecessary_final
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_late
- unnecessary_library_directive
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_null_aware_operator_on_extension_on_nullable
- unnecessary_null_checks
- unnecessary_null_in_if_null_operators
- unnecessary_nullable_for_final_variable_declarations
Expand All @@ -188,10 +198,14 @@ linter:
- unnecessary_string_escapes
- unnecessary_string_interpolations
- unnecessary_this
- unnecessary_to_list_in_spreads
- unreachable_from_main
- unrelated_type_equality_checks
- unsafe_html
- use_build_context_synchronously
- use_colored_box
- use_decorated_box
- use_enums
- use_full_hex_values_for_flutter_colors
- use_function_type_syntax_for_parameters
- use_if_null_to_convert_nulls_to_bools
Expand All @@ -203,6 +217,8 @@ linter:
- use_rethrow_when_possible
- use_setters_to_change_properties
- use_string_buffers
- use_string_in_part_of_directives
- use_super_parameters
- use_test_throws_matchers
- use_to_and_as_if_applicable
- valid_regexps
Expand Down
55 changes: 36 additions & 19 deletions lib/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Evaluate the rules using the catalogue: https://dart-lang.github.io/linter/lints/
analyzer:
# Both of the strong-mode lints are really impactful throughout the project, and both of these might be rules that you
# may want to modify to `true` if they are too severe.
# All language lints are really impactful throughout the project, and these might be rules that you may want to modify
# to `false` if they are too severe.
#
# We think that both of these rules are usually enforced in scenarios where we are manipulating untyped field/data,
# meaning: the `dynamic` type - this means a very high opportunity to access non-existing properties and have errors
# like NoSuchMethod, thrown while in runtime. If there is a need to use dynamic type, it would be done by explicitly
# declaring such fields as `dynamic`.
strong-mode:
implicit-casts: false
implicit-dynamic: false
# These rules are usually enforced in scenarios where we are manipulating untyped field/data, meaning: the `dynamic`
# type - so, a very high opportunity to access non-existing properties and have errors like NoSuchMethod thrown in
# runtime. If there is a need to use dynamic type, it would be done by explicitly declaring such fields as `dynamic`.
language:
strict-casts: true
strict-inference: true
strict-raw-types: true

errors:
# The benefits of being able to inject environment variable are substantial. This should be used with care and
Expand All @@ -24,7 +24,6 @@ linter:
- always_declare_return_types
- always_put_control_body_on_new_line
- always_put_required_named_parameters_first
- always_require_non_null_named_parameters
# Most of the times, letting Dart infer is just as readable and, consequently, way less verbose. There are a bunch
# of cases (like frequently with generics) that we don't need to specify a particular type, but we would still be
# forced anyways (and more often than not, they are really verbose). Dart design also corroborates with this idea:
Expand Down Expand Up @@ -77,11 +76,6 @@ linter:
- avoid_relative_lib_imports
- avoid_renaming_method_parameters
- avoid_return_types_on_setters
# This made sense in a scenario where NNBD didn't exist. Now that we can deal with optional types, expecting an
# optional return from primitive types are completly acceptable.
# - avoid_returning_null
# Not applicable with NNBD.
# - avoid_returning_null_for_future
# Not applicable with NNBD.
# - avoid_returning_null_for_void
- avoid_returning_this
Expand All @@ -106,16 +100,22 @@ linter:
- cast_nullable_to_non_nullable
# Not working as inteded but useful. Use when this is solved: https://github.com/dart-lang/linter/issues/1381
# - close_sinks
- collection_methods_unrelated_type
- combinators_ordering
- comment_references
- conditional_uri_does_not_exist
- constant_identifier_names
- control_flow_in_finally
- curly_braces_in_flow_control_structures
- dangling_library_doc_comments
- depend_on_referenced_packages
- deprecated_consistency
- deprecated_member_use_from_same_package
# TODO: Not sure, as I have never used this before.
# - diagnostic_describe_all_properties
- directives_ordering
# While there are plausible scenarios, such as fire and forget, they are much more unlikely than programming errors.
- discarded_futures
- do_not_use_environment
- empty_catches
- empty_constructor_bodies
Expand All @@ -126,19 +126,24 @@ linter:
- flutter_style_todos
- hash_and_equals
- implementation_imports
- invariant_booleans
- iterable_contains_unrelated_type
- implicit_call_tearoffs
# It adds too much boilerplate for very specific scenarios, such as libraries that are exposed to another bunch of
# plugins or libraries. When used in a "controlled" environment, it'll probably just add more boilerplate code than
# helping it being explicit "reopen".
# - implicit_reopen
- invalid_case_patterns
- join_return_with_assignment
- leading_newlines_in_multiline_strings
- library_annotations
- library_names
- library_prefixes
- library_private_types_in_public_api
# Possibly one of the most discussed topics in code-styling. We prefer to keep it at 120, due to several reasons.
# This is a totally biased opinion and all three 80, 100 and 120 line lenghts have good/valid points. Although,
# when exceeding 120, it becomes really hard to read.
# - lines_longer_than_80_chars
- list_remove_unrelated_type
- literal_only_boolean_expressions
- matching_super_parameters
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
# There are a lot of scenarios where you want to switch over a particular cases that share something in common, and
Expand All @@ -147,8 +152,11 @@ linter:
- no_duplicate_case_values
- no_leading_underscores_for_library_prefixes
- no_leading_underscores_for_local_identifiers
- no_literal_bool_comparisons
- no_logic_in_create_state
- no_runtimeType_toString
- no_self_assignments
- no_wildcard_variable_uses
- non_constant_identifier_names
- noop_primitive_operations
# TODO: Not sure, couldn't quite understand why it's better to type cast to a non-nullable type instead of using
Expand Down Expand Up @@ -202,7 +210,6 @@ linter:
# normally come with single quotes, and this is enough of a reason to use it, as there is no other clear distinction
# between single/double quotes.
# - prefer_double_quotes
- prefer_equal_for_default_values
# We turned this off due to the fact that we don't want to force the use of this arrow-syntax return when we have a
# multiline return.
#
Expand Down Expand Up @@ -264,9 +271,11 @@ linter:
- tighten_type_of_initializing_formals
- type_annotate_public_apis
- type_init_formals
- type_literal_in_constant_pattern
- unawaited_futures
- unnecessary_await_in_return
- unnecessary_brace_in_string_interps
- unnecessary_breaks
- unnecessary_const
- unnecessary_constructor_name
# While var keyword is indeed shorter than final, when we allow this approach as our default behavior, we could
Expand All @@ -275,8 +284,10 @@ linter:
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_late
- unnecessary_library_directive
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_null_aware_operator_on_extension_on_nullable
- unnecessary_null_checks
- unnecessary_null_in_if_null_operators
- unnecessary_nullable_for_final_variable_declarations
Expand All @@ -287,10 +298,14 @@ linter:
- unnecessary_string_escapes
- unnecessary_string_interpolations
- unnecessary_this
- unnecessary_to_list_in_spreads
- unreachable_from_main
- unrelated_type_equality_checks
- unsafe_html
- use_build_context_synchronously
- use_colored_box
- use_decorated_box
- use_enums
- use_full_hex_values_for_flutter_colors
- use_function_type_syntax_for_parameters
- use_if_null_to_convert_nulls_to_bools
Expand All @@ -306,6 +321,8 @@ linter:
- use_rethrow_when_possible
- use_setters_to_change_properties
- use_string_buffers
- use_string_in_part_of_directives
- use_super_parameters
- use_test_throws_matchers
- use_to_and_as_if_applicable
- valid_regexps
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: strict
version: 1.4.0
version: 2.0.0
description: A heavily opinionated analysis_options for Dart/Flutter projects with strict - but justified - lint rules
repository: https://github.com/olmps/strict
issue_tracker: https://github.com/olmps/strict/issues

environment:
sdk: ">=2.16.1 <3.0.0"
sdk: ">=3.1.0 <4.0.0"

0 comments on commit 45f3973

Please sign in to comment.