Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Flutter lint #253

Merged
merged 24 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
95f217e
Enable `flutter_lints` linting
jasikpark Feb 13, 2025
9030664
Fix unmarked deps, we aren't on web so we don't need a URL strategy
jasikpark Feb 13, 2025
7b0441a
` dart fix --apply --code=use_super_parameters`
jasikpark Feb 13, 2025
ca4f55c
`dart fix --apply --code=use_key_in_widget_constructors`
jasikpark Feb 13, 2025
c88014c
`dart fix --apply --code=use_function_type_syntax_for_parameters`
jasikpark Feb 13, 2025
78157a8
Ignore code-generated `lib/services/theme.dart` file
jasikpark Feb 13, 2025
65d1ecd
`dart fix --apply --code=unnecessary_this`
jasikpark Feb 13, 2025
e6e7775
`dart fix --apply --code=unnecessary_null_in_if_null_operators`
jasikpark Feb 13, 2025
73f1191
`dart fix --apply --code=unnecessary_new`
jasikpark Feb 13, 2025
38c9cfc
`dart fix --apply --code=sort_child_properties_last`
jasikpark Feb 13, 2025
c01c0ed
`dart fix --apply --code=sized_box_for_whitespace`
jasikpark Feb 13, 2025
a3387ea
`dart fix --apply --code=prefer_typing_uninitialized_variables`
jasikpark Feb 13, 2025
9b4c1be
`dart fix --apply --code=prefer_is_empty`
jasikpark Feb 13, 2025
f58b374
`dart fix --apply --code=prefer_interpolation_to_compose_strings`
jasikpark Feb 13, 2025
cbcf435
`dart fix --apply --code=prefer_final_fields`
jasikpark Feb 13, 2025
99e3b4a
`dart fix --apply --code=prefer_const_constructors_in_immutables`
jasikpark Feb 13, 2025
67e8896
`dart fix --apply --code=prefer_collection_literals`
jasikpark Feb 13, 2025
45f0b38
`dart fix --apply --code=no_leading_underscores_for_local_identifiers`
jasikpark Feb 13, 2025
581c2f3
`dart fix --apply --code=curly_braces_in_flow_control_structures`
jasikpark Feb 13, 2025
89974a5
`dart fix --apply --code=avoid_function_literals_in_foreach_calls`
jasikpark Feb 13, 2025
e6c1f19
`dart fix --apply --code=annotate_overrides`
jasikpark Feb 13, 2025
1b13646
Add CI for dart linting
jasikpark Feb 13, 2025
2d0ba84
`dart format lib/`
jasikpark Feb 13, 2025
e6f0929
Re-enable the `usePathUrlStrategy` call, with proper deps
jasikpark Mar 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name: Flutter format
name: Flutter check
on:
push:
branches:
- main
pull_request:
paths:
- '.github/workflows/flutterfmt.yml'
- '.github/workflows/flutterfmt.sh'
- '.github/workflows/fluttercheck.yml'
- '**.dart'
jobs:
flutterfmt:
Expand All @@ -25,3 +24,19 @@ jobs:

- name: Check formating
run: dart format -l120 lib/ --set-exit-if-changed --suppress-analytics --output none
flutterlint:
name: Run flutter lint
runs-on: ubuntu-latest
steps:
- name: Install flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.29.0'

- name: Check out code
uses: actions/checkout@v4
with:
show-progress: false

- name: Check linting
run: dart fix --dry-run
32 changes: 32 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

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

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/tools/linter-rules.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/tools/analysis
formatter:
page_width: 120

analyzer:
exclude:
# This is a generated file, let's ignore it.
- lib/services/theme.dart
4 changes: 2 additions & 2 deletions lib/components/CIDRField.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'IPField.dart';
//TODO: Support initialValue
class CIDRField extends StatefulWidget {
const CIDRField({
Key? key,
super.key,
this.ipHelp = "ip address",
this.autoFocus = false,
this.focusNode,
Expand All @@ -17,7 +17,7 @@ class CIDRField extends StatefulWidget {
this.textInputAction,
this.ipController,
this.bitsController,
}) : super(key: key);
});

final String ipHelp;
final bool autoFocus;
Expand Down
9 changes: 3 additions & 6 deletions lib/components/CIDRFormField.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ import 'package:mobile_nebula/validators/ipValidator.dart';
class CIDRFormField extends FormField<CIDR> {
//TODO: onSaved, validator, auto-validate, enabled?
CIDRFormField({
Key? key,
super.key,
autoFocus = false,
enableIPV6 = false,
focusNode,
nextFocusNode,
ValueChanged<CIDR>? onChanged,
FormFieldSetter<CIDR>? onSaved,
super.onSaved,
textInputAction,
CIDR? initialValue,
super.initialValue,
this.ipController,
this.bitsController,
}) : super(
key: key,
initialValue: initialValue,
onSaved: onSaved,
validator: (cidr) {
if (cidr == null) {
return "Please fill out this field";
Expand Down
6 changes: 3 additions & 3 deletions lib/components/DangerButton.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class DangerButton extends StatelessWidget {
const DangerButton({Key? key, required this.child, this.onPressed}) : super(key: key);
const DangerButton({super.key, required this.child, this.onPressed});

final Widget child;
final GestureTapCallback? onPressed;
Expand All @@ -14,21 +14,21 @@ class DangerButton extends StatelessWidget {
if (Platform.isAndroid) {
return FilledButton(
onPressed: onPressed,
child: child,
style: FilledButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.error,
foregroundColor: Theme.of(context).colorScheme.onError,
),
child: child,
);
} else {
// Workaround for https://github.com/flutter/flutter/issues/161590
final themeData = CupertinoTheme.of(context);
return CupertinoTheme(
data: themeData.copyWith(primaryColor: CupertinoColors.white),
child: CupertinoButton(
child: child,
onPressed: onPressed,
color: CupertinoColors.systemRed.resolveFrom(context),
child: child,
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/components/FormPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import 'package:mobile_nebula/services/utils.dart';
/// SimplePage with a form and built in validation and confirmation to discard changes if any are made
class FormPage extends StatefulWidget {
const FormPage({
Key? key,
super.key,
required this.title,
required this.child,
required this.onSave,
required this.changed,
this.hideSave = false,
this.scrollController,
}) : super(key: key);
});

final String title;
final Function onSave;
Expand Down
4 changes: 2 additions & 2 deletions lib/components/IPAndPortField.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'IPField.dart';
//TODO: Support initialValue
class IPAndPortField extends StatefulWidget {
const IPAndPortField({
Key? key,
super.key,
this.ipOnly = false,
this.ipHelp = "ip address",
this.autoFocus = false,
Expand All @@ -20,7 +20,7 @@ class IPAndPortField extends StatefulWidget {
this.ipTextAlign,
this.ipController,
this.portController,
}) : super(key: key);
});

final String ipHelp;
final bool ipOnly;
Expand Down
14 changes: 4 additions & 10 deletions lib/components/IPAndPortFormField.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,22 @@ import 'IPAndPortField.dart';
class IPAndPortFormField extends FormField<IPAndPort> {
//TODO: onSaved, validator, auto-validate, enabled?
IPAndPortFormField({
Key? key,
super.key,
ipOnly = false,
enableIPV6 = false,
ipHelp = "ip address",
autoFocus = false,
focusNode,
nextFocusNode,
ValueChanged<IPAndPort>? onChanged,
FormFieldSetter<IPAndPort>? onSaved,
super.onSaved,
textInputAction,
IPAndPort? initialValue,
super.initialValue,
noBorder,
ipTextAlign = TextAlign.center,
this.ipController,
this.portController,
}) : super(
key: key,
initialValue: initialValue,
onSaved: onSaved,
validator: (ipAndPort) {
if (ipAndPort == null) {
return "Please fill out this field";
Expand Down Expand Up @@ -114,10 +111,7 @@ class _IPAndPortFormField extends FormFieldState<IPAndPort> {
@override
void didUpdateWidget(IPAndPortFormField oldWidget) {
super.didUpdateWidget(oldWidget);
var update = IPAndPort(
ip: widget.ipController?.text,
port: int.tryParse(widget.portController?.text ?? "") ?? null,
);
var update = IPAndPort(ip: widget.ipController?.text, port: int.tryParse(widget.portController?.text ?? ""));
bool shouldUpdate = false;

if (widget.ipController != oldWidget.ipController) {
Expand Down
8 changes: 4 additions & 4 deletions lib/components/IPField.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class IPField extends StatelessWidget {
final textAlign;

const IPField({
Key? key,
super.key,
this.ipOnly = false,
this.help = "ip address",
this.autoFocus = false,
Expand All @@ -28,7 +28,7 @@ class IPField extends StatelessWidget {
this.textInputAction,
this.controller,
this.textAlign = TextAlign.center,
}) : super(key: key);
});

@override
Widget build(BuildContext context) {
Expand All @@ -48,7 +48,7 @@ class IPField extends StatelessWidget {
maxLength: ipOnly ? 15 : null,
maxLengthEnforcement: ipOnly ? MaxLengthEnforcement.enforced : MaxLengthEnforcement.none,
inputFormatters: ipOnly ? [IPTextInputFormatter()] : [FilteringTextInputFormatter.allow(RegExp(r'[^\s]+'))],
textInputAction: this.textInputAction,
textInputAction: textInputAction,
placeholder: help,
),
);
Expand All @@ -72,7 +72,7 @@ class IPTextInputFormatter extends TextInputFormatter {

TextEditingValue _selectionAwareTextManipulation(
TextEditingValue value,
String substringManipulation(String substring),
String Function(String substring) substringManipulation,
) {
final int selectionStartIndex = value.selection.start;
final int selectionEndIndex = value.selection.end;
Expand Down
9 changes: 4 additions & 5 deletions lib/components/IPFormField.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,23 @@ import 'IPField.dart';
class IPFormField extends FormField<String> {
//TODO: validator, auto-validate, enabled?
IPFormField({
Key? key,
super.key,
ipOnly = false,
enableIPV6 = false,
help = "ip address",
autoFocus = false,
focusNode,
nextFocusNode,
ValueChanged<String>? onChanged,
FormFieldSetter<String>? onSaved,
super.onSaved,
textPadding = const EdgeInsets.all(6.0),
textInputAction,
initialValue,
this.controller,
crossAxisAlignment = CrossAxisAlignment.center,
textAlign = TextAlign.center,
}) : super(
key: key,
initialValue: initialValue,
onSaved: onSaved,
validator: (ip) {
if (ip == null || ip == "") {
return "Please fill out this field";
Expand Down Expand Up @@ -108,8 +106,9 @@ class _IPFormField extends FormFieldState<String> {
oldWidget.controller?.removeListener(_handleControllerChanged);
widget.controller?.addListener(_handleControllerChanged);

if (oldWidget.controller != null && widget.controller == null)
if (oldWidget.controller != null && widget.controller == null) {
_controller = TextEditingController.fromValue(oldWidget.controller!.value);
}
if (widget.controller != null) {
setValue(widget.controller!.text);
if (oldWidget.controller == null) _controller = null;
Expand Down
9 changes: 4 additions & 5 deletions lib/components/PlatformTextFormField.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:mobile_nebula/components/SpecialTextField.dart';
class PlatformTextFormField extends FormField<String> {
//TODO: auto-validate, enabled?
PlatformTextFormField({
Key? key,
super.key,
widgetKey,
this.controller,
focusNode,
Expand All @@ -28,11 +28,9 @@ class PlatformTextFormField extends FormField<String> {
String? initialValue,
String? placeholder,
FormFieldValidator<String>? validator,
ValueChanged<String?>? onSaved,
super.onSaved,
}) : super(
key: key,
initialValue: controller != null ? controller.text : (initialValue ?? ''),
onSaved: onSaved,
validator: (str) {
if (validator != null) {
return validator(str);
Expand Down Expand Up @@ -117,8 +115,9 @@ class _PlatformTextFormFieldState extends FormFieldState<String> {
oldWidget.controller?.removeListener(_handleControllerChanged);
widget.controller?.addListener(_handleControllerChanged);

if (oldWidget.controller != null && widget.controller == null)
if (oldWidget.controller != null && widget.controller == null) {
_controller = TextEditingController.fromValue(oldWidget.controller!.value);
}
if (widget.controller != null) {
setValue(widget.controller!.text);
if (oldWidget.controller == null) _controller = null;
Expand Down
12 changes: 6 additions & 6 deletions lib/components/SimplePage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ enum SimpleScrollable { none, vertical, horizontal, both }

class SimplePage extends StatelessWidget {
const SimplePage({
Key? key,
super.key,
required this.title,
required this.child,
this.leadingAction,
Expand All @@ -19,7 +19,7 @@ class SimplePage extends StatelessWidget {
this.onLoading,
this.alignment,
this.refreshController,
}) : super(key: key);
});

final Widget title;
final Widget child;
Expand All @@ -43,13 +43,13 @@ class SimplePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget realChild = child;
var addScrollbar = this.scrollbar;
var addScrollbar = scrollbar;

if (scrollable == SimpleScrollable.vertical || scrollable == SimpleScrollable.both) {
realChild = SingleChildScrollView(
scrollDirection: Axis.vertical,
child: realChild,
controller: refreshController == null ? scrollController : null,
child: realChild,
);
addScrollbar = true;
}
Expand All @@ -69,10 +69,10 @@ class SimplePage extends StatelessWidget {
onRefresh: onRefresh,
onLoading: onLoading,
controller: refreshController!,
child: realChild,
enablePullUp: onLoading != null,
enablePullDown: onRefresh != null,
footer: ClassicFooter(loadStyle: LoadStyle.ShowWhenLoading),
child: realChild,
),
);
addScrollbar = true;
Expand All @@ -83,7 +83,7 @@ class SimplePage extends StatelessWidget {
}

if (alignment != null) {
realChild = Align(alignment: this.alignment!, child: realChild);
realChild = Align(alignment: alignment!, child: realChild);
}

if (bottomBar != null) {
Expand Down
Loading