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 custom lints #303

Merged
merged 10 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion forui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ Bump minimum Flutter version to 3.27.0.

* Change `FSelectMenuTile` to be scrollable.

* **Breaking** Change `FLocalizations.of(...)` to return `FLocalizations?` instead of `FLocalizations` - do `FLocalizations.of(...) ?? DefaultLocalizations()`.
* Change `ThemeBuildContext` to `FThemeBuildContext`.

* **Breaking** Change `Layout` to `FLayout`.

* **Breaking** Change `FLocalizations.of(...)` to return `FLocalizations?` instead of `FLocalizations` - do `FLocalizations.of(...) ?? FDefaultLocalizations()`.
This change is sadly needed as Flutter now forcefully regenerates `FLocalizations` each time `flutter pub get` is called.

* **Breaking** Change `FTileData.index` to `FTileData.last`.
Expand Down
4 changes: 3 additions & 1 deletion forui/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
include: package:flint/analysis_options.flutter.yaml
analyzer:
plugins:
- custom_lint
errors:
unused_result: ignore

linter:
rules:
- use_key_in_widget_constructors
- require_trailing_commas
- require_trailing_commas
3,400 changes: 3,400 additions & 0 deletions forui/custom_lint.log

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion forui/example/lib/sandbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class _SandboxState extends State<Sandbox> with SingleTickerProviderStateMixin {
}

class AForm extends StatelessWidget {
final Layout side;
final FLayout side;

const AForm({required this.side, super.key});

Expand Down
2 changes: 1 addition & 1 deletion forui/lib/src/foundation/form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ abstract class FFormField<T> extends StatelessWidget {
..add(StringProperty('forceErrorText', forceErrorText))
..add(ObjectFlagProperty.has('validator', validator))
..add(DiagnosticsProperty('initialValue', initialValue))
..add(DiagnosticsProperty('enabled', enabled))
..add(FlagProperty('enabled', value: enabled, ifFalse: 'disabled'))
..add(EnumProperty('autovalidateMode', autovalidateMode))
..add(StringProperty('restorationId', restorationId));
}
Expand Down
2 changes: 2 additions & 0 deletions forui/lib/src/foundation/notifiers.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/foundation.dart';

// ignore_for_file: always_call_super_dispose_last

/// A [ChangeNotifier] that provides additional life-cycle tracking capabilities.
class FChangeNotifier with ChangeNotifier {
bool _disposed = false;
Expand Down
8 changes: 4 additions & 4 deletions forui/lib/src/foundation/portal/portal.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

Expand Down Expand Up @@ -60,9 +60,9 @@ class FPortal extends StatefulWidget {
..add(DiagnosticsProperty('controller', controller))
..add(DiagnosticsProperty('followerAnchor', followerAnchor))
..add(DiagnosticsProperty('targetAnchor', targetAnchor))
..add(DiagnosticsProperty('shift', shift))
..add(ObjectFlagProperty.has('shift', shift))
..add(DiagnosticsProperty('offset', offset))
..add(DiagnosticsProperty('followerBuilder', followerBuilder));
..add(ObjectFlagProperty.has('followerBuilder', followerBuilder));
}
}

Expand Down Expand Up @@ -196,7 +196,7 @@ class _RenderBox extends RenderBox with RenderObjectWithChildMixin<RenderBox> {
..add(DiagnosticsProperty('link', link))
..add(DiagnosticsProperty('targetAnchor', targetAnchor))
..add(DiagnosticsProperty('followerAnchor', followerAnchor))
..add(DiagnosticsProperty('shift', shift))
..add(ObjectFlagProperty.has('shift', shift))
..add(DiagnosticsProperty('offset', offset));
}

Expand Down
4 changes: 2 additions & 2 deletions forui/lib/src/foundation/rendering.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/rendering.dart';
import 'package:meta/meta.dart';

/// Possible way to layout a sequence of items.
enum Layout {
enum FLayout {
/// Lays out the items horizontally from left to right.
ltr(vertical: false),

Expand All @@ -19,7 +19,7 @@ enum Layout {
/// Whether the layout is vertical.
final bool vertical;

const Layout({required this.vertical});
const FLayout({required this.vertical});
}

@internal
Expand Down
10 changes: 5 additions & 5 deletions forui/lib/src/localizations/localization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ extension FDateTimeLocalizations on FLocalizations {
}

/// The default localization for when no localization is provided.
class DefaultLocalizations extends FLocalizations {
static final _localizations = DefaultLocalizations._();
class FDefaultLocalizations extends FLocalizations {
static final _localizations = FDefaultLocalizations._();

/// Creates a [DefaultLocalizations].
factory DefaultLocalizations() => _localizations;
/// Creates a [FDefaultLocalizations].
factory FDefaultLocalizations() => _localizations;

DefaultLocalizations._() : super('');
FDefaultLocalizations._() : super('');

@override
String fullDate(DateTime date) => DateFormat.yMMMMd().format(date);
Expand Down
10 changes: 5 additions & 5 deletions forui/lib/src/theme/breakpoints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ final class FBreakpoints with Diagnosticable {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('sm', sm))
..add(DiagnosticsProperty('md', md))
..add(DiagnosticsProperty('lg', lg))
..add(DiagnosticsProperty('xl', xl))
..add(DiagnosticsProperty('xl2', xl2));
..add(DoubleProperty('sm', sm))
..add(DoubleProperty('md', md))
..add(DoubleProperty('lg', lg))
..add(DoubleProperty('xl', xl))
..add(DoubleProperty('xl2', xl2));
}
}
6 changes: 3 additions & 3 deletions forui/lib/src/theme/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:meta/meta.dart';
/// Applies a theme to descendant widgets.
///
/// A theme configures the colors and typographic choices of Forui widgets. The actual configuration is stored in
/// a [FThemeData]. Descendant widgets obtain the current theme's [FThemeData] via either [ThemeBuildContext.theme],
/// a [FThemeData]. Descendant widgets obtain the current theme's [FThemeData] via either [FThemeBuildContext.theme],
/// or [FTheme.of]. When a widget uses either, it is automatically rebuilt if the theme later changes.
///
/// ```dart
Expand All @@ -34,7 +34,7 @@ import 'package:meta/meta.dart';
class FTheme extends StatelessWidget {
/// Returns the current [FThemeData], or `FThemes.zinc.light` if there is no ancestor [FTheme].
///
/// It is recommended to use the terser [ThemeBuildContext.theme] getter instead.
/// It is recommended to use the terser [FThemeBuildContext.theme] getter instead.
///
/// ## Troubleshooting:
///
Expand Down Expand Up @@ -140,7 +140,7 @@ class _InheritedTheme extends InheritedTheme {
}

/// Provides functions for accessing the current [FThemeData].
extension ThemeBuildContext on BuildContext {
extension FThemeBuildContext on BuildContext {
/// Returns the current [FThemeData], or `FThemes.zinc.light` if there is no ancestor [FTheme].
///
/// ## Troubleshooting:
Expand Down
2 changes: 1 addition & 1 deletion forui/lib/src/widgets/badge/badge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class FBadge extends StatelessWidget {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('style', style, defaultValue: FBadgeStyle.primary))
..add(DiagnosticsProperty('builder', builder, level: DiagnosticLevel.debug));
..add(ObjectFlagProperty.has('builder', builder));
}
}

Expand Down
8 changes: 4 additions & 4 deletions forui/lib/src/widgets/calendar/day/day_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class DayPicker extends StatefulWidget {
..add(DiagnosticsProperty('month', month))
..add(DiagnosticsProperty('today', today))
..add(DiagnosticsProperty('focused', focused))
..add(DiagnosticsProperty('selectable', selectable))
..add(DiagnosticsProperty('selected', selected))
..add(DiagnosticsProperty('onPress', onPress))
..add(DiagnosticsProperty('onLongPress', onLongPress));
..add(ObjectFlagProperty.has('selectable', selectable))
..add(ObjectFlagProperty.has('selected', selected))
..add(ObjectFlagProperty.has('onPress', onPress))
..add(ObjectFlagProperty.has('onLongPress', onLongPress));
}
}

Expand Down
14 changes: 7 additions & 7 deletions forui/lib/src/widgets/calendar/day/paged_day_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class PagedDayPicker extends PagedPicker {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('selected', selected))
..add(DiagnosticsProperty('onMonthChange', onMonthChange))
..add(DiagnosticsProperty('onPress', onPress))
..add(DiagnosticsProperty('onLongPress', onLongPress))
..add(DiagnosticsProperty('dayBuilder', dayBuilder));
..add(ObjectFlagProperty.has('selected', selected))
..add(ObjectFlagProperty.has('onMonthChange', onMonthChange))
..add(ObjectFlagProperty.has('onPress', onPress))
..add(ObjectFlagProperty.has('onLongPress', onLongPress))
..add(ObjectFlagProperty.has('dayBuilder', dayBuilder));
}
}

Expand All @@ -52,7 +52,7 @@ class _PagedDayPickerState extends PagedPickerState<PagedDayPicker> {
@override
Widget buildItem(BuildContext context, int page) => DayPicker(
style: widget.style.dayPickerStyle,
localization: FLocalizations.of(context) ?? DefaultLocalizations(),
localization: FLocalizations.of(context) ?? FDefaultLocalizations(),
dayBuilder: widget.dayBuilder,
month: widget.start.truncate(to: DateUnit.months).plus(months: page),
today: widget.today,
Expand Down Expand Up @@ -88,7 +88,7 @@ class _PagedDayPickerState extends PagedPickerState<PagedDayPicker> {
}

SemanticsService.announce(
(FLocalizations.of(context) ?? DefaultLocalizations()).fullDate(current.toNative()),
(FLocalizations.of(context) ?? FDefaultLocalizations()).fullDate(current.toNative()),
textDirection,
);
});
Expand Down
4 changes: 2 additions & 2 deletions forui/lib/src/widgets/calendar/month/month_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MonthPicker extends StatefulWidget {
..add(DiagnosticsProperty('end', end, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('today', today, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('focused', focused, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('onPress', onPress, level: DiagnosticLevel.debug));
..add(ObjectFlagProperty.has('onPress', onPress, level: DiagnosticLevel.debug));
}
}

Expand Down Expand Up @@ -82,7 +82,7 @@ class _MonthPickerState extends State<MonthPicker> {
current: widget.today.truncate(to: DateUnit.months) == month,
selectable: widget.start <= month && month <= widget.end,
format: (date) =>
(FLocalizations.of(context) ?? DefaultLocalizations()).abbreviatedMonth(date.toNative()),
(FLocalizations.of(context) ?? FDefaultLocalizations()).abbreviatedMonth(date.toNative()),
onPress: widget.onPress,
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PagedMonthPicker extends PagedPicker {
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty('onPress', onPress));
properties.add(ObjectFlagProperty.has('onPress', onPress));
}
}

Expand Down
6 changes: 3 additions & 3 deletions forui/lib/src/widgets/calendar/shared/entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract class Entry extends StatelessWidget {
TextDirection.ltr || null => BorderRadius.horizontal(left: yesterday, right: tomorrow),
TextDirection.rtl => BorderRadius.horizontal(left: tomorrow, right: yesterday),
},
text: (FLocalizations.of(context) ?? DefaultLocalizations()).day(date.toNative()),
text: (FLocalizations.of(context) ?? FDefaultLocalizations()).day(date.toNative()),
data: data,
current: today,
);
Expand Down Expand Up @@ -126,7 +126,7 @@ abstract class Entry extends StatelessWidget {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('style', style))
..add(DiagnosticsProperty('builder', builder));
..add(ObjectFlagProperty.has('builder', builder));
}
}

Expand Down Expand Up @@ -227,7 +227,7 @@ class _Content extends StatelessWidget {
..add(DiagnosticsProperty('style', style))
..add(DiagnosticsProperty('borderRadius', borderRadius))
..add(StringProperty('text', text))
..add(DiagnosticsProperty('state', data.toString()))
..add(StringProperty('state', data.toString()))
..add(FlagProperty('current', value: current, ifTrue: 'current'));
}
}
Expand Down
6 changes: 3 additions & 3 deletions forui/lib/src/widgets/calendar/shared/header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class _HeaderState extends State<Header> with SingleTickerProviderStateMixin {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
(FLocalizations.of(context) ?? DefaultLocalizations()).yearMonth(widget.month.toNative()),
(FLocalizations.of(context) ?? FDefaultLocalizations()).yearMonth(widget.month.toNative()),
style: widget.style.headerTextStyle,
),
RotationTransition(
Expand Down Expand Up @@ -183,8 +183,8 @@ class Navigation extends StatelessWidget {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('style', style))
..add(DiagnosticsProperty('onPrevious', onPrevious))
..add(DiagnosticsProperty('onNext', onNext));
..add(ObjectFlagProperty.has('onPrevious', onPrevious))
..add(ObjectFlagProperty.has('onNext', onNext));
}
}

Expand Down
2 changes: 1 addition & 1 deletion forui/lib/src/widgets/calendar/shared/paged_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class PagedPicker extends StatefulWidget {
..add(DiagnosticsProperty('end', end))
..add(DiagnosticsProperty('today', today))
..add(DiagnosticsProperty('initial', initial))
..add(DiagnosticsProperty('selectable', selectable));
..add(ObjectFlagProperty.has('selectable', selectable));
}
}

Expand Down
3 changes: 2 additions & 1 deletion forui/lib/src/widgets/calendar/year/paged_year_picker.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

Expand Down Expand Up @@ -26,7 +27,7 @@ class PagedYearPicker extends PagedPicker {
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty('onPress', onPress));
properties.add(ObjectFlagProperty.has('onPress', onPress));
}
}

Expand Down
4 changes: 2 additions & 2 deletions forui/lib/src/widgets/calendar/year/year_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class YearPicker extends StatefulWidget {
..add(DiagnosticsProperty('end', end, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('today', today, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('focused', focused, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('onPress', onPress, level: DiagnosticLevel.debug));
..add(ObjectFlagProperty.has('onPress', onPress, level: DiagnosticLevel.debug));
}
}

Expand Down Expand Up @@ -86,7 +86,7 @@ class _YearPickerState extends State<YearPicker> {
focusNode: _years[i],
current: widget.today.year == year.year,
selectable: widget.start <= year && year <= widget.end,
format: (date) => (FLocalizations.of(context) ?? DefaultLocalizations()).year(date.toNative()),
format: (date) => (FLocalizations.of(context) ?? FDefaultLocalizations()).year(date.toNative()),
onPress: widget.onPress,
),
],
Expand Down
6 changes: 3 additions & 3 deletions forui/lib/src/widgets/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ class FCheckbox extends StatefulWidget {
properties
..add(DiagnosticsProperty('style', style))
..add(StringProperty('semanticLabel', semanticLabel))
..add(FlagProperty('value', value: value))
..add(FlagProperty('value', value: value, ifTrue: 'checked'))
..add(ObjectFlagProperty.has('onChange', onChange))
..add(FlagProperty('enabled', value: enabled))
..add(DiagnosticsProperty('autofocus', autofocus))
..add(FlagProperty('enabled', value: enabled, ifFalse: 'disabled'))
..add(FlagProperty('autofocus', value: autofocus, ifTrue: 'autofocus'))
..add(DiagnosticsProperty('focusNode', focusNode))
..add(ObjectFlagProperty.has('onFocusChange', onFocusChange));
}
Expand Down
2 changes: 1 addition & 1 deletion forui/lib/src/widgets/dialog/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class FDialog extends StatelessWidget {
..add(DiagnosticsProperty('insetAnimationDuration', insetAnimationDuration, defaultValue: _defaultDuration))
..add(DiagnosticsProperty('insetAnimationCurve', insetAnimationCurve, defaultValue: Curves.decelerate))
..add(StringProperty('semanticLabel', semanticLabel))
..add(DiagnosticsProperty('builder', builder));
..add(ObjectFlagProperty.has('builder', builder));
}
}

Expand Down
4 changes: 2 additions & 2 deletions forui/lib/src/widgets/header/header_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class FHeaderAction extends StatelessWidget {
..add(FlagProperty('autofocus', value: autofocus, ifTrue: 'autofocus'))
..add(DiagnosticsProperty('focusNode', focusNode))
..add(ObjectFlagProperty.has('onFocusChange', onFocusChange))
..add(DiagnosticsProperty('onPress', onPress))
..add(DiagnosticsProperty('onLongPress', onLongPress));
..add(ObjectFlagProperty.has('onPress', onPress))
..add(ObjectFlagProperty.has('onLongPress', onLongPress));
}
}

Expand Down
Loading
Loading