node-red / nrlint

Node-RED Flow Linter
Apache License 2.0
36 stars 15 forks source link

Nrlint does not allow subraction of Dates #21

Closed colinl closed 2 years ago

colinl commented 2 years ago

Current Behavior

Using nrlint 1.0.2 the following code shows the error that the left hand side of an arithmetic operation must of type 'any', 'Number' ... The function does run ok (it subtracts the millisecond values).

const d1 = new Date()
const d2 = new Date(d1.getTime() + 1000)
msg.payload = d2 - d1
return msg;

Expected Behavior

No error should be reported

Steps To Reproduce

See example flow

Example flow

[{"id":"0ae098f0f8d40b2e","type":"inject","z":"84405ff5.25fa6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":230,"y":2540,"wires":[["377b3ad15f21e80e"]]},{"id":"377b3ad15f21e80e","type":"function","z":"84405ff5.25fa6","name":"nrlint test","func":"const d1 = new Date()\nconst d2 = new Date(d1.getTime() + 1000)\nmsg.payload = d2 - d1\nreturn msg;","outputs":1,"noerr":2,"initialize":"","finalize":"","libs":[],"x":380,"y":2540,"wires":[["680355ca417c9cf1"]]},{"id":"680355ca417c9cf1","type":"debug","z":"84405ff5.25fa6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":2540,"wires":[]}]

Environment

knolleary commented 2 years ago

When I run this through nrlint, I don't get any errors.

I do so an error when I edit this code using monaco - it complains about the types in the sum. Is that what you're referring to? IN which case, this isn't an nrlint bug - its something to do with monaco and its own built-in javascript validation.

colinl commented 2 years ago

Yes, it was the types in the sum I was referring to, I should have been more explicit. You are correct, it isn't an nrlint issue, it only appears when using Monaco. I will close this.