-
Notifications
You must be signed in to change notification settings - Fork 0
✨ Bad Code Example #2
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| class BadFlutterExample extends StatefulWidget { | ||
| @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; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| @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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Comment on lines
+1
to
+152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
bool isPositive(int value) => value > 0;
Comment on lines
+1
to
+152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
There was a problem hiding this comment.
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.