Need a linter check script to get scan the syntax "gs.getMessage("yyyy-mm-dd") from all the scripts

Naman Srivastav
Tera Contributor
Need a linter check script to get scan the syntax "gs.getMessage("yyyy-mm-dd") from all the scripts it is running for the "gs" but  not for the "'yyyy-mm-dd" and getMessage("yyyy-mm-dd"), please help me with the script to scan the findings as I am trying from script include or please modify the given below script. please help me out with this
 
 
 
(function(engine) {

    engine.rootNode.visit(function(node) {

   if(node.getTypeName() === "NAME" &&
           node.getNameIdentifier() === 'yyyy-MM-dd') {
           
            {
                engine.finding.incrementWithNode(node);
            }
        }
    });
})(engine);
1 ACCEPTED SOLUTION

Aniket Chavan
Tera Sage
Tera Sage

Hello @Naman Srivastav ,

You can give a try to the script below and see how it works for you.

(function(engine) {
    engine.rootNode.visit(function(node) {
        if (
            node.getTypeName() === "STRING" &&
            node.getParent() &&
            node.getParent().getTypeName() === "CALL" &&
            node.getParent().getFirstChild() &&
            node.getParent().getFirstChild().getTypeName() === "NAME" &&
            node.getParent().getFirstChild().getNameIdentifier() === "gs.getMessage" &&
            node.getValue() === 'yyyy-MM-dd'
        ) {
            engine.finding.incrementWithNode(node.getParent());
        }
    });
})(engine);

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket

View solution in original post

5 REPLIES 5

Aniket Chavan
Tera Sage
Tera Sage

Hello @Naman Srivastav ,

You can give a try to the script below and see how it works for you.

(function(engine) {
    engine.rootNode.visit(function(node) {
        if (
            node.getTypeName() === "STRING" &&
            node.getParent() &&
            node.getParent().getTypeName() === "CALL" &&
            node.getParent().getFirstChild() &&
            node.getParent().getFirstChild().getTypeName() === "NAME" &&
            node.getParent().getFirstChild().getNameIdentifier() === "gs.getMessage" &&
            node.getValue() === 'yyyy-MM-dd'
        ) {
            engine.finding.incrementWithNode(node.getParent());
        }
    });
})(engine);

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket

Naman Srivastav
Tera Contributor

Thank you for responding my question As you mentioned I used this script but it does not scan any findings as I used the syntax in the script include I have also included a screenshot of no findings with the script include 

 

@Naman Srivastav , Oh okay then lets give a try to the below modified script and let me know how it works for you.

(function(engine) {
    engine.rootNode.visit({
        visitNode: function(node, e, c) {
            // Check if the node is a string, part of gs.getMessage, and has the value 'yyyy-MM-dd'
            if (
                node.getTypeName() === "STRING" &&
                node.getParent() &&
                node.getParent().getTypeName() === "CALL" &&
                node.getParent().getFirstChild() &&
                node.getParent().getFirstChild().getTypeName() === "NAME" &&
                node.getParent().getFirstChild().getNameIdentifier() === "gs.getMessage" &&
                node.getValue() === 'yyyy-MM-dd'
            ) {
                engine.finding.increment(node, "Avoid using 'yyyy-MM-dd' as a parameter in gs.getMessage");
            }

            c(node.getChildren());
        }
    });
})(engine);

Naman Srivastav
Tera Contributor

@Aniket Chavan thanks for helping me with the scripts, I ran the given script now it is showing failure with the given error as "Rhino error: java.lang.NullPointerException" I have shared the screenshot, and again thanks for looking into my problem.

 

sp.PNG