Skip to content

Commit

Permalink
Lints setup (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirland authored Nov 8, 2022
1 parent 5eeeb03 commit b670486
Show file tree
Hide file tree
Showing 42 changed files with 438 additions and 363 deletions.
92 changes: 80 additions & 12 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,95 @@

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:pedantic/analysis_options.yaml
include: package:flutter_lints/flutter.yaml

linter:
rules:
- always_declare_return_types
- always_put_required_named_parameters_first
- always_use_package_imports
- camel_case_types
- library_names
- annotate_overrides
- avoid_bool_literals_in_conditional_expressions
- avoid_catching_errors
- avoid_empty_else
- avoid_returning_null
- avoid_multiple_declarations_per_line
- avoid_null_checks_in_equality_operators
- avoid_print
- 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_shadowing_type_parameters
- avoid_single_cascade_in_expression_statements
- avoid_type_to_string
- avoid_types_as_parameter_names
- avoid_unnecessary_containers
- avoid_void_async
- camel_case_extensions
- camel_case_types
- cancel_subscriptions
- cascade_invocations
- cast_nullable_to_non_nullable
- close_sinks
- constant_identifier_names
- curly_braces_in_flow_control_structures
- empty_constructor_bodies
- empty_statements
- unnecessary_parenthesis
- unnecessary_this
- unnecessary_const
- unnecessary_overrides
- unnecessary_brace_in_string_interps
- eol_at_end_of_file
- exhaustive_cases
- file_names
- hash_and_equals
- iterable_contains_unrelated_type
- library_names
- lines_longer_than_80_chars
- curly_braces_in_flow_control_structures
- list_remove_unrelated_type
- literal_only_boolean_expressions
- missing_whitespace_between_adjacent_strings
- no_default_cases
- no_duplicate_case_values
- no_leading_underscores_for_local_identifiers
- no_runtimeType_toString
- non_constant_identifier_names
- only_throw_errors
- prefer_adjacent_string_concatenation
- prefer_asserts_with_message
- prefer_const_constructors_in_immutables
- prefer_const_declarations
- prefer_contains
- prefer_expression_function_bodies
- prefer_final_in_for_each
- prefer_final_locals
- prefer_if_null_operators
- prefer_initializing_formals
- prefer_is_empty
- prefer_is_not_empty
- prefer_is_not_operator
- prefer_iterable_whereType
- prefer_void_to_null
- recursive_getters
- require_trailing_commas
- slash_for_doc_comments
- unawaited_futures
- unnecessary_await_in_return
- unnecessary_brace_in_string_interps
- unnecessary_const
- unnecessary_late
- unnecessary_new
- unnecessary_nullable_for_final_variable_declarations
- unnecessary_overrides
- unnecessary_parenthesis
- unnecessary_raw_strings
- unnecessary_statements
- unnecessary_string_interpolations
- unnecessary_this
- unrelated_type_equality_checks
- use_build_context_synchronously
- use_if_null_to_convert_nulls_to_bools
- use_key_in_widget_constructors
- valid_regexps

dart_code_metrics:
anti-patterns:
Expand Down Expand Up @@ -65,7 +134,6 @@ analyzer:
- '**/*.g.dart'
- '**/*.gen.dart'
- '**/*.gr.dart'


- 'lib/generated_plugin_registrant.dart'
errors:
invalid_annotation_target: ignore
4 changes: 3 additions & 1 deletion lib/core/common/config.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: constant_identifier_names

import 'dart:async';

import 'package:flutter_template/core/common/extension/string_extensions.dart';
Expand All @@ -23,7 +25,7 @@ extension EnviromentPath on Environments {
}
}

String get path => 'assets/environments/' + fileName;
String get path => 'assets/environments/$fileName';
}

abstract class Config {
Expand Down
16 changes: 8 additions & 8 deletions lib/core/common/extension/string_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ extension StringExtensions on String {
bool get isNumber => contains(RegExp(r'^[0-9]+$'));

String get camelCaseToSnakeCase {
var sb = StringBuffer();
final sb = StringBuffer();
var first = true;
runes.forEach((int rune) {
var char = String.fromCharCode(rune);
for (final rune in runes) {
final char = String.fromCharCode(rune);
if (char.isUpperCase && !first) {
if (char != '_') {
sb.write('_');
Expand All @@ -17,23 +17,23 @@ extension StringExtensions on String {
first = false;
sb.write(char.toLowerCase());
}
});
}
return sb.toString();
}

String get addUnderscoreBeforeNumbers {
var sb = StringBuffer();
final sb = StringBuffer();
var first = true;
var prev = '';
runes.forEach((int rune) {
var char = String.fromCharCode(rune);
for (final rune in runes) {
final char = String.fromCharCode(rune);
if (char.isNumber && !first && !prev.isNumber) {
sb.write('_');
}
first = false;
sb.write(char);
prev = char;
});
}
return sb.toString();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/core/common/helper/enum_helpers.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:collection/collection.dart';
import 'package:dartx/dartx.dart';

T? enumFromString<T>(Iterable<T> values, String value) =>
values.firstWhereOrNull((type) => type.toString().split('.').last == value);
values.firstOrNullWhere((type) => type.toString().split('.').last == value);
12 changes: 6 additions & 6 deletions lib/core/common/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class _CrashReportWrappedPrinter extends LogPrinter {
StackTrace _currentStacktrace() {
// Filter: FirebaseCrashlytics.record, _CrashReportWrappedPrinter
// Logger.log, Logger.e
var trace = Trace.current(4);
var frames = trace.frames;
final trace = Trace.current(4);
final frames = trace.frames;
final newFrames = frames.map(
(frame) => Frame(
frame.uri,
Expand Down Expand Up @@ -107,15 +107,15 @@ class _PrintableTrace extends Trace {
String toString() {
var i = 1;
return frames.map((frame) {
var number = '#${i++}'.padRight(8);
var member = frame.member!
final number = '#${i++}'.padRight(8);
final member = frame.member!
.replaceAllMapped(
RegExp(r'[^.]+\.<async>'),
(match) => '${match[1]}.<${match[1]}_async_body>',
)
.replaceAll('<fn>', '<anonymous closure>');
var line = frame.line ?? 0;
var column = frame.column ?? 0;
final line = frame.line ?? 0;
final column = frame.column ?? 0;
return '$number$member (${frame.uri}:$line:$column)\n';
}).join();
}
Expand Down
7 changes: 3 additions & 4 deletions lib/core/common/network_exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
part 'network_exceptions.freezed.dart';

@freezed
class NetworkException extends Object with _$NetworkException {
class NetworkException with _$NetworkException implements Exception {
const factory NetworkException.unauthorizedRequest(body) =
UnauthorizedRequest;

Expand Down Expand Up @@ -54,9 +54,8 @@ class NetworkException extends Object with _$NetworkException {
case 503:
return const NetworkException.serviceUnavailable();
default:
var responseCode = statusCode;
return NetworkException.defaultError(
responseCode,
statusCode,
'Received invalid status code. body: $body',
);
}
Expand All @@ -73,7 +72,7 @@ class NetworkException extends Object with _$NetworkException {
case DioErrorType.other:
case DioErrorType.receiveTimeout:
case DioErrorType.sendTimeout:
networkExceptions = NetworkException.noInternetConnection();
networkExceptions = const NetworkException.noInternetConnection();
break;
case DioErrorType.response:
networkExceptions = NetworkException.handleResponse(
Expand Down
6 changes: 3 additions & 3 deletions lib/core/common/result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class Result<S> extends Equatable {

static Result<S> success<S>(S data) => _SuccessResult(data);

Result._();
const Result._();

factory Result(S Function() computation) {
try {
Expand Down Expand Up @@ -85,7 +85,7 @@ abstract class Result<S> extends Equatable {
class _SuccessResult<S> extends Result<S> {
final S _value;

_SuccessResult(this._value) : super._();
const _SuccessResult(this._value) : super._();

@override
_SuccessResult<T> either<T>(
Expand Down Expand Up @@ -114,7 +114,7 @@ class _SuccessResult<S> extends Result<S> {
class _FailureResult<S> extends Result<S> {
final Object _value;

_FailureResult(this._value) : super._();
const _FailureResult(this._value) : super._();

@override
_FailureResult<T> either<T>(
Expand Down
2 changes: 1 addition & 1 deletion lib/core/common/store/secure_storage_cached_source.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async';

import 'package:flutter/widgets.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:meta/meta.dart';
import 'package:stock/stock.dart';

class SecuredStorageSourceOfTruth extends CachedSourceOfTruth<String, String> {
Expand Down
7 changes: 4 additions & 3 deletions lib/core/di/di_repository_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class RepositoryDiModule {
factory RepositoryDiModule() => _instance;

void setupModule(GetIt locator) {
locator._setupProvidersAndUtils();
locator._setupSources();
locator._setupRepositories();
locator
.._setupProvidersAndUtils()
.._setupSources()
.._setupRepositories();
}
}

Expand Down
36 changes: 18 additions & 18 deletions lib/core/model/serializer/project_serializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import 'package:stock/stock.dart';

class ProjectStockTypeMapper extends StockTypeMapper<ProjectDbEntity, Project> {
@override
ProjectDbEntity fromOutput(Project commonModel) => ProjectDbEntity(
id: commonModel.id,
description: commonModel.description,
name: commonModel.name,
url: commonModel.url,
language: commonModel.language,
imageUrl: commonModel.imageUrl,
ProjectDbEntity fromOutput(Project value) => ProjectDbEntity(
id: value.id,
description: value.description,
name: value.name,
url: value.url,
language: value.language,
imageUrl: value.imageUrl,
);

@override
Project fromInput(ProjectDbEntity serviceModel) => Project(
id: serviceModel.id,
description: serviceModel.description,
name: serviceModel.name,
url: serviceModel.url,
language: serviceModel.language,
imageUrl: serviceModel.imageUrl,
Project fromInput(ProjectDbEntity value) => Project(
id: value.id,
description: value.description,
name: value.name,
url: value.url,
language: value.language,
imageUrl: value.imageUrl,
);
}

Expand All @@ -29,10 +29,10 @@ class ProjectListStockTypeMapper
final _projectSerializer = ProjectStockTypeMapper();

@override
List<Project> fromInput(List<ProjectDbEntity> databaseModel) =>
databaseModel.map(_projectSerializer.fromInput).toList();
List<Project> fromInput(List<ProjectDbEntity> value) =>
value.map(_projectSerializer.fromInput).toList();

@override
List<ProjectDbEntity> fromOutput(List<Project> commonModel) =>
commonModel.map(_projectSerializer.fromOutput).toList();
List<ProjectDbEntity> fromOutput(List<Project> value) =>
value.map(_projectSerializer.fromOutput).toList();
}
5 changes: 4 additions & 1 deletion lib/core/model/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ part 'user.g.dart';
@freezed
class User with _$User {
@JsonSerializable()
factory User({String? name, required String email}) = _User;
factory User({
required String email,
String? name,
}) = _User;

factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
}
Loading

0 comments on commit b670486

Please sign in to comment.