Skip to content

Commit

Permalink
DCM lint updates and related fixes (#393)
Browse files Browse the repository at this point in the history
* lints: add `double-literal-format` lint and fixes

* lints: add `prefer-first`, `prefer-last`, and `prefer-immediate-return`

Includes fixes

* chore: remove a redundant `async`

* fix: avoid non-const or final global state

* lints: add always-remove-listener and fix

* lints: add `avoid-unnecessary-setstate` and fixes

* lints: add `avoid-wrapping-in-padding` and fixes

* lints: add `prefer-const-border-radius` and fixes

* lints: add `prefer-correct-edge-insets-constructor` and fixes

* lints: add `use-setstate-synchronously` and fixes

* lints: remove `number-of-parameters`

* fix(MacosTextField): remove FocusNode listener instead of disposing FocusNode

* chore(actions): split out tests into their own workflow
  • Loading branch information
GroovinChip authored Mar 21, 2023
1 parent fc6a26b commit fcf6ea1
Show file tree
Hide file tree
Showing 28 changed files with 122 additions and 103 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/flutter_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,3 @@ jobs:
- name: Analyze code
run: flutter analyze --fatal-infos .

- name: Test code
run: flutter test

19 changes: 19 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Flutter Analysis
on: [pull_request, workflow_dispatch]

jobs:
package-analysis:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Install Flutter
uses: subosito/flutter-action@v2
with:
channel: stable

- name: Install dependencies
run: flutter pub get

- name: Test code
run: flutter test
12 changes: 11 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@ analyzer:
dart_code_metrics:
metrics:
cyclomatic-complexity: 20
number-of-parameters: 4
maximum-nesting-level: 5
metrics-exclude:
- test/**
- example/test/**
rules:
- prefer-trailing-comma
- double-literal-format
- prefer-first
- prefer-last
- prefer-immediate-return
- avoid-global-state
- always-remove-listener
- avoid-unnecessary-setstate
- avoid-wrapping-in-padding
- prefer-const-border-radius
- prefer-correct-edge-insets-constructor
- use-setstate-synchronously
- member-ordering:
alphabetize: false
order:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/buttons/back_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class MacosBackButtonState extends State<MacosBackButton>
: _isHovered
? hoverColor
: fillColor,
borderRadius: BorderRadius.circular(7),
borderRadius: const BorderRadius.all(Radius.circular(7)),
),
child: Icon(
CupertinoIcons.back,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/buttons/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class MacosCheckbox extends StatelessWidget {
: activeColor ?? theme.primaryColor,
context,
),
borderRadius: BorderRadius.circular(4.0),
borderRadius: const BorderRadius.all(Radius.circular(4.0)),
)
: BoxDecoration(
color: isLight ? null : CupertinoColors.tertiaryLabel,
Expand All @@ -118,7 +118,7 @@ class MacosCheckbox extends StatelessWidget {
context,
),
),
borderRadius: BorderRadius.circular(4.0),
borderRadius: const BorderRadius.all(Radius.circular(4.0)),
),
child: Icon(
isDisabled || value == false
Expand Down
2 changes: 1 addition & 1 deletion lib/src/buttons/disclosure_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class MacosDisclosureButtonState extends State<MacosDisclosureButton>
? const MacosColor(0xff3C383C)
: const MacosColor(0xffE5E5E5)
: fillColor,
borderRadius: BorderRadius.circular(7),
borderRadius: const BorderRadius.all(Radius.circular(7)),
),
child: RotatedBox(
quarterTurns: widget.isPressed ? 1 : 3,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/buttons/icon_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class MacosIconButtonState extends State<MacosIconButton>
borderRadius: widget.borderRadius != null
? widget.borderRadius
: widget.shape == BoxShape.rectangle
? BorderRadius.circular(7.0)
? const BorderRadius.all(Radius.circular(7))
: null,
color: !enabled
? disabledColor
Expand Down
7 changes: 3 additions & 4 deletions lib/src/buttons/popup_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1091,8 +1091,7 @@ class _MacosPopupButtonState<T> extends State<MacosPopupButton<T>>

void _handleTap() {
final TextDirection? textDirection = Directionality.maybeOf(context);
const EdgeInsetsGeometry menuMargin =
EdgeInsetsDirectional.only(start: 4.0, end: 4.0);
const EdgeInsetsGeometry menuMargin = EdgeInsets.symmetric(horizontal: 4.0);

final List<_MenuItem<T>> menuItems = <_MenuItem<T>>[
for (int index = 0; index < widget.items!.length; index += 1)
Expand Down Expand Up @@ -1239,7 +1238,7 @@ class _MacosPopupButtonState<T> extends State<MacosPopupButton<T>>
boxShadow: [
BoxShadow(
color: buttonStyles.borderColor,
offset: const Offset(0, .5),
offset: const Offset(0, 0.5),
blurRadius: 0.2,
spreadRadius: 0,
),
Expand All @@ -1251,7 +1250,7 @@ class _MacosPopupButtonState<T> extends State<MacosPopupButton<T>>
),
borderRadius: _kBorderRadius,
),
padding: const EdgeInsets.fromLTRB(8.0, 0.0, 2.0, 0.0),
padding: const EdgeInsets.only(left: 8.0, right: 2.0),
height: _kPopupButtonHeight,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
Expand Down
6 changes: 3 additions & 3 deletions lib/src/buttons/pulldown_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ class _MacosPulldownButtonState extends State<MacosPulldownButton>
void _handleTap() {
final TextDirection? textDirection = Directionality.maybeOf(context);
const EdgeInsetsGeometry menuMargin =
EdgeInsetsDirectional.only(start: 4.0, end: 4.0);
EdgeInsets.symmetric(horizontal: 4.0);

final List<_MenuItem> menuItems = <_MenuItem>[
for (int index = 0; index < widget.items!.length; index += 1)
Expand Down Expand Up @@ -904,7 +904,7 @@ class _MacosPulldownButtonState extends State<MacosPulldownButton>
boxShadow: [
BoxShadow(
color: buttonStyles.borderColor,
offset: const Offset(0, .5),
offset: const Offset(0, 0.5),
blurRadius: 0.2,
spreadRadius: 0,
),
Expand All @@ -913,7 +913,7 @@ class _MacosPulldownButtonState extends State<MacosPulldownButton>
color: buttonStyles.bgColor,
borderRadius: borderRadius,
),
padding: const EdgeInsets.fromLTRB(8.0, 0.0, 2.0, 0.0),
padding: const EdgeInsets.only(left: 8.0, right: 2.0),
height: buttonHeight,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/buttons/segmented_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class _MacosSegmentedControlState extends State<MacosSegmentedControl> {
const Color(0xFFDBDCDE),
const Color(0xFF4F5155),
),
offset: const Offset(0, .5),
spreadRadius: .5,
offset: const Offset(0, 0.5),
spreadRadius: 0.5,
),
],
borderRadius: const BorderRadius.all(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/buttons/toolbar/toolbar_icon_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ToolBarIconButton extends ToolbarItem {

if (showLabel) {
iconButton = Padding(
padding: const EdgeInsets.fromLTRB(6.0, 6.0, 6.0, 0.0),
padding: const EdgeInsets.only(left: 6.0, top: 6.0, right: 6.0),
child: Column(
children: [
iconButton,
Expand Down
3 changes: 2 additions & 1 deletion lib/src/fields/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class MacosTextField extends StatefulWidget {
this.focusNode,
this.decoration,
this.focusedDecoration,
this.padding = const EdgeInsets.fromLTRB(2.0, 4.0, 2.0, 4.0),
this.padding = const EdgeInsets.symmetric(horizontal: 2.0, vertical: 4.0),
this.placeholder,
this.placeholderStyle = _kDefaultPlaceholderStyle,
this.prefix,
Expand Down Expand Up @@ -1157,6 +1157,7 @@ class _MacosTextFieldState extends State<MacosTextField>
void dispose() {
_focusNode?.dispose();
_controller?.dispose();
_effectiveFocusNode.removeListener(_handleFocusChanged);
super.dispose();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/indicators/progress_indicators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class _DeterminateCirclePainter extends CustomPainter {
final Color? borderColor;

static const double _twoPi = math.pi * 2.0;
static const double _epsilon = .001;
static const double _epsilon = 0.001;
static const double _sweep = _twoPi - _epsilon;
static const double _startAngle = -math.pi / 2.0;

Expand Down Expand Up @@ -240,7 +240,7 @@ class _DeterminateBarPainter extends CustomPainter {
void paint(Canvas canvas, Size size) {
// Draw the background line
canvas.drawRRect(
BorderRadius.circular(100).toRRect(
const BorderRadius.all(Radius.circular(100)).toRRect(
Offset.zero & size,
),
Paint()
Expand Down
17 changes: 11 additions & 6 deletions lib/src/indicators/slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ class MacosSlider extends StatelessWidget {
backgroundColor,
context,
),
borderRadius:
BorderRadius.circular(_kSliderBorderRadius),
borderRadius: const BorderRadius.all(
Radius.circular(_kSliderBorderRadius),
),
),
),
),
Expand All @@ -192,8 +193,9 @@ class MacosSlider extends StatelessWidget {
width: width * _percentage,
decoration: BoxDecoration(
color: MacosDynamicColor.resolve(color, context),
borderRadius:
BorderRadius.circular(_kSliderBorderRadius),
borderRadius: const BorderRadius.all(
Radius.circular(_kSliderBorderRadius),
),
),
),
),
Expand Down Expand Up @@ -273,7 +275,8 @@ class _ContinuousThumb extends StatelessWidget {
width: _kContinuousThumbSize,
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(_kContinuousThumbSize),
borderRadius:
const BorderRadius.all(Radius.circular(_kContinuousThumbSize)),
boxShadow: const [
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.1),
Expand All @@ -300,7 +303,9 @@ class _DiscreteThumb extends StatelessWidget {
width: _kDiscreteThumbWidth,
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(_kDiscreteThumbBorderRadius),
borderRadius: const BorderRadius.all(
Radius.circular(_kDiscreteThumbBorderRadius),
),
boxShadow: const [
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.1),
Expand Down
6 changes: 2 additions & 4 deletions lib/src/layout/resizable_pane.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,8 @@ class _ResizablePaneState extends State<ResizablePane> {
oldWidget.minSize != widget.minSize ||
oldWidget.maxSize != widget.maxSize ||
oldWidget.resizableSide != widget.resizableSide) {
setState(() {
if (widget.minSize > _size) _size = widget.minSize;
if (widget.maxSize < _size) _size = widget.maxSize;
});
if (widget.minSize > _size) _size = widget.minSize;
if (widget.maxSize < _size) _size = widget.maxSize;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/layout/scrollbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class _RawMacosScrollBarState extends RawScrollbarState<_RawMacosScrollBar> {
);
_trackColorTween = ColorTween(
begin: MacosColors.transparent,
end: widget.effectiveThumbColor.withOpacity(.15),
end: widget.effectiveThumbColor.withOpacity(0.15),
).animate(_trackColorAnimationController);
_thumbThicknessAnimationController.addListener(() {
updateScrollbarPainter();
Expand Down
9 changes: 3 additions & 6 deletions lib/src/layout/sidebar/sidebar_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ class _SidebarItem extends StatelessWidget {
/// Typically a [Navigator] call
final VoidCallback? onClick;

void _handleActionTap() async {
onClick?.call();
}
void _handleActionTap() => onClick?.call();

Map<Type, Action<Intent>> get _actionMap => <Type, Action<Intent>>{
ActivateIntent: CallbackAction<ActivateIntent>(
Expand Down Expand Up @@ -286,9 +284,8 @@ class _SidebarItem extends StatelessWidget {
padding: EdgeInsets.only(right: spacing),
child: MacosIconTheme.merge(
data: MacosIconThemeData(
color: selected
? MacosColors.white
: theme.primaryColor,
color:
selected ? MacosColors.white : theme.primaryColor,
size: itemSize.iconSize,
),
child: item.leading!,
Expand Down
3 changes: 1 addition & 2 deletions lib/src/layout/toolbar/sliver_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class _SliverToolBarDelegate extends SliverPersistentHeaderDelegate {
);
}

final Widget toolBar = FlexibleSpaceBar.createSettings(
return FlexibleSpaceBar.createSettings(
minExtent: minExtent,
maxExtent: maxExtent,
currentExtent: math.max(minExtent, maxExtent - shrinkOffset),
Expand All @@ -295,7 +295,6 @@ class _SliverToolBarDelegate extends SliverPersistentHeaderDelegate {
height: height,
),
);
return toolBar;
}

@override
Expand Down
10 changes: 2 additions & 8 deletions lib/src/layout/toolbar/toolbar_divider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,9 @@ class ToolBarDivider extends ToolbarItem {
const Color.fromRGBO(255, 255, 255, 0.25),
);
if (displayMode == ToolbarItemDisplayMode.inToolbar) {
return Padding(
padding: padding!,
child: Container(color: color, width: 1, height: 28),
);
return Container(color: color, width: 1, height: 28, padding: padding!);
} else {
return Padding(
padding: padding!,
child: Container(color: color, height: 1),
);
return Container(color: color, height: 1, padding: padding!);
}
}
}
5 changes: 2 additions & 3 deletions lib/src/layout/toolbar/toolbar_popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class _ToolbarPopupMenuState<T> extends State<_ToolbarPopupMenu<T>> {
super.initState();
_fadeOpacity = CurvedAnimation(
parent: widget.route.animation!,
curve: const Interval(0.0, 0.50),
curve: const Interval(0.0, 0.5),
reverseCurve: const Interval(0.75, 1.0),
);
}
Expand Down Expand Up @@ -335,7 +335,7 @@ class _ToolbarPopupRoute<T> extends PopupRoute<T> {
@override
Widget buildPage(context, animation, secondaryAnimation) {
return LayoutBuilder(builder: (context, constraints) {
final page = _ToolbarPopupRoutePage<T>(
return _ToolbarPopupRoutePage<T>(
target: target,
placementOffset: placementOffset,
placement: placement,
Expand All @@ -349,7 +349,6 @@ class _ToolbarPopupRoute<T> extends PopupRoute<T> {
horizontalOffset: horizontalOffset,
position: position,
);
return page;
});
}

Expand Down
Loading

0 comments on commit fcf6ea1

Please sign in to comment.