Skip to content

Commit fcf6ea1

Browse files
authored
DCM lint updates and related fixes (#393)
* 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
1 parent fc6a26b commit fcf6ea1

28 files changed

+122
-103
lines changed

.github/workflows/flutter_analysis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,3 @@ jobs:
3434
3535
- name: Analyze code
3636
run: flutter analyze --fatal-infos .
37-
38-
- name: Test code
39-
run: flutter test
40-

.github/workflows/test.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Flutter Analysis
2+
on: [pull_request, workflow_dispatch]
3+
4+
jobs:
5+
package-analysis:
6+
runs-on: ubuntu-latest
7+
8+
steps:
9+
- uses: actions/checkout@v3
10+
- name: Install Flutter
11+
uses: subosito/flutter-action@v2
12+
with:
13+
channel: stable
14+
15+
- name: Install dependencies
16+
run: flutter pub get
17+
18+
- name: Test code
19+
run: flutter test

analysis_options.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,23 @@ analyzer:
1414
dart_code_metrics:
1515
metrics:
1616
cyclomatic-complexity: 20
17-
number-of-parameters: 4
1817
maximum-nesting-level: 5
1918
metrics-exclude:
2019
- test/**
2120
- example/test/**
2221
rules:
2322
- prefer-trailing-comma
23+
- double-literal-format
24+
- prefer-first
25+
- prefer-last
26+
- prefer-immediate-return
27+
- avoid-global-state
28+
- always-remove-listener
29+
- avoid-unnecessary-setstate
30+
- avoid-wrapping-in-padding
31+
- prefer-const-border-radius
32+
- prefer-correct-edge-insets-constructor
33+
- use-setstate-synchronously
2434
- member-ordering:
2535
alphabetize: false
2636
order:

lib/src/buttons/back_button.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class MacosBackButtonState extends State<MacosBackButton>
196196
: _isHovered
197197
? hoverColor
198198
: fillColor,
199-
borderRadius: BorderRadius.circular(7),
199+
borderRadius: const BorderRadius.all(Radius.circular(7)),
200200
),
201201
child: Icon(
202202
CupertinoIcons.back,

lib/src/buttons/checkbox.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class MacosCheckbox extends StatelessWidget {
106106
: activeColor ?? theme.primaryColor,
107107
context,
108108
),
109-
borderRadius: BorderRadius.circular(4.0),
109+
borderRadius: const BorderRadius.all(Radius.circular(4.0)),
110110
)
111111
: BoxDecoration(
112112
color: isLight ? null : CupertinoColors.tertiaryLabel,
@@ -118,7 +118,7 @@ class MacosCheckbox extends StatelessWidget {
118118
context,
119119
),
120120
),
121-
borderRadius: BorderRadius.circular(4.0),
121+
borderRadius: const BorderRadius.all(Radius.circular(4.0)),
122122
),
123123
child: Icon(
124124
isDisabled || value == false

lib/src/buttons/disclosure_button.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class MacosDisclosureButtonState extends State<MacosDisclosureButton>
177177
? const MacosColor(0xff3C383C)
178178
: const MacosColor(0xffE5E5E5)
179179
: fillColor,
180-
borderRadius: BorderRadius.circular(7),
180+
borderRadius: const BorderRadius.all(Radius.circular(7)),
181181
),
182182
child: RotatedBox(
183183
quarterTurns: widget.isPressed ? 1 : 3,

lib/src/buttons/icon_button.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class MacosIconButtonState extends State<MacosIconButton>
253253
borderRadius: widget.borderRadius != null
254254
? widget.borderRadius
255255
: widget.shape == BoxShape.rectangle
256-
? BorderRadius.circular(7.0)
256+
? const BorderRadius.all(Radius.circular(7))
257257
: null,
258258
color: !enabled
259259
? disabledColor

lib/src/buttons/popup_button.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,8 +1091,7 @@ class _MacosPopupButtonState<T> extends State<MacosPopupButton<T>>
10911091

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

10971096
final List<_MenuItem<T>> menuItems = <_MenuItem<T>>[
10981097
for (int index = 0; index < widget.items!.length; index += 1)
@@ -1239,7 +1238,7 @@ class _MacosPopupButtonState<T> extends State<MacosPopupButton<T>>
12391238
boxShadow: [
12401239
BoxShadow(
12411240
color: buttonStyles.borderColor,
1242-
offset: const Offset(0, .5),
1241+
offset: const Offset(0, 0.5),
12431242
blurRadius: 0.2,
12441243
spreadRadius: 0,
12451244
),
@@ -1251,7 +1250,7 @@ class _MacosPopupButtonState<T> extends State<MacosPopupButton<T>>
12511250
),
12521251
borderRadius: _kBorderRadius,
12531252
),
1254-
padding: const EdgeInsets.fromLTRB(8.0, 0.0, 2.0, 0.0),
1253+
padding: const EdgeInsets.only(left: 8.0, right: 2.0),
12551254
height: _kPopupButtonHeight,
12561255
child: Row(
12571256
mainAxisAlignment: MainAxisAlignment.spaceBetween,

lib/src/buttons/pulldown_button.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ class _MacosPulldownButtonState extends State<MacosPulldownButton>
808808
void _handleTap() {
809809
final TextDirection? textDirection = Directionality.maybeOf(context);
810810
const EdgeInsetsGeometry menuMargin =
811-
EdgeInsetsDirectional.only(start: 4.0, end: 4.0);
811+
EdgeInsets.symmetric(horizontal: 4.0);
812812

813813
final List<_MenuItem> menuItems = <_MenuItem>[
814814
for (int index = 0; index < widget.items!.length; index += 1)
@@ -904,7 +904,7 @@ class _MacosPulldownButtonState extends State<MacosPulldownButton>
904904
boxShadow: [
905905
BoxShadow(
906906
color: buttonStyles.borderColor,
907-
offset: const Offset(0, .5),
907+
offset: const Offset(0, 0.5),
908908
blurRadius: 0.2,
909909
spreadRadius: 0,
910910
),
@@ -913,7 +913,7 @@ class _MacosPulldownButtonState extends State<MacosPulldownButton>
913913
color: buttonStyles.bgColor,
914914
borderRadius: borderRadius,
915915
),
916-
padding: const EdgeInsets.fromLTRB(8.0, 0.0, 2.0, 0.0),
916+
padding: const EdgeInsets.only(left: 8.0, right: 2.0),
917917
height: buttonHeight,
918918
child: Row(
919919
mainAxisAlignment: MainAxisAlignment.spaceBetween,

lib/src/buttons/segmented_control.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class _MacosSegmentedControlState extends State<MacosSegmentedControl> {
5454
const Color(0xFFDBDCDE),
5555
const Color(0xFF4F5155),
5656
),
57-
offset: const Offset(0, .5),
58-
spreadRadius: .5,
57+
offset: const Offset(0, 0.5),
58+
spreadRadius: 0.5,
5959
),
6060
],
6161
borderRadius: const BorderRadius.all(

0 commit comments

Comments
 (0)