Support for Ballerina Lang

Hi All,
I am currently working on creating support for Ballerina lang into code scanners.
is there any extension model in SonarCloud to onboard third party language?


Welcome to the community!

Sorry but there’s no way to add a plugin to SonarCloud. What you can do is write an analyzer that

And then feed that report into your SonarCloud analysis.


First of all, thank you for your timely response Ann,

After extensive research, I’ve decided to create a SonarQube Plugin to support Ballerina Static Code Analysis, focusing on SonarQube 9.9 LTS.

In my research, I found three primary approaches to implement a language plugin in SonarQube:

Approach 1 - Using SSLR:

Used in the SonarQube Python Plugin, it involves creating a lexer and parser for a new language to then perform the static code analysis.

Approach 2 - Using SLang:

As seen in the SonarQube Golang Plugin, this method involves two essential steps before checks are applied. Firstly, the source code is converted to SLang-specific tokens using the ‘sonar-go-to-slang’ executable. Then, the generated JSON token structure is processed through the SLang JSON tree function, effectively transforming the Go syntax into SLang syntax before conducting the analysis. The rules in SLang are implemented using SLang-specific trees. While I haven’t delved deeply into the intricacies of the scanning process with tree-based checks, it’s clear that SLang functions by converting language-specific keywords to generic keywords.

Approach 3 - Using Sonar Plugin API:

This is the approach employed by the SonarQube Kotlin Plugin, which uses language-specific PSI-based keywords. Furthermore it doesn’t involve any intermediate conversions like in SLang. The checks have been implemented using Kotlin-specific ,PSI-based keywords.

I’m currently inclined towards the third approach, given Ballerina’s visitor capabilities.

However I would like to understand why Golang was implemented using SLang, in contrast to the Kotlin plugin. Are there any distinct advantages to implementing a third-party language plugin using the SLang-based approach as used for the Golang plugin, or is it more advantageous to adopt the Kotlin plugin’s methodology?

I’d greatly appreciate any corrections to my findings and additional insights into the rationale behind the different implementation approaches for the Kotlin and Golang plugins.

Furthermore, please categorize this post under SonarQube, as my primary focus will be on creating SonarQube-based static code analysis support for Ballerina Language.


1 Like

Hi @Xenowa ,

Well done, you have researched quite thoroughly the subject. First, some advice, generally more specific is better and you don’t want to implement the parser yourself as it doesn’t provide a lot of value. We only implemented the Python parser ourselves, because we didn’t find any that satisfied our needs.

Concerning Golang, Slang was an experiment to have only one analyzer for several different languages, so has to reuse some of the logic between them. We decided to include in Slang language that we thought nice to have, but were not our main priority.

For you, I think the best is to follow the Kotlin plugin.

Best of luck with your Plugin for Ballerina,


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.