Skip to content

Commit

Permalink
Use stricter analysis options
Browse files Browse the repository at this point in the history
  • Loading branch information
tp committed Nov 10, 2024
1 parent 0603dc9 commit cf0fe66
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 69 deletions.
122 changes: 119 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,120 @@
include: package:flutter_lints/flutter.yaml
include: package:flutter_lints/flutter.yaml # https://github.com/flutter/packages/blob/main/packages/flutter_lints/lib/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
analyzer:
language:
strict-casts: true
strict-raw-types: true

errors:
always_declare_return_types: error
always_put_required_named_parameters_first: error
always_require_non_null_named_parameters: error
# Disabled due to the usage in "hand-rolled" from JSON, will be removed once we can make use of the JSON macro in tests & the example
argument_type_not_assignable: ignore
avoid_bool_literals_in_conditional_expressions: error
avoid_catching_errors: error
avoid_double_and_int_checks: error
avoid_empty_else: error
avoid_equals_and_hash_code_on_mutable_classes: error
avoid_escaping_inner_quotes: error
avoid_field_initializers_in_const_classes: error
avoid_function_literals_in_foreach_calls: error
avoid_init_to_null: error
avoid_js_rounded_ints: error
avoid_null_checks_in_equality_operators: error
avoid_returning_null_for_future: error
avoid_returning_null_for_void: error
avoid_returning_this: error
avoid_setters_without_getters: error
avoid_shadowing_type_parameters: error
avoid_single_cascade_in_expression_statements: error
avoid_slow_async_io: error
avoid_types_as_parameter_names: error
avoid_void_async: error
avoid_web_libraries_in_flutter: error
await_only_futures: error
camel_case_extensions: error
camel_case_types: error
cancel_subscriptions: error
close_sinks: error
control_flow_in_finally: error
curly_braces_in_flow_control_structures: error
do_not_use_environment: error
empty_catches: error
empty_constructor_bodies: error
empty_statements: error
exhaustive_cases: error
file_names: error
flutter_style_todos: error
hash_and_equals: error
implementation_imports: error
invariant_booleans: error
iterable_contains_unrelated_type: error
join_return_with_assignment: error
leading_newlines_in_multiline_strings: error
library_names: error
library_prefixes: error
list_remove_unrelated_type: error
missing_required_param: error
missing_return: error
unused_import: error

linter:
rules:
- always_declare_return_types
- avoid_bool_literals_in_conditional_expressions
- avoid_catching_errors
- avoid_double_and_int_checks
- avoid_dynamic_calls
- avoid_empty_else
- avoid_equals_and_hash_code_on_mutable_classes
- avoid_escaping_inner_quotes
- avoid_field_initializers_in_const_classes
- avoid_init_to_null
- avoid_js_rounded_ints
- avoid_null_checks_in_equality_operators
- avoid_returning_null_for_void
- avoid_returning_this
- avoid_setters_without_getters
- avoid_shadowing_type_parameters
- avoid_single_cascade_in_expression_statements
- avoid_slow_async_io
- avoid_type_to_string
- avoid_types_as_parameter_names
- avoid_void_async
- avoid_web_libraries_in_flutter
- await_only_futures
- camel_case_extensions
- camel_case_types
- cancel_subscriptions
- close_sinks
- collection_methods_unrelated_type
- control_flow_in_finally
- curly_braces_in_flow_control_structures
- depend_on_referenced_packages
- directives_ordering
- do_not_use_environment
- empty_catches
- empty_constructor_bodies
- empty_statements
- exhaustive_cases
- file_names
- flutter_style_todos
- hash_and_equals
- implementation_imports
- join_return_with_assignment
- leading_newlines_in_multiline_strings
- library_names
- library_prefixes
- prefer_final_fields
- prefer_final_in_for_each
- prefer_final_locals
- prefer_iterable_whereType
- prefer_single_quotes
- require_trailing_commas
- sort_constructors_first
- test_types_in_equals
- type_annotate_public_apis
- unawaited_futures
- unrelated_type_equality_checks
- use_super_parameters
6 changes: 3 additions & 3 deletions lib/src/index_columns.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ part of 'index_entity_store.dart';
/// The collection of indexed columns for a given [IndexedEntityStore]
class IndexColumns {
IndexColumns._(
Map<String, IndexColumn> indexColumns,
Map<String, IndexColumn<dynamic, dynamic>> indexColumns,
) : _indexColumns = Map.unmodifiable(indexColumns);

final Map<String, IndexColumn> _indexColumns;
final Map<String, IndexColumn<dynamic, dynamic>> _indexColumns;

IndexColumn operator [](String columnName) {
IndexColumn<dynamic, dynamic> operator [](String columnName) {
final col = _indexColumns[columnName];

if (col == null) {
Expand Down
23 changes: 13 additions & 10 deletions lib/src/index_entity_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class IndexedEntityStore<T, K> {

String get _entityKey => _connector.entityKey;

final Map<K, List<QueryResultMapping>> _singleEntityResults = {};
final Map<K, List<QueryResultMapping<dynamic>>> _singleEntityResults = {};

final List<QueryResultMapping> _entityResults = [];
final List<QueryResultMapping<dynamic>> _entityResults = [];

@visibleForTesting
int get subscriptionCount {
Expand Down Expand Up @@ -187,7 +187,7 @@ class IndexedEntityStore<T, K> {
if (whereClause != null) ' AND `entity`.`key` IN ( ${whereClause.$1} ) ',
if (orderBy != null)
'AND `index`.`field` = ? ORDER BY `index`.`value` ${orderBy.$2 == SortOrder.asc ? 'ASC' : 'DESC'}',
if (limit != null) ' LIMIT ?'
if (limit != null) ' LIMIT ?',
].join();
final values = [
_entityKey,
Expand Down Expand Up @@ -294,11 +294,13 @@ class IndexedEntityStore<T, K> {
// TODO(tp): QueryBuilder? where,
final bool? all,
}) {
assert(entity != null ||
entities != null ||
key != null ||
keys != null ||
all != null);
assert(
entity != null ||
entities != null ||
key != null ||
keys != null ||
all != null,
);
assert(
all == null ||
(entity == null && entities == null && key == null && keys == null),
Expand All @@ -325,7 +327,7 @@ class IndexedEntityStore<T, K> {

_handleUpdate(
{
for (final row in result) row['key']!,
for (final row in result) row['key']! as K,
},
);
}
Expand Down Expand Up @@ -418,7 +420,8 @@ class IndexedEntityStore<T, K> {
if (newValue.dbValues.length ==
mapping.$2._value.value.dbValues.length &&
newValue.dbValues.indexed.every(
(e) => mapping.$2._value.value.dbValues[e.$1] == e.$2)) {
(e) => mapping.$2._value.value.dbValues[e.$1] == e.$2,
)) {
continue; // values already match
}

Expand Down
12 changes: 6 additions & 6 deletions lib/src/indexed_entity_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import 'package:indexed_entity_store/indexed_entity_store.dart';
import 'package:sqlite3/sqlite3.dart';

class IndexedEntityDabase {
final Database _database;
factory IndexedEntityDabase.open(String path) {
return IndexedEntityDabase._(path);
}

IndexedEntityDabase._(String path) : _database = sqlite3.open(path) {
final res = _database.select(
Expand Down Expand Up @@ -36,6 +38,8 @@ class IndexedEntityDabase {
);
}

final Database _database;

void _initialDBSetup() {
_database.execute('PRAGMA foreign_keys = ON');

Expand Down Expand Up @@ -95,10 +99,6 @@ class IndexedEntityDabase {
);
}

factory IndexedEntityDabase.open(String path) {
return IndexedEntityDabase._(path);
}

IndexedEntityStore<T, K> entityStore<T, K, S>(
IndexedEntityConnector<T, K, S> connector,
) {
Expand All @@ -110,7 +110,7 @@ class IndexedEntityDabase {
);
}

dispose() {
void dispose() {
_database.dispose();
}
}
16 changes: 8 additions & 8 deletions lib/src/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class _AndQuery extends Query {
final Query second;

@override
(String, List) _entityKeysQuery() {
(String, List<dynamic>) _entityKeysQuery() {
return (
' ${first._entityKeysQuery().$1} INTERSECT ${second._entityKeysQuery().$1} ',
[...first._entityKeysQuery().$2, ...second._entityKeysQuery().$2],
Expand All @@ -36,7 +36,7 @@ class _OrQuery extends Query {
final Query second;

@override
(String, List) _entityKeysQuery() {
(String, List<dynamic>) _entityKeysQuery() {
return (
' ${first._entityKeysQuery().$1} UNION ${second._entityKeysQuery().$1} ',
[...first._entityKeysQuery().$2, ...second._entityKeysQuery().$2],
Expand All @@ -52,7 +52,7 @@ class _EqualQuery extends Query {
final dynamic value;

@override
(String, List) _entityKeysQuery() {
(String, List<dynamic>) _entityKeysQuery() {
if (this.value == null) {
return (
'SELECT `entity` FROM `index` WHERE `type` = ? AND `field` = ? AND `value` IS NULL',
Expand Down Expand Up @@ -85,7 +85,7 @@ class _GreaterThanQuery extends Query {
final dynamic value;

@override
(String, List) _entityKeysQuery() {
(String, List<dynamic>) _entityKeysQuery() {
final value = this.value is DateTime
? (this.value as DateTime).microsecondsSinceEpoch
: this.value;
Expand All @@ -111,7 +111,7 @@ class _LessThanQuery extends Query {
final dynamic value;

@override
(String, List) _entityKeysQuery() {
(String, List<dynamic>) _entityKeysQuery() {
final value = this.value is DateTime
? (this.value as DateTime).microsecondsSinceEpoch
: this.value;
Expand All @@ -137,10 +137,10 @@ class _ContainsStringQuery extends Query {
final bool caseInsensitive;

@override
(String, List) _entityKeysQuery() {
(String, List<dynamic>) _entityKeysQuery() {
if (caseInsensitive) {
return (
"SELECT `entity` FROM `index` WHERE `type` = ? AND `field` = ? AND `value` LIKE ?",
'SELECT `entity` FROM `index` WHERE `type` = ? AND `field` = ? AND `value` LIKE ?',
[
entity,
field,
Expand All @@ -150,7 +150,7 @@ class _ContainsStringQuery extends Query {
}

return (
"SELECT `entity` FROM `index` WHERE `type` = ? AND `field` = ? AND `value` GLOB ?",
'SELECT `entity` FROM `index` WHERE `type` = ? AND `field` = ? AND `value` GLOB ?',
[
entity,
field,
Expand Down
Loading

0 comments on commit cf0fe66

Please sign in to comment.