Specialized Sonar JavaScript plugin rule designed to identify specific method calls throughout various source files

In my quest to develop a specialized rule for the Sonar javascript plugin, I am focusing on verifying whether an init() function is invoked within a set of JS source files. To kick things off, I subscribe to call expressions:

public void init() {
    subscribeTo(EcmaScriptGrammar.CALL_EXPRESSION);
}

My next step involves confirming the invocation of the init() function by modifying the visitNode method:

public void visitNode(AstNode node){
    String functionCall=new String();
    List<Token> tokens = node.getTokens();
    for(int i=0; i<tokens.size(); i++){
       functionCall+=tokens.get(i).getValue();
    }
    if(functionCall.equals("init()"))
        callMade=true;
}

To wrap things up, as I exit the file, I flag a violation if init() hasn't been called:

public void leaveFile(AstNode node){
    if(!callMade)
        getContext().createLineViolation(this,"No call to init()",node);
}

While this approach works effectively, it generates violations for every JS source file that lacks an init() call. My goal is to trigger a violation only if init() is not invoked in any of the JS source files. How can I make this happen?

Answer №1

Unfortunately, this cannot be achieved at the current moment.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

If you want to obtain a result of 1.0f when adding negative zero floats, you must utilize a specialized

After performing calculations on two vectors a = (-0, -0, -5) and b = (0, 1, 0) using my custom Vector class, the result obtained was 1, which should have been 0. Interestingly, when I switched to using PVector, the calculation worked correctly. Upon inspe ...

There was an issue with the task ':app:dexDebug' that led to an execution failure. The error was caused by a process exception within the org.gradle.process.internal.ExecException

I'm encountering the following issue when trying to run my project. Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Lib ...

Potential Cross-Origin Resource Sharing (CORS) problem arises when integrating Node Express with an Ionic

Currently, I have an Ionic application that communicates with a Node Express application using Restangular. Everything works smoothly when the Node Express server is configured to use HTTP. On the Ionic app side: RestangularProvider.setBaseUrl('http ...

"Mastering the art of displaying real-time data on a thermometer using D3.js

Welcome to the sample code for a thermometer created using D3.js. You can view the code on jsfiddle. I've developed a web page displaying a dynamic thermometer with values updating every second. Here's the function: setInterval(function(){ getN ...

Execute Javascript after modification of the DOM

I have developed two custom directives known as app-content and app-content-item. These directives are intended to be utilized in upcoming projects to provide a basic structure with simple styling. They will be incorporated into a module and should be nest ...

What could be causing the erratic jumping behavior of the "newsletter sign-up" form within my modal dialog window?

On the homepage, there is a modal window that appears upon every pageload (it will be changed later), however, there seems to be an issue with the 'email sign up' form inside the window. The form seems to momentarily display at the top of the si ...

I'm trying to reverse the order of my array, but for some reason the collections aren't working correctly

Below is the code snippet that I am having trouble with: public void p10(int a, int b, int c){ int[] nums = new int[] {a, b, c}; Arrays.sort(nums, Collections.reverseOrder()); System.out.println(Arrays.toString(nums)); } I am encountering an e ...

Is it possible to enable users to download files in addition to displaying JSON data in the browser via Spring REST call?

I am currently working on a basic REST call /** * REST CALL * @return */ @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public List<Template> getTemplatesJson(){ logger.info("GET all computers- /compu ...

What is the best way to replicate touch functionality on mobile browsers for both Android and iPhone devices?

Recently, while developing a web application, I ran into an issue on mobile browsers where the :active pseudo class wasn't functioning properly. I am currently utilizing CSS sprites and looking for guidance on how to simulate clicks for mobile browser ...

Retrieve information from a pair of models

Hey there, I need some help. Can someone please guide me on how to obtain the 'topics' array and append it to res.view()? I've tried multiple approaches but keep getting 'undefined' in the 'topics' array. Subjects.qu ...

What should be used for data fetching in Next.js: SWR or traditional fetch/axios along with useEffect?

I'm currently diving into the world of Next.js and I'm eager to showcase data based on user input queries. However, I'm uncertain if leveraging useSWR is the most suitable approach to tackle this challenge because I haven't come across ...

The div in JavaScript is expanding properly, but it is not contracting back as expected

I'm experiencing an issue with a div element that I created. My goal is to have it expand when a link is clicked and collapse when the same link is clicked again. At the moment, the div expands correctly but does not collapse as expected. Any assistan ...

JavaScript - the global and local variable dilemma

REVISED2: I'm encountering an issue with converting images to canvas using Pixastic in HTML5. How can I 'return' this converted image back to a global variable? Any suggestions? <img id="mainIllustration" alt="main illustration" src="Img ...

Use Node-RED to fetch JSON or CSV data and store it in InfluxDB

Versions Node-RED v0.16.2 InfluxDB v1.2.2 Grafana v4.2.0 Ubuntu 16.04.2 I'm looking to access weather data from a local official weather station. The options available are in either csv or JSON format. I am attempting to retrieve the JSON feed us ...

The window fails to load properly after building, but functions perfectly while in development server mode

My application is not displaying a window after it's built, but it works perfectly fine when I execute npm run serve Even though there is a process running in the task manager, the same issue persists if I try using the installer. I'm not receiv ...

Guide on accessing the text content within a div element in HTML by triggering a button click

To extract specific text from multiple div tags, I need to trigger an event when clicking a button. <div class="col-lg-3 col-md-6 mb-4"> <div class="pricing-table pricing-secondary"> <div class="price-hea ...

In TypeScript, maximize the capabilities of JavaScript modules by utilizing the import extension

Incorporating the dynamo-cache package from NPM into my TypeScript project has been a bit of a challenge. Essentially, this module introduces a new method to the AWS.DynamoDB.DocumentClient: AWS.DynamoDB.DocumentClient.prototype.configCache = function(con ...

What is the clarification on AngularJs' ng-options?

In my demo, I have a small setup. Essentially, it consists of a select element with the following data: address: { select: { code: "0", name: "Select proof of address" }, letter: { ...

Leveraging the flexibility of an undefined variable as a useEffect dependency

Summary: Need help using listRef.current.clientWidth as a dependency in useEffect. I'm working on creating a dynamic list that automatically adjusts the width of its items based on the list's width. I've almost got it working, but I'm ...

Enhance your 3D models with react-three-fiber's canvas modification capabilities

I am looking to modify the model function within the canvas. Currently, I have two separate Models (functions in js files) named Model1 and Model2. Both Models have the ability to outline the mesh when hovered over. The existing code structure is as follow ...