SQL language (T-SQL, MySQL, Snowflake, Vertica and PostgreSQL dialects) plugin for SonarQube
SQL language (T-SQL, MySQL, PostgreSQL, Snowflake and Vertica SQL dialects) plugin for SonarQube
You can support this project and others via Paypal
Currently plug-in supports:
Tutorials:
Different plugin versions supports the following:
Please see examples on how to use different dialects.
Sonar settings for tsql. You can check example at here
sonar.projectKey=examples.sql.mysql.project
sonar.projectName=examples.sql.mysql.project
sonar.projectVersion=1.1
sonar.sources=src
# optional
sonar.language=sql
# optional as plugin defaults to tsql
sonar.sql.dialect=tsql
Sonar settings for pssql. You can check example at here
sonar.projectKey=examples.sql.psql.project
sonar.projectName=examples.sql.psql.project
sonar.projectVersion=1.1
sonar.sources=src
# optional
sonar.language=sql
sonar.sql.dialect=pssqlv2
Sonar settings for mysql. You can check example at here
sonar.projectKey=examples.sql.mysql.project
sonar.projectName=examples.sql.mysql.project
sonar.projectVersion=1.1
sonar.sources=src
# optional
sonar.language=sql
sonar.sql.dialect=mysql
Sonar settings for vsql (Vertica SQL). You can check example at here
sonar.projectKey=examples.sql.vsql.project
sonar.projectName=examples.sql.vsql.project
sonar.projectVersion=1.1
sonar.sources=src
# optional
sonar.language=sql
sonar.sql.dialect=vsql
Sonar settings for snowflake. You can check example at here
sonar.projectKey=examples.sql.snowflake.project
sonar.projectName=examples.sql.snowflake.project
sonar.projectVersion=1.1
sonar.sources=src
# optional
sonar.language=sql
sonar.sql.dialect=snowflake
This is an example for sonar settings for project which uses custom plugin rules from local directory (located at ./rules directory). You can check full example at here
sonar.projectKey=pssql.custom.rules
sonar.projectName=Test PSSQL custom rules project
sonar.projectVersion=1.0
sonar.sources=src
# optional
sonar.language=sql
sonar.sql.dialect=pssqlv2
# change these
sonar.sql.rules.path=./rules
The following options are available for configuration:
Please configure additional properties:
When you want PLSQL plugin execution ( this will disable execution sql plugin):
sonar.lang.patterns.sql=na
When you want SQL plugin execution ( this will disable pssql plugin):
sonar.lang.patterns.plsqlopen=na
With the plugin - there is additional cli tool available (it does not require sonar execution):
Usage:
java -jar rulesHelper.jar
- will print helpjava -jar rulesHelper.jar print text "SELECT * FROM dbo.test;" tsql
- will print parsed AST tree for TSQL dialectFull help info:
Please pass the following:
action (print, verify or analyze)
type (text or file)
value (sql string or path to rules file/folder)
dialect (tsql, pssql, mysql, pssql, pssqlv2, snowflake)
folder (folder to analyze, only applicable when using analyze action)
Example to print AST tree:
print text "SELECT * FROM dbo.test;" tsql
Example to verify custom rules definitions:
verify file "c:/tests/customRules.rules;" mysql
Example to execute custom rules and plugin rules against specified folder:
analyze file "c:/tests/customRules.rules;" snowflake "c:\docs\src"
Example to execute sql analysis againt specified folder:
analyze file "NA" snowflake "c:\docs\src"
Run: mvn versions:display-dependency-updates spotless:check spotless:apply install
Added container definitions for easy development with VSCode. Download the remote containers extension and let it figure out the maven targets.
mkdir -p ~/workspace/sonarqube/extensions/plugins
cp ~/workspace/sonar-sql-plugin/src/sonar-sql-plugin/target/sonar-sql-plugin-1.1.0.jar ~/workspace/sonarqube/extensions/plugins
docker run -i --name sonarqube \
-p 9000:9000 \
-v ~/workspace/sonarqube/conf:/opt/sonarqube/conf \
-v ~/workspace/sonarqube/extensions:/opt/sonarqube/extensions \
-v ~/workspace/sonarqube/logs:/opt/sonarqube/logs \
-v ~/workspace/sonarqube/data:/opt/sonarqube/data \
sonarqube
docker start sonarqube
docker run \
--rm \
-e SONAR_HOST_URL="http://127.0.0.1:9000" \
-e SONAR_LOGIN="YOUR_ADMIN_TOKEN_HERE" \
-e SONAR_PASSWORD="YOUR_ADMIN_PWD_HERE" \
--network="host" \
-v "FOLDER_WITH_THE_CODE:/usr/src" \
sonarsource/sonar-scanner-cli -X
Example commit for adding Snowflake grammar: https://github.com/gretard/sonar-sql-plugin/commit/e3296a5d1c69a031f24358aad87a4e46c46ea785