Skip to content

Commit

Permalink
refactor: update linting rules (#80)
Browse files Browse the repository at this point in the history
Closes #79
  • Loading branch information
rafamizes authored Aug 24, 2024
1 parent a4154cd commit 174c6bf
Show file tree
Hide file tree
Showing 31 changed files with 212 additions and 178 deletions.
23 changes: 9 additions & 14 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
include: package:lint/analysis_options_package.yaml
include: package:lint/package.yaml

analyzer:
strong-mode:
# A value of false ensures that the type inference engine never implicitly casts
# from dynamic to a more specific type.
implicit-casts: false
# A value of false ensures that the type inference engine never chooses the
# dynamic type when it can’t determine a static type.
implicit-dynamic: false
exclude:
- '**.freezed.dart'
- '**.g.dart'
linter:
rules:
# Make constructors the first thing in every class
sort_unnamed_constructors_first: true
sort_constructors_first: true
avoid_catches_without_on_clauses: true
avoid_equals_and_hash_code_on_mutable_classes: true
cancel_subscriptions: true
# Good packages document everything
public_member_api_docs: true
use_key_in_widget_constructors: true
always_declare_return_types: true
cancel_subscriptions: true
close_sinks: true
only_throw_errors: true
package_api_docs: true
always_use_package_imports: false
17 changes: 11 additions & 6 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
include: package:lint/analysis_options_package.yaml
include: package:lint/strict.yaml

analyzer:
exclude:
- '**.freezed.dart'
- '**.g.dart'
linter:
rules:
# Make constructors the first thing in every class
sort_unnamed_constructors_first: true
sort_constructors_first: true
# Good packages document everything
public_member_api_docs: true
# It's a good practice to expose the ability to provide a key when creating public widgets.
use_key_in_widget_constructors: true

avoid_catches_without_on_clauses: true
avoid_equals_and_hash_code_on_mutable_classes: true
cancel_subscriptions: true
only_throw_errors: true
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void main() {
/// Demo purposes form app widget.
class _DemoApp extends StatelessWidget {
/// Ctor.
const _DemoApp({Key? key}) : super(key: key);
const _DemoApp();

static final _labelStyle = TextStyle(color: const Grey.veryDark().color);

Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ packages:
dependency: "direct dev"
description:
name: lint
sha256: "7e9eb7b748d782921353d757334705c45a9cc37b5c694054856ed77a0a7df9fd"
sha256: d758a5211fce7fd3f5e316f804daefecdc34c7e53559716125e6da7388ae8565
url: "https://pub.dev"
source: hosted
version: "1.8.1"
version: "2.3.0"
mask_text_input_formatter:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
lint: ^1.7.1
lint: ^2.3.0

flutter:
uses-material-design: true
14 changes: 7 additions & 7 deletions lib/src/brazil/br_mobile_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class BrMobileField extends StatelessWidget {
EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
bool enableInteractiveSelection = true,
AutovalidateMode? autovalidateMode,
Key? key,
}) : _toBrMobileField = ((context) {
super.key,
}) : _toBrMobileField = ((context) {
final FormFieldSetter<String>? onSavedStrip = onSaved == null
? null
: !strip
Expand All @@ -78,7 +78,10 @@ class BrMobileField extends StatelessWidget {
mask.replaceAll(RegExp(r'[-()\s]'), ''),
);
return BasicTextField(
validator: Pair.str(BrMobile(mal: malformed), validator ?? _dummy),
validator: Pair.str(
BrMobile(mal: malformed).call,
validator ?? const Ok().call,
).call,
blank: blank,
trim: trim,
keyboardType: TextInputType.number,
Expand Down Expand Up @@ -109,13 +112,10 @@ class BrMobileField extends StatelessWidget {
enableInteractiveSelection: enableInteractiveSelection,
autovalidateMode: autovalidateMode,
);
}),
super(key: key);
});

final ToBasicTextField _toBrMobileField;

static String? _dummy(String? input) => null;

/// Builds a [BasicTextField] suitable for Brazilian mobile numbers.
@override
BasicTextField build(BuildContext context) => _toBrMobileField(context);
Expand Down
14 changes: 7 additions & 7 deletions lib/src/brazil/br_phone_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class BrPhoneField extends StatelessWidget {
EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
bool enableInteractiveSelection = true,
AutovalidateMode? autovalidateMode,
Key? key,
}) : _toBrPhoneField = ((context) {
super.key,
}) : _toBrPhoneField = ((context) {
final FormFieldSetter<String>? onSavedStrip = onSaved == null
? null
: !strip
Expand All @@ -80,7 +80,10 @@ class BrPhoneField extends StatelessWidget {
mask.replaceAll(RegExp(r'[-()\s]'), ''),
);
return BasicTextField(
validator: Pair.str(BrPhone(mal: malformed), validator ?? _dummy),
validator: Pair.str(
BrPhone(mal: malformed).call,
validator ?? const Ok().call,
).call,
blank: blank,
trim: trim,
keyboardType: TextInputType.number,
Expand Down Expand Up @@ -111,13 +114,10 @@ class BrPhoneField extends StatelessWidget {
enableInteractiveSelection: enableInteractiveSelection,
autovalidateMode: autovalidateMode,
);
}),
super(key: key);
});

final ToBasicTextField _toBrPhoneField;

static String? _dummy(String? input) => null;

/// Builds a [BasicTextField] suitable for Brazilian phone numbers.
@override
BasicTextField build(BuildContext context) => _toBrPhoneField(context);
Expand Down
13 changes: 6 additions & 7 deletions lib/src/brazil/cep_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class CepField extends StatelessWidget {
EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
bool enableInteractiveSelection = true,
AutovalidateMode? autovalidateMode,
Key? key,
}) : _toCepField = ((context) {
super.key,
}) : _toCepField = ((context) {
final FormFieldSetter<String>? onSavedStrip = onSaved == null
? null
: !strip
Expand All @@ -69,7 +69,9 @@ class CepField extends StatelessWidget {
: (String mask) =>
onFieldSubmitted(mask.replaceAll('-', ''));
return BasicTextField(
validator: Pair.str(Cep(mal: malformed), validator ?? _dummy),
validator:
Pair.str(Cep(mal: malformed).call, validator ?? const Ok().call)
.call,
blank: blank,
trim: trim,
keyboardType: TextInputType.number,
Expand Down Expand Up @@ -100,13 +102,10 @@ class CepField extends StatelessWidget {
enableInteractiveSelection: enableInteractiveSelection,
autovalidateMode: autovalidateMode,
);
}),
super(key: key);
});

final ToBasicTextField _toCepField;

static String? _dummy(String? input) => null;

/// Builds a [BasicTextField] suitable for CEP values.
@override
BasicTextField build(BuildContext context) => _toCepField(context);
Expand Down
14 changes: 7 additions & 7 deletions lib/src/brazil/cnpj_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class CnpjField extends StatelessWidget {
EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
bool enableInteractiveSelection = true,
AutovalidateMode? autovalidateMode,
Key? key,
}) : _toCnpjField = ((context) {
super.key,
}) : _toCnpjField = ((context) {
final FormFieldSetter<String>? onSavedStrip = onSaved == null
? null
: !strip
Expand All @@ -69,7 +69,10 @@ class CnpjField extends StatelessWidget {
: (String mask) =>
onFieldSubmitted(mask.replaceAll(RegExp('[-/.]'), ''));
return BasicTextField(
validator: Pair.str(Cnpj(mal: malformed), validator ?? _dummy),
validator: Pair.str(
Cnpj(mal: malformed).call,
validator ?? const Ok().call,
).call,
blank: blank,
trim: trim,
keyboardType: TextInputType.number,
Expand Down Expand Up @@ -100,13 +103,10 @@ class CnpjField extends StatelessWidget {
enableInteractiveSelection: enableInteractiveSelection,
autovalidateMode: autovalidateMode,
);
}),
super(key: key);
});

final ToBasicTextField _toCnpjField;

static String? _dummy(String? input) => null;

/// Builds a [BasicTextField] suitable for CNPJ values.
@override
BasicTextField build(BuildContext context) => _toCnpjField(context);
Expand Down
13 changes: 6 additions & 7 deletions lib/src/brazil/cpf_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class CpfField extends StatelessWidget {
EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
bool enableInteractiveSelection = true,
AutovalidateMode? autovalidateMode,
Key? key,
}) : _toCpfField = ((context) {
super.key,
}) : _toCpfField = ((context) {
final FormFieldSetter<String>? onSavedStrip = onSaved == null
? null
: !strip
Expand All @@ -69,7 +69,9 @@ class CpfField extends StatelessWidget {
: (String mask) =>
onFieldSubmitted(mask.replaceAll(RegExp('[-.]'), ''));
return BasicTextField(
validator: Pair.str(Cpf(mal: malformed), validator ?? _dummy),
validator:
Pair.str(Cpf(mal: malformed).call, validator ?? const Ok().call)
.call,
blank: blank,
trim: trim,
keyboardType: TextInputType.number,
Expand Down Expand Up @@ -100,13 +102,10 @@ class CpfField extends StatelessWidget {
enableInteractiveSelection: enableInteractiveSelection,
autovalidateMode: autovalidateMode,
);
}),
super(key: key);
});

final ToBasicTextField _toCpfField;

static String? _dummy(String? input) => null;

/// Builds a [BasicTextField] suitable for CPF values.
@override
BasicTextField build(BuildContext context) => _toCpfField(context);
Expand Down
24 changes: 13 additions & 11 deletions lib/src/core/basic_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ class BasicTextField extends StatelessWidget {
EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
bool enableInteractiveSelection = true,
AutovalidateMode? autovalidateMode,
Key? key,
}) : _toBasicField = ((context) {
super.key,
}) : _toBasicField = ((context) {
ValStr val = validator ?? _ok;
if (blank != null) {
val = Pair.str2(Req(blank: blank), val);
val = Pair.str2(Req(blank: blank).call, val).call;
}
if (trim) {
val = Trim(val);
val = Trim(val).call;
}
final ValueChanged<String>? maybeTrimOnChanged = onChanged == null
? null
Expand Down Expand Up @@ -91,8 +91,7 @@ class BasicTextField extends StatelessWidget {
enableInteractiveSelection: enableInteractiveSelection,
autovalidateMode: autovalidateMode,
);
}),
super(key: key);
});

/// Text form field whose number of characters (length) must be equal to
/// [len] characters.
Expand Down Expand Up @@ -135,7 +134,8 @@ class BasicTextField extends StatelessWidget {
AutovalidateMode? autovalidateMode,
Key? key,
}) : this(
validator: Pair.str2(Len(len, diff: diff), validator ?? _ok),
validator:
Pair.str2(Len(len, diff: diff).call, validator ?? _ok).call,
trim: trim,
blank: blank,
keyboardType: keyboardType,
Expand Down Expand Up @@ -203,7 +203,8 @@ class BasicTextField extends StatelessWidget {
AutovalidateMode? autovalidateMode,
Key? key,
}) : this(
validator: Pair.str2(Len.min(min, short: short), validator ?? _ok),
validator:
Pair.str2(Len.min(min, short: short).call, validator ?? _ok).call,
trim: trim,
blank: blank,
keyboardType: keyboardType,
Expand Down Expand Up @@ -271,7 +272,8 @@ class BasicTextField extends StatelessWidget {
AutovalidateMode? autovalidateMode,
Key? key,
}) : this(
validator: Pair.str2(Len.max(max, long: long), validator ?? _ok),
validator:
Pair.str2(Len.max(max, long: long).call, validator ?? _ok).call,
trim: trim,
blank: blank,
controller: controller,
Expand Down Expand Up @@ -345,9 +347,9 @@ class BasicTextField extends StatelessWidget {
Key? key,
}) : this(
validator: Pair.str2(
Len.range(min, max, short: short, long: long),
Len.range(min, max, short: short, long: long).call,
validator ?? _ok,
),
).call,
trim: trim,
blank: blank,
controller: controller,
Expand Down
Loading

0 comments on commit 174c6bf

Please sign in to comment.