From f3765cf054823440d5cae35309116ddc6a3b1b87 Mon Sep 17 00:00:00 2001 From: Aditya Chavda Date: Mon, 20 May 2024 18:40:26 +0530 Subject: [PATCH] :sparkles: Bad Code Example --- .github/workflows/code-quality.yaml | 21 +++- lib/bad_example.dart | 152 ++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 lib/bad_example.dart diff --git a/.github/workflows/code-quality.yaml b/.github/workflows/code-quality.yaml index b539b94..6ced8c3 100644 --- a/.github/workflows/code-quality.yaml +++ b/.github/workflows/code-quality.yaml @@ -28,10 +28,29 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Run DCM + - name: Run DCM Analyze uses: CQLabs/dcm-action@v1.0.8 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 diff --git a/lib/bad_example.dart b/lib/bad_example.dart new file mode 100644 index 0000000..9a13954 --- /dev/null +++ b/lib/bad_example.dart @@ -0,0 +1,152 @@ +import 'package:flutter/material.dart'; + +class BadFlutterExample extends StatefulWidget { + @override + State createState() => _BadFlutterExampleState(); +} + +class _BadFlutterExampleState extends State { + // Many parameters + void doSomething(int a, int b, int c, int d, int e) { + if (e > 100) return; + 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'); + } + } + + 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); + } + + @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(); + } +}