I could successfully integrate Sahi automation tool to SonarQube and could get the results but the issue is to define set of rules to report issues related to sahi script and find duplicate functions.

Here is the code snippet of Sahi

File name: sample1.sah

function eno_selectFromCombo($Field_Name, $Value) //Function name
{
    if($Value!="")
    {   
        _setStrictVisibilityCheck(true);
        if(_exists(_select($Field_Name)))
        {
            _assertEqual(false, _select($Field_Name).disabled)
            _setSelected(_select($Field_Name),$Value);
        }
        else
        {
            onScriptError($Field_Name + " doesn't exist ")
        }
        _setStrictVisibilityCheck(false);
    }
    else
    {   
        _log($Field_Name + " is set with default value")
    }
}

File name: sample2.sah

function eno_selectCombo($Field_Name, $Value) //Different function name but same set of code
    {
        if($Value!="")
        {   
            _setStrictVisibilityCheck(true);
            if(_exists(_select($Field_Name)))
            {
                _assertEqual(false, _select($Field_Name).disabled)
                _setSelected(_select($Field_Name),$Value);
            }
            else
            {
                onScriptError($Field_Name + " doesn't exist ")
            }
            _setStrictVisibilityCheck(false);
        }
        else
        {   
            _log($Field_Name + " is set with default value")
        }
    }

Same set of code copied over but with different name

For the above example,

  • How do I define rules to identify issues, if any?

    How do I find the duplicate function with same set of code but with different function name? This will help to reduce redundant functions

1

There are 1 best solutions below

2
Pierre-Yves On

Even if these files have references to external APIs, they seem to use a standard JavaScript syntax. You should be able to analyse such files with the SonarQube JavaScript plugin. If your files names end with "sah", you should have the following line in your sonar-project.properties:

sonar.javascript.file.suffixes=.js,.sah