Skip to content
Open
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
21 changes: 20 additions & 1 deletion .github/workflows/code-quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,29 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Run DCM
- name: Run DCM Analyze
uses: CQLabs/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
github_pat: ${{ secrets.PAT }}
ci_key: ${{ secrets.DCM_CI_KEY }}
email: ${{ secrets.DCM_EMAIL }}

- name: Run DCM Code Duplication
run: dcm check-code-duplication --ci-key="${{ secrets.DCM_CI_KEY }}" --email="${{ secrets.DCM_EMAIL }}" lib

- name: Run DCM Check Parameters
run: dcm check-parameters --ci-key="${{ secrets.DCM_CI_KEY }}" --email="${{ secrets.DCM_EMAIL }}" lib --monorepo

- name: Run DCM Check Unused Code & Files
run: dcm check-unused-code --ci-key="${{ secrets.DCM_CI_KEY }}" --email="${{ secrets.DCM_EMAIL }}" lib --monorepo
- run: dcm check-unused-files --ci-key="${{ secrets.DCM_CI_KEY }}" --email="${{ secrets.DCM_EMAIL }}" lib --monorepo

- name: Run DCM Check Dependencies
run: dcm check-dependencies --ci-key="${{ secrets.DCM_CI_KEY }}" --email="${{ secrets.DCM_EMAIL }}" lib

- name: Run DCM Metrics Calculation
run: dcm calculate-metrics --ci-key="${{ secrets.DCM_CI_KEY }}" --email="${{ secrets.DCM_EMAIL }}" lib --reporter=html

- name: Run DCM Widget Analyses
run: dcm analyze-widgets --ci-key="${{ secrets.DCM_CI_KEY }}" --email="${{ secrets.DCM_EMAIL }}" lib --reporter=html
152 changes: 152 additions & 0 deletions lib/bad_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import 'package:flutter/material.dart';

class BadFlutterExample extends StatefulWidget {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming the class to match the file name or vice versa to improve clarity and maintainability.


Consider adding a const constructor to improve performance by allowing widgets to be compile-time constants when possible.

@override
State<BadFlutterExample> createState() => _BadFlutterExampleState();
}

class _BadFlutterExampleState extends State<BadFlutterExample> {
// Many parameters
void doSomething(int a, int b, int c, int d, int e) {
if (e > 100) return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting magic numbers into named constants for better readability and maintainability.

Also applies to: 72-72, 83-83, 84-84

if (a > 0) {
if (b > 0) {
if (c > 0) {
if (d > 0) {
print('All positive');
} else {
print('d is not positive');
}
} else {
print('c is not positive');
}
} else {
print('b is not positive');
}
} else {
print('a is not positive');
}
}
Comment on lines +10 to +29

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doSomething method has a deeply nested structure due to multiple if statements, which makes it hard to read and maintain. Consider refactoring this method to reduce nesting, possibly by using early returns or extracting methods. This will improve the readability and maintainability of the code.


void method1() {
print('method1');
}

void method2() {
print('method2');
}

void method3() {
print('method3');
}

void method4() {
print('method4');
}

void method5() {
print('method5');
}

void method6() {
print('method6');
}

void method7() {
print('method7');
}

void method8() {
print('method8');
}

void method9() {
print('method9');
}

void method10() {
print('method10');
}

void complexMethod() {
doSomething(1, 2, 3, 4, 5);
method1();
method2();
method3();
method4();
method5();
method6();
method7();
method8();
method9();
method10();
doSomething(1, 2, 3, 4, 5);
doSomething(1, 2, 3, 4, 5);
}
Comment on lines +71 to +85

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The complexMethod method sequentially calls multiple methods, including doSomething three times with the same arguments, which could indicate unnecessary repetition or a lack of abstraction. If the intention is to perform a series of operations that are logically related, consider encapsulating these operations within a more appropriately named method or class that clearly defines their purpose. This will enhance the modularity and clarity of the code.


@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Bad Flutter Example'),
),
body: SingleChildScrollView(
child: Column(
children: [
for (int i = 0; i < 10; i++)
Container(
margin: EdgeInsets.all(10),
child: Column(
children: [
Row(
children: [
Text('Item $i'),
Icon(Icons.star),
ElevatedButton(
onPressed: () {},
child: Text('Button $i'),
),
],
),
],
),
),
Text('Counter: 0'),
ElevatedButton(
onPressed: () {
complexMethod();
},
child: Text('Do Something'),
),
for (int i = 0; i < 10; i++)
Container(
margin: EdgeInsets.all(10),
child: Column(
children: [
Row(
children: [
Text('Item $i'),
Icon(Icons.star),
ElevatedButton(
onPressed: () {},
child: Text('Button $i'),
),
],
),
],
),
),
],
),
),
);
}

void testMethod() {
method1();
method2();
method3();
method4();
method5();
}
}
Comment on lines +1 to +152

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Description: Nested if statements make the code hard to read and understand
  • Impact: Reduced maintainability and potential for bugs
  • Recommendation: Use a single if statement with logical operators: void doSomething(int a, int b, int c, int d, int e) {
    if (e > 100 || a <= 0 || b <= 0 || c <= 0 || d <= 0) return;
    print('All positive');
    }

Comment on lines +1 to +152

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Description: Redundant code duplication
  • Impact: Wastes space and increases maintenance effort
  • Recommendation: Refactor into a helper method: void doSomething(int a, int b, int c, int d, int e) {
    if (isPositive(e) && isPositive(a) && isPositive(b) && isPositive(c) && isPositive(d)) {
    print('All positive');
    }
    }

bool isPositive(int value) => value > 0;

Comment on lines +1 to +152

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Description: No null check on user.displayName, potential runtime error.
  • Impact: If the 'user' object is null, accessing its 'displayName' property will cause a runtime error. This violates Dart's null safety principles.
  • Recommendation: Add a null check before accessing user.displayName. For example: final String userName = user?.displayName ?? 'Guest';
  • Severity: High