The PhpStorm/JavaScript expression statement doesn't involve assignment or function call

I am striving to enhance the cleanliness of my method.

Based on the value of an integer number, I am generating different date formats, resulting in the following:


        getRanges() {
            var currentDate = new Date();
            //This can definitely be simplified
            const format = (format) => {
                this.formatedTimeRange.start = moment(new Date(currentDate.getTime() - this.timeRange * 60000), "YYYY-MM-DDTHH:mm:ss.SSSZ").format(format);
                this.formatedTimeRange.end = moment(new Date(this.linesData[0].x[this.linesData[0].x.length-1]), "YYYY-MM-DDTHH:mm:ss.SSSZ").format(format);
            }

            const Ranges = {
                '1': format("YYYY-MM-DD HH:mm:ss"),
                '5': format("YYYY-MM-DD HH:mm:ss"),
                '15': format("YYYY-MM-DD HH:mm:ss"),
                '60': format("YYYY-MM-DD HH:mm"),
                '180': format("YYYY-MM-DD HH:mm"),
                '360': format("YYYY-MM-DD HH:mm"),
                '720': format("YYYY-MM-DD HH:mm"),
                '1440': format("YYYY-MM-DD HH:mm"),
                '2880': format("YYYY-MM-DD HH"),
                '10080': format("YYYY-MM-DD HH"),
                '43200': format("YYYY-MM-DD"),
            }

            Ranges[this.timeRange];
        }
    

However, a warning message is triggered:

Expression statement is not assignment or call in line Ranges[this.timeRange];

P.S. The code is functioning properly.

Answer №1

In order to retrieve this value, you must incorporate the "return" statement; on the other hand, if you intend to display the Range[this.timeRange];, then you should utilize the "print" command. Another option is simply removing this line altogether, as indicated by the comment above since its necessity is not evident.

Answer №2

Your data formatting process is currently applying every possible format each time, but it seems like you intended to select a specific format based on the value of this.timeRange. By implementing the following change, you can achieve that desired functionality:

const TimeFormats = {
  '1': () => format("YYYY-MM-DD HH:mm:ss"),
  '5': () => format("YYYY-MM-DD HH:mm:ss"),
  // add more formats as needed
};

if (TimeFormats[this.timeRange]) {
  TimeFormats[this.timeRange]();
}

In this solution, TimeFormats acts as a collection of formatters with unique IDs. The specific formatter is selected and executed within the last if statement if it exists.

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

Steps for constructing an object containing an array of nested objects

I've been working on this problem for some time now, and it's starting to feel like a messy situation that just won't come together. I'm trying to recreate an object with 5 properties and a nested array of objects, but so far, it's ...

Utilizing Workbox "debug" feature with VueJS PWAs through GenerateSW

Having trouble finding consistent documentation on configurations when using GenerateSW to build your WorkBox service-worker.js? Look no further. The Workbox debug mode can help you overcome many issues in the service-worker.js: workbox.setConfig({ deb ...

The GIPHY API object returns no results

Utilizing Angular 2 to fetch data from the GIPHY API. export class ListaGifsComponent { gifs : Object[] = []; urlBase = "http://api.giphy.com/v1/gifs/search?q="; termoPesquisado = "ryan+gosling"; key = "O8RhkTXfiSPmSCHosPAnhO70pdnHUiWn"; ...

Enhancing code branch coverage using Istanbul

The code snippet provided has a branch coverage of only 50% (refer to the coverage report below). I am unsure how to enhance this as there are no if statements present. I suspect that Istanbul must utilize some form of measurement that I have yet to grasp ...

Inspect the key within a complex hierarchy of nested objects in an array

I am working with an array of nested objects and need to extract the value of a specific key property. Currently, I am using a for loop and checking for the existence of children property, but I feel there might be a more optimal way to accomplish this tas ...

Jenkins integration with a MEAN stack application: A step-by-step guide

I'm working on a Mean stack application and looking to integrate Jenkins CI into my workflow. I am uncertain about the steps needed to accomplish this task. Currently, I use bower for installing frontend packages and npm for other functionalities. ...

Error encountered in AngularJS when utilizing the Flickr API with the parameter "nojsoncallback=1": Unexpected token Syntax

My AngularJS application is trying to access the Flickr API. I need the data in RAW JSON format without any function wrapper, following the guidelines provided in the documentation by using &nojsoncallback=1. However, I keep encountering a console er ...

Developing a Secondary User within Meteor.JS after Establishing the Primary User

Is it possible to automatically create a secondary user upon registration of the primary user using a form generated with the useraccounts:core package? An issue arises when attempting to run Accounts.createUser within Accounts.onCreateUser, resulting in ...

Messages traced by log4javascript are not being displayed

I am currently utilizing log4javascript version 1.4.3. Everything in my application seems to be functioning correctly with all log levels except for trace. To simplify the troubleshooting process and ensure that the issue does not lie within my applicati ...

Using TypeScript, what is the best way to call a public method within a wrapped Component?

Currently, I'm engaged in a React project that utilizes TypeScript. Within the project, there is an integration of the react-select component into another customized component. The custom wrapped component code is as follows: import * as React from " ...

Unable to retrieve the value of a key from a node object

I'm baffled by how this is even possible For example, when I execute this code: console.error(order.Items[i]); The output is: { ItemURL: '', IsBundle: false, GiftTaxPrice: '0', GiftPrice: '0', GiftNotes: null ...

How can I set a background image to automatically adjust to the width of the window, be full height, allow for vertical scrolling, and

How can I set a full-screen background image that adjusts to the body width without horizontal scrolling, maintains height proportionate to width, and allows for vertical scrolling? Here is my current code: html, body { margin: 0px; padding: 0px; } bo ...

Utilize Next.js with Axios for making an HTTP request to a Laravel Lumen endpoint, then showcase the retrieved data within the Next.js

I currently have a Next.js application that utilizes Axios to make calls to Lumen endpoints. The Axios HTTP client functions are organized in a separate folder named services/index.tsx, with sample code as follows: export const register = async (payload: a ...

Encountered a CastError in Mongoose when trying to cast the value "Object" to a string

I am struggling with a Mongoose CastError issue within my Node.js API. The problem arises at a specific route where data is being returned appended with some additional information. Despite finding various solutions for similar problems, my scenario seems ...

The issue of Access-Control-Allow-Origin not functioning properly when using Ajax for a POST request

I am encountering an issue with the header "Access-control-allow-origin" when making a request using the following code: <script type='text/javascript'> function save() { $.ajax( { type: 'POST', ur ...

Adapt the dimensions of the iframe to perfectly match the content within

Looking for a way to dynamically adjust the size of an iframe to perfectly fit its content, even after the initial load. It seems like I'll need some kind of event handling to automatically adjust the dimensions based on changes in the content within ...

What is a clear indication that a <div> is filled with text?

Picture a scenario where a website contains an element that needs to be filled with random text using JavaScript. Once the div is completely filled, it should reset and begin again. It may sound odd, but the question is: how will the JavaScript determine w ...

Struggling with TypeScript declaration files has been a challenge for me

I'm encountering an issue with using the trace function in my TypeScript code. The function has been declared in a .d.ts file as shown below: declare function trace(arg: string | number | boolean); declare function trace(arg: { id: number; name: strin ...

Having trouble accessing the property '_wrapper' of an undefined object when using vue multiselect

Encountering an issue with VUE-MULTISELECT Here is the code snippet: <b-modal id="skills"> <div> <label class="typo__label">Tagging</label> <multiselect v-model=&q ...

Issue with Achieving Two-Way Binding in Angular 1.5 Component when using $ctrl

I am struggling with customizing some products using a component in my index.html. Ultimately, I need to calculate the total of selected products within the main controller "planosVoz" using two-way binding on the svaTotal property in the component control ...