<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: karthikeyan</title>
    <description>The latest articles on DEV Community by karthikeyan (@twt_karthikraja).</description>
    <link>https://dev.to/twt_karthikraja</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F389529%2Fae93b8a3-0e40-4ebe-933c-0108815680fa.jpg</url>
      <title>DEV Community: karthikeyan</title>
      <link>https://dev.to/twt_karthikraja</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/twt_karthikraja"/>
    <language>en</language>
    <item>
      <title>Flutter continuous code inspection with Sonarqube</title>
      <dc:creator>karthikeyan</dc:creator>
      <pubDate>Mon, 13 Jul 2020 12:20:44 +0000</pubDate>
      <link>https://dev.to/twt_karthikraja/flutter-continuous-code-inspection-with-sonarqube-3din</link>
      <guid>https://dev.to/twt_karthikraja/flutter-continuous-code-inspection-with-sonarqube-3din</guid>
      <description>&lt;h1&gt;
  
  
  Prerequisites
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;DartAnalyzer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The dartanalyzer command performs the same static analysis that you get when you use an IDE or editor that has Dart support. You can customize the analysis using an analysis options file or special comments in Dart source code.&lt;/p&gt;

&lt;p&gt;Here’s an example of performing static analysis over all the Dart files under the lib, test, and web directories:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dartanalyzer lib test web&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Dart is downloaded by the Flutter SDK in $FLUTTER_HOME/bin/cache/dart-sdk, however, command lines are not on the path by default (dartanalyzer must be on the path).&lt;/p&gt;

&lt;p&gt;It is recommended to install Dart SDK separately for more reliability in a CI/CD environment.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Flutter SDK&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Install Flutter as explained on the official documentation page.&lt;/p&gt;

&lt;h1&gt;
  
  
  SonarQube Installation
&lt;/h1&gt;

&lt;p&gt;SonarQube is an open-source platform for continuous inspection of code quality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using Docker:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The images of the Community, Developer, and Enterprise Editions are available on Docker Hub &lt;a href="https://hub.docker.com/_/sonarqube"&gt;https://hub.docker.com/_/sonarqube&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start the server by running:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;$ docker run -d --name sonarqube -p 9000:9000 &amp;lt;image_name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log in to &lt;a href="http://localhost:9000"&gt;http://localhost:9000&lt;/a&gt; with System Administrator credentials (login=admin, password=admin).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Advanced configuration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The sonarqube doesn't own a plugin for analyzing dart language and flutter test reports. So we require a custom made plugin (jar) added to sonarqube extensions.&lt;/p&gt;

&lt;p&gt;A plugin to enable an analysis of Dart and Flutter projects into SonarQube is available below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/insideapp-oss/sonar-flutter/releases/download/0.2.1/sonar-flutter-plugin-0.2.1.jar"&gt;https://github.com/insideapp-oss/sonar-flutter/releases/download/0.2.1/sonar-flutter-plugin-0.2.1.jar&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Customized image8&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In some environments, it may make more sense to prepare a custom image containing your configuration. A Dockerfile to achieve this may be as simple as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dockerfile
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM sonarqube

COPY sonar-flutter-plugin-0.2.1.jar   /opt/sonarqube/extensions/plugins

* Build &amp;amp; Run

sudo docker build --tag sonarq .

sudo docker run -d -p 9000:9000 sonarq
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Sonar Scanner
&lt;/h1&gt;

&lt;p&gt;The SonarScanner is the scanner to use when there is no specific scanner for your build system.&lt;/p&gt;

&lt;p&gt;Source: &lt;a href="https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.3.0.2102-linux.zip"&gt;https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.3.0.2102-linux.zip&lt;/a&gt;&lt;br&gt;
Installation:&lt;/p&gt;

&lt;p&gt;Expand the downloaded file into the directory of your choice. We'll refer to it as $install_directory in the next steps.&lt;br&gt;
Update the global settings to point to your SonarQube server by editing $install_directory/conf/sonar-scanner.properties:&lt;/p&gt;

&lt;p&gt;`* Default SonarQube server&lt;br&gt;
sonar.host.url=&lt;a href="http://localhost:9000"&gt;http://localhost:9000&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the $install_directory/bin directory to your path.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;export PATH = "$PATH:/$HOME/sonar-scanner/bin"`&lt;/p&gt;

&lt;p&gt;Verify your installation by opening a new shell and executing the command sonar-scanner -h (sonar-scanner.bat -h on Windows).&lt;/p&gt;

&lt;p&gt;You should get output like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;usage: sonar-scanner [options]

Options:

-D,--define &amp;lt;arg&amp;gt; Define property
-h,--help Display help information
-v,--version Display version information
-X,--debug Produce execution debug output
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Sonar Configuration
&lt;/h1&gt;

&lt;p&gt;Create a sonar-project.properties file at the root of the project :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project identification&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sonar.projectKey=flutter_sample
sonar.projectName=Flutter Sample
sonar.projectVersion=1.0 
Source code location.
Path is relative to the sonar-project.properties file. Defaults to .
Use commas to specify more than one folder.
sonar.sources=lib
sonar.tests=test 
Encoding of the source code. Default is default system encoding.
sonar.sourceEncoding=UTF-8 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Run Analysis
&lt;/h1&gt;

&lt;p&gt;Use the following commands from the root folder to start an analysis:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Download dependencies &lt;br&gt;
flutter pub get &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run tests&lt;br&gt;
flutter test --machine &amp;gt; tests.output&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Compute coverage (--machine and --coverage cannot be run at once...)&lt;br&gt;
flutter test --coverage&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run the analysis and publish to the SonarQube server&lt;br&gt;
sonar-scanner&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Output:
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Lk__U6xj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/icyvnz4wig6bljwrmbzv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Lk__U6xj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/icyvnz4wig6bljwrmbzv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R2Cgrhqg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/u0d3vnucv80ef5druzni.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R2Cgrhqg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/u0d3vnucv80ef5druzni.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://dart.dev/tools/dartanalyzer"&gt;https://dart.dev/tools/dartanalyzer&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.sonarqube.org/"&gt;https://www.sonarqube.org/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/"&gt;https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.sonarqube.org/latest/setup/get-started-2-minutes/"&gt;https://docs.sonarqube.org/latest/setup/get-started-2-minutes/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://hub.docker.com/_/sonarqube"&gt;https://hub.docker.com/_/sonarqube&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/insideapp-oss/sonar-flutter"&gt;https://github.com/insideapp-oss/sonar-flutter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>sonarqube</category>
    </item>
  </channel>
</rss>
