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

feat(analyze): Add DCM and fix potentiall bugs, depreciations #315

Merged
merged 11 commits into from
Sep 6, 2024
6 changes: 5 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
with:
flutter-version: '3.13.0' # Uses the minimum supported version.
channel: stable
- name: Install DCM
uses: CQLabs/setup-dcm@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Get Flutter version
- name: Get Flutter version
run: flutter --version
Expand All @@ -37,7 +41,7 @@ jobs:
run: flutter analyze
- name: Check if flutter analyze passes
run: echo $?
# Run melos analyze to find analzyer issues in demos
# Run melos analyze to find analzyer issues using DCM.dev for both Flutter and Dart
- name: Run melos analyze
run: melos analyze
- name: Check if melos analyze passes
Expand Down
58 changes: 36 additions & 22 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,40 @@ To get started with contributing, please follow the steps below:
1. [Fork the wolt_modal_sheet repo](https://github.com/woltapp/wolt_modal_sheet/fork) on GitHub.
2. Clone your forked repo locally.
3. Ensure you have [Melos](https://pub.dev/packages/melos/install) installed.
```bash
dart pub global activate melos
```

```bash
dart pub global activate melos
```

4. Use Melos to bootstrap the project.
```bash
melos bootstrap
```
5. Create a new branch from the `main` branch.
6. Make your changes.
7. Run Melos format to format the code.
```bash
melos format
```
8. Run Melos analyze to identify any issues.
```bash
melos analyze
```
9. Make sure all existing tests pass and add new tests for the changes you made.
Execute the following command to run the tests.
```bash
melos test
```
10. Create a pull request.

```bash
melos bootstrap
```

5. Ensure DCM (dcm.dev) is installed and activated
- Enabling and activating DCM is optional. When you open a PR, the CI bots will show you any DCM warnings introduced
by your change which should be fixed before submitting. please follow instructions at <https://dcm.dev/pricing/>. You can either use the free tier of DCM, or purchase a pro or team license. Note that the free tier doesn't support all the rules of the paid tier, so you will also need to consult the output of the `Dart Code Metrics workflow on Github` when you open your PR. To enable DCM check this [quick start guide](https://dcm.dev/docs/quick-start/)

6. Create a new branch from the `main` branch.
7. Make your changes.
8. Run Melos format to format the code.

```bash
melos format
```

9. Run Melos analyze to identify any issues.
- Note, if you don't have DCM install locally, this command will fail, but you can check PR's CI output after sending your PR.

```bash
melos analyze
```

10. Make sure all existing tests pass and add new tests for the changes you made. Execute the following command to run the tests.

```bash
melos test
```

11. Create a pull request.
25 changes: 25 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
include: package:flutter_lints/flutter.yaml

dart_code_metrics:
extends:
- recommended
rules:
- prefer-single-widget-per-file: false
- avoid-unsafe-collection-methods: false
- avoid-shadowing: false
- avoid-missing-image-alt: false
- dispose-fields: false
- avoid-incomplete-copy-with: false
- prefer-prefixed-global-constants: false
- move-variable-closer-to-its-usage: false
- prefer-match-file-name: false
- avoid-unnecessary-gesture-detector: false
- avoid-equal-expressions: false
- prefer-correct-callback-field-name: false
- match-getter-setter-field-names: false
- avoid-undisposed-instances: false
- always-remove-listener: false
- avoid-empty-setstate: false
- no-empty-block: false
- avoid-dynamic: false
- avoid-duplicate-test-assertions: false
- prefer-correct-test-file-name: false
6 changes: 6 additions & 0 deletions coffee_maker/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
include: package:flutter_lints/flutter.yaml
#dart_code_metrics:
# extends:
# - recommended
# rules:
# - prefer-single-widget-per-file: false
# - avoid-unsafe-collection-methods: false
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class StoreOnlineStatusButton extends StatelessWidget {
builder: (_, isOnline, __) {
return OutlinedButton(
style: Theme.of(context).outlinedButtonTheme.style!.copyWith(
side: const MaterialStatePropertyAll(
side: const WidgetStatePropertyAll(
BorderSide(width: 2, color: WoltColors.gray)),
),
onPressed: () {
Expand Down
2 changes: 1 addition & 1 deletion coffee_maker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ publish_to: "none"

environment:
sdk: '>=2.19.2 <4.0.0'
flutter: '>=3.7.2'
flutter: '>=3.13.0'

dependencies:
flutter:
Expand Down
27 changes: 9 additions & 18 deletions coffee_maker_navigator_2/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,12 @@
# 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/lints.
#
# 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/guides/language/analysis-options
analyzer:
errors:
deprecated_member_use: ignore
#dart_code_metrics:
# extends:
# - recommended
# rules:
# - prefer-single-widget-per-file: false
# - avoid-unsafe-collection-methods: false
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AddWaterScreenBackButton extends StatelessWidget {
EdgeInsets.only(top: MediaQuery.paddingOf(context).top),
child: BackButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.white),
backgroundColor: WidgetStateProperty.all(Colors.white),
),
onPressed: Navigator.of(context).pop,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import 'package:demo_ui_components/demo_ui_components.dart';
import 'package:flutter/material.dart';

class WoltCircularElevatedButton extends StatelessWidget {
const WoltCircularElevatedButton(
{required this.onPressed, required this.icon, super.key});
const WoltCircularElevatedButton({
required this.onPressed,
required this.icon,
super.key,
});

final IconData icon;
final VoidCallback onPressed;
Expand Down
19 changes: 9 additions & 10 deletions demo_ui_components/lib/src/button/wolt_elevated_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,23 @@ class WoltElevatedButton extends StatelessWidget {
Widget build(BuildContext context) {
return ElevatedButton(
style: ButtonStyle(
foregroundColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
return states.contains(MaterialState.disabled)
foregroundColor: WidgetStateProperty.resolveWith(
(Set<WidgetState> states) {
return states.contains(WidgetState.disabled)
? theme.disabledForegroundColor(colorName)
: theme.enabledForegroundColor(colorName);
},
),
backgroundColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
return states.contains(MaterialState.disabled)
backgroundColor: WidgetStateProperty.resolveWith(
(Set<WidgetState> states) {
return states.contains(WidgetState.disabled)
? theme.disabledBackgroundColor(colorName)
: theme.enabledBackgroundColor(colorName);
},
),
overlayColor:
MaterialStateProperty.all<Color>(theme.splashColor(colorName)),
shadowColor: MaterialStateProperty.all<Color>(Colors.transparent),
shape: MaterialStateProperty.all<OutlinedBorder>(
overlayColor: WidgetStateProperty.all(theme.splashColor(colorName)),
shadowColor: WidgetStateProperty.all(Colors.transparent),
shape: WidgetStateProperty.all<OutlinedBorder>(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ class WoltModalSheetBackButton extends StatelessWidget {

String semanticsLabel(BuildContext context) {
return Localizations.of<MaterialLocalizations>(
context, MaterialLocalizations)
?.backButtonTooltip ??
context,
MaterialLocalizations,
)?.backButtonTooltip ??
const DefaultMaterialLocalizations().backButtonTooltip;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class WoltModalSheetCloseButton extends StatelessWidget {

String semanticsLabel(BuildContext context) {
return Localizations.of<MaterialLocalizations>(
context, MaterialLocalizations)
?.closeButtonLabel ??
context,
MaterialLocalizations,
)?.closeButtonLabel ??
const DefaultMaterialLocalizations().closeButtonLabel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class WoltSelectionList<T> extends StatefulWidget {
tileCrossAxisAlignment: tileCrossAxisAlignment,
selectionListType: WoltSelectionListType.singleSelect,
onSelectionUpdateInWoltSelectionList: (selectedValues, updatedItemData) {
onSelectionUpdateInSingleSelectionList.call(updatedItemData);
onSelectionUpdateInSingleSelectionList(updatedItemData);
},
);
}
Expand All @@ -98,8 +98,10 @@ class WoltSelectionList<T> extends StatefulWidget {
tileCrossAxisAlignment: tileCrossAxisAlignment,
selectionListType: WoltSelectionListType.multiSelect,
onSelectionUpdateInWoltSelectionList: (selectedValues, updatedItemData) {
onSelectionUpdateInMultiSelectionList.call(
selectedValues, updatedItemData);
onSelectionUpdateInMultiSelectionList(
selectedValues,
updatedItemData,
);
},
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,31 @@ class WoltSelectionListItemDataGroup<T> {
required WoltSelectionListType selectionListType,
required bool isSelected,
}) {
final element = group.elementAt(index);
List<WoltSelectionListItemData<T>> updatedGroup;

switch (selectionListType) {
case WoltSelectionListType.multiSelect:
updatedGroup = List<WoltSelectionListItemData<T>>.of(group);
final element = group.elementAt(index);
updatedGroup[index] = element.copyWith(isSelected: isSelected);
break;
case WoltSelectionListType.singleSelect:
updatedGroup = group.map((item) {
final selectedIndex = group.indexOf(item);

return item.copyWith(
isSelected: index == selectedIndex ? isSelected : false);
isSelected: index == selectedIndex ? isSelected : false,
);
}).toList();
break;
}

return WoltSelectionListItemDataGroup<T>(group: updatedGroup);
return WoltSelectionListItemDataGroup(group: updatedGroup);
}

WoltSelectionListItemDataGroup<T> copyWith(
List<WoltSelectionListItemData<T>>? group) {
return WoltSelectionListItemDataGroup<T>(group: group ?? this.group);
List<WoltSelectionListItemData<T>>? group,
) {
return WoltSelectionListItemDataGroup(group: group ?? this.group);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class _WoltSelectionListTileState<T> extends State<WoltSelectionListTile<T>> {
void _onTap() {
setState(() {
_isSelected = !_isSelected;
widget.onSelected.call(_isSelected);
widget.onSelected(_isSelected);
});
}

Expand Down Expand Up @@ -96,13 +96,17 @@ class _WoltSelectionListTileState<T> extends State<WoltSelectionListTile<T>> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(_data.title,
style: Theme.of(context).textTheme.bodyLarge!),
Text(
_data.title,
style: Theme.of(context).textTheme.bodyLarge!,
),
if (subtitle != null) ...[
const SizedBox(height: 4),
Text(subtitle,
style: Theme.of(context).textTheme.bodyMedium),
]
Text(
subtitle,
style: Theme.of(context).textTheme.bodyMedium,
),
],
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class RadioTrailing extends StatelessWidget {
padding: EdgeInsets.all(4),
child: DecoratedBox(
decoration: ShapeDecoration(
color: WoltColors.blue, shape: CircleBorder()),
color: WoltColors.blue,
shape: CircleBorder(),
),
),
)
: const SizedBox.expand(),
Expand All @@ -81,7 +83,8 @@ class _TrailingDecoration extends StatelessWidget {
decoration: BoxDecoration(
color: fillColor,
border: const Border.fromBorderSide(
BorderSide(color: WoltColors.blue, width: 2)),
BorderSide(color: WoltColors.blue, width: 2),
),
shape: BoxShape.circle,
),
child: SizedBox.fromSize(size: Size.square(trailingSize), child: child),
Expand Down
7 changes: 2 additions & 5 deletions demo_ui_components/lib/src/text/app_text_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class _AppTextFormFieldState extends State<AppTextFormField> {
),
if (errorText.isNotEmpty) ...[
const SizedBox(height: 12),
_FormFieldError(errorText)
_FormFieldError(errorText),
],
],
);
Expand Down Expand Up @@ -246,10 +246,7 @@ Color _cursorColor(bool invalid) {
return invalid ? WoltColors.red : WoltColors.blue;
}

Color _containerBorderColor({
required bool hasFocus,
required bool invalid,
}) {
Color _containerBorderColor({required bool hasFocus, required bool invalid}) {
if (invalid) {
return WoltColors.red64;
}
Expand Down
Loading
Loading