DataDog / datadog-static-analyzer

Datadog Static Analyzer
https://docs.datadoghq.com/static_analysis/
Apache License 2.0
100 stars 12 forks source link

[STAL-1960] Add console.log tests, special TreeSitterNode serialization #407

Closed jasonforal closed 3 months ago

jasonforal commented 3 months ago

What problem are you trying to solve?

Currently, when calling console.log on a TreeSitterNode, we get the raw, internal representation, which is a bunch of integers.

Console logging is useful for debugging during the rule writing process, so it should output a more friendly helpful representation of a node.

What is your solution?

Implement a custom JSON.stringify replacer function to serialize the node with helpful information like the CST node type and text.

Before

// console.log(tsNode);
'{"id":0,"_startLine":1,"_startCol":7,"_endLine":1,"_endCol":10,"_typeId":1}'

After

// console.log(tsNode);
'{"type":"identifier","start":{"line":1,"col":7},"end":{"line":1,"col":10},"text":"abc"}'

Alternatives considered

What the reviewer should know

jasonforal commented 3 months ago

Rebased -- you can verify here: https://github.com/DataDog/datadog-static-analyzer/compare/f2f79cc93d170d836ee9bf142bb4f697e6815f18..6e2f2e7ddb500d6790f1892351cb1232d03b39f3