Skip to content

Commit f3765cf

Browse files
committed
✨ Bad Code Example
1 parent 0701709 commit f3765cf

File tree

2 files changed

+172
-1
lines changed

2 files changed

+172
-1
lines changed

.github/workflows/code-quality.yaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,29 @@ jobs:
2828
with:
2929
github_token: ${{ secrets.GITHUB_TOKEN }}
3030

31-
- name: Run DCM
31+
- name: Run DCM Analyze
3232
uses: CQLabs/[email protected]
3333
with:
3434
github_token: ${{ secrets.GITHUB_TOKEN }}
3535
github_pat: ${{ secrets.PAT }}
3636
ci_key: ${{ secrets.DCM_CI_KEY }}
3737
email: ${{ secrets.DCM_EMAIL }}
38+
39+
- name: Run DCM Code Duplication
40+
run: dcm check-code-duplication --ci-key="${{ secrets.DCM_CI_KEY }}" --email="${{ secrets.DCM_EMAIL }}" lib
41+
42+
- name: Run DCM Check Parameters
43+
run: dcm check-parameters --ci-key="${{ secrets.DCM_CI_KEY }}" --email="${{ secrets.DCM_EMAIL }}" lib --monorepo
44+
45+
- name: Run DCM Check Unused Code & Files
46+
run: dcm check-unused-code --ci-key="${{ secrets.DCM_CI_KEY }}" --email="${{ secrets.DCM_EMAIL }}" lib --monorepo
47+
- run: dcm check-unused-files --ci-key="${{ secrets.DCM_CI_KEY }}" --email="${{ secrets.DCM_EMAIL }}" lib --monorepo
48+
49+
- name: Run DCM Check Dependencies
50+
run: dcm check-dependencies --ci-key="${{ secrets.DCM_CI_KEY }}" --email="${{ secrets.DCM_EMAIL }}" lib
51+
52+
- name: Run DCM Metrics Calculation
53+
run: dcm calculate-metrics --ci-key="${{ secrets.DCM_CI_KEY }}" --email="${{ secrets.DCM_EMAIL }}" lib --reporter=html
54+
55+
- name: Run DCM Widget Analyses
56+
run: dcm analyze-widgets --ci-key="${{ secrets.DCM_CI_KEY }}" --email="${{ secrets.DCM_EMAIL }}" lib --reporter=html

lib/bad_example.dart

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
import 'package:flutter/material.dart';
2+
3+
class BadFlutterExample extends StatefulWidget {
4+
@override
5+
State<BadFlutterExample> createState() => _BadFlutterExampleState();
6+
}
7+
8+
class _BadFlutterExampleState extends State<BadFlutterExample> {
9+
// Many parameters
10+
void doSomething(int a, int b, int c, int d, int e) {
11+
if (e > 100) return;
12+
if (a > 0) {
13+
if (b > 0) {
14+
if (c > 0) {
15+
if (d > 0) {
16+
print('All positive');
17+
} else {
18+
print('d is not positive');
19+
}
20+
} else {
21+
print('c is not positive');
22+
}
23+
} else {
24+
print('b is not positive');
25+
}
26+
} else {
27+
print('a is not positive');
28+
}
29+
}
30+
31+
void method1() {
32+
print('method1');
33+
}
34+
35+
void method2() {
36+
print('method2');
37+
}
38+
39+
void method3() {
40+
print('method3');
41+
}
42+
43+
void method4() {
44+
print('method4');
45+
}
46+
47+
void method5() {
48+
print('method5');
49+
}
50+
51+
void method6() {
52+
print('method6');
53+
}
54+
55+
void method7() {
56+
print('method7');
57+
}
58+
59+
void method8() {
60+
print('method8');
61+
}
62+
63+
void method9() {
64+
print('method9');
65+
}
66+
67+
void method10() {
68+
print('method10');
69+
}
70+
71+
void complexMethod() {
72+
doSomething(1, 2, 3, 4, 5);
73+
method1();
74+
method2();
75+
method3();
76+
method4();
77+
method5();
78+
method6();
79+
method7();
80+
method8();
81+
method9();
82+
method10();
83+
doSomething(1, 2, 3, 4, 5);
84+
doSomething(1, 2, 3, 4, 5);
85+
}
86+
87+
@override
88+
Widget build(BuildContext context) {
89+
return Scaffold(
90+
appBar: AppBar(
91+
title: Text('Bad Flutter Example'),
92+
),
93+
body: SingleChildScrollView(
94+
child: Column(
95+
children: [
96+
for (int i = 0; i < 10; i++)
97+
Container(
98+
margin: EdgeInsets.all(10),
99+
child: Column(
100+
children: [
101+
Row(
102+
children: [
103+
Text('Item $i'),
104+
Icon(Icons.star),
105+
ElevatedButton(
106+
onPressed: () {},
107+
child: Text('Button $i'),
108+
),
109+
],
110+
),
111+
],
112+
),
113+
),
114+
Text('Counter: 0'),
115+
ElevatedButton(
116+
onPressed: () {
117+
complexMethod();
118+
},
119+
child: Text('Do Something'),
120+
),
121+
for (int i = 0; i < 10; i++)
122+
Container(
123+
margin: EdgeInsets.all(10),
124+
child: Column(
125+
children: [
126+
Row(
127+
children: [
128+
Text('Item $i'),
129+
Icon(Icons.star),
130+
ElevatedButton(
131+
onPressed: () {},
132+
child: Text('Button $i'),
133+
),
134+
],
135+
),
136+
],
137+
),
138+
),
139+
],
140+
),
141+
),
142+
);
143+
}
144+
145+
void testMethod() {
146+
method1();
147+
method2();
148+
method3();
149+
method4();
150+
method5();
151+
}
152+
}

0 commit comments

Comments
 (0)