node-red / nrlint

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

New Flow Parser API and lint rules using visitor pattern #7

Closed knolleary closed 3 years ago

knolleary commented 3 years ago

This PR builds on top of #6

It provides a new Flow Parser API. This is a clean implementation that includes Groups.

The focus of this API is slightly different to the Flow Manipulation API - the goal is to help tools parse flow json and explore it, rather than build a flow from nothing.

We can certainly look at adding manipulation features back in, but it isn't what we need today.

The API provides a function called walk(callback) - this will cause callback to be called once for every object in the flow.

I have updated the flow linter to use this new API as I described in my comment yesterday - https://github.com/node-red/nrlint/pull/6#issuecomment-845450555

I have reimplemented the rules to use this new approach which makes them much more efficient. The only one I'll admit is not as good is the loop detection. The existing code would identify all nodes in the loop - my code only reports the one node in the loop when we realise we are in a loop. That could be improved - I'm just aware the existing code does a lot of looping over the data structures and is quite expensive to run.

Next Steps

Again, I realise I am making some big changes to the linter. I am happy to discuss these proposals and take a different approach if you think these are not useful.

My next piece of work will be to update the linter sidebar in the editor to improve the user experience.