Code reviews are one of my daily activities. To help me streamline the process, I like to use the help of static code analysis tools like NDepend and SonarQube.
While looking through the SonarQube logs for a specific project I noticed a large list of issues in a set of Javascript files. These Javascript files were external libraries (like jQuery) that were imported into the project and not created by the dev team. Fixing these issues would only be possible by sending a pull request to the library maintainers.
To stop the pollution of our SonarQube logs, I decided to exclude these files from the log analysis.
Here are the steps:
- Browse to your SonarQube dashboard.
- Login as an administrator.
- After being logged in, you can go to the Administration tab on the project level.
- Select Analysis Scope from the Category list.
- Go to the Files tab and add one or more Source File Exclusions.
- In our case we want to exclude the Scripts folder in our web project, so we add Scripts/** to the Source File Exclusions
- IMPORTANT: Source File Exclusions are case sensitive. First time I entered scripts/** which had no effect.
- Source File Exclusions are executed on the project level and applied for each csproj file individually:
2018-09-03T06:55:30.4158415Z INFO: ------------- Scan MTIL.Web
2018-09-03T06:55:30.4158415Z INFO: Base dir: D:\b\4\agent\_work\35\s\MTIL.Web
2018-09-03T06:55:30.4168180Z INFO: Working dir: D:\b\4\agent\_work\35\.sonarqube\out\.sonar\MTIL_MTIL_C301B249-2F5F-4264-B23F-FC169C8E7397
2018-09-03T06:55:30.4207240Z INFO: Source encoding: UTF-8, default locale: en_US
2018-09-03T06:55:30.4207240Z INFO: Index files
2018-09-03T06:55:30.4207240Z INFO: Excluded sources:
2018-09-03T06:55:30.4207240Z INFO: Scripts/**
2018-09-03T06:55:30.4431835Z INFO: Analyzer working directory contains 5 .pb file(s)
2018-09-03T06:55:30.5886820Z INFO: 40 files indexed
2018-09-03T06:55:30.5886820Z INFO: 14 files ignored because of inclusion/exclusion patterns
2018-09-03T06:55:30.5964940Z INFO: Quality profile for cs: Sonar way
2018-09-03T06:55:30.6238360Z INFO: Sensor Lines Sensor
2018-09-03T06:55:30.6248125Z INFO: Sensor Lines Sensor (done) | time=1ms
2018-09-03T06:55:30.6248125Z INFO: Sensor SCM Sensor
2018-09-03T06:55:30.6736375Z INFO: SCM provider for this project is: git
2018-09-03T06:55:30.6746140Z INFO: 1 files to be analyzed
2018-09-03T06:55:31.7077510Z WARNING: WARN: Missing blame information for the following files:
2018-09-03T06:55:31.7116570Z INFO: 0/1 files analyzed
2018-09-03T06:55:31.7184925Z INFO: Sensor SCM Sensor (done) | time=1034ms
2018-09-03T06:55:31.7184925Z INFO: Sensor C#
2018-09-03T06:55:31.7194690Z INFO: Importing analysis results from D:\b\4\agent\_work\35\.sonarqube\out\6\output-cs
2018-09-03T06:55:31.7194690Z WARNING: WARN: * D:/b/4/agent/_work/35/s/MTIL.Web/ErrorHandler/AiHandleErrorAttribute.cs
2018-09-03T06:55:31.7194690Z WARNING: WARN: This may lead to missing/broken features in SonarQube
2018-09-03T06:55:31.7809885Z INFO: Importing Roslyn report
2018-09-03T06:55:31.8151660Z INFO: Sensor C# (done) | time=155ms
2018-09-03T06:55:31.8151660Z INFO: Sensor C# Unit Tests Coverage Report Import
2018-09-03T06:55:31.8151660Z INFO: Sensor C# Unit Tests Coverage Report Import (done) | time=0ms
2018-09-03T06:55:31.8161425Z INFO: Sensor C# Integration Tests Coverage Report Import
2018-09-03T06:55:31.8161425Z INFO: Sensor C# Integration Tests Coverage Report Import (done) | time=0ms
2018-09-03T06:55:31.8161425Z INFO: Sensor C# Unit Test Results Import
2018-09-03T06:55:31.8161425Z INFO: Sensor C# Unit Test Results Import (done) | time=0ms
2018-09-03T06:55:31.8171190Z INFO: Sensor Zero Coverage Sensor
2018-09-03T06:55:31.8415315Z INFO: Sensor Zero Coverage Sensor (done) | time=14ms
2018-09-03T06:55:31.8415315Z INFO: Sensor Code Colorizer Sensor
2018-09-03T06:55:31.8415315Z INFO: Sensor Code Colorizer Sensor (done) | time=2ms
2018-09-03T06:55:31.8425080Z INFO: Sensor CPD Block Indexer
2018-09-03T06:55:31.8425080Z INFO: DefaultCpdBlockIndexer is used for cs
2018-09-03T06:55:31.8718030Z INFO: Sensor CPD Block Indexer (done) | time=1ms