Done
Pinned fields
Click on the next to a field label to start pinning.
Details
Assignee
Quentin JaquierQuentin JaquierReporter
Tibor BlénessyTibor BlénessySprint
NoneFix versions
Priority
Normal
Details
Details
Assignee
Quentin Jaquier
Quentin JaquierReporter
Tibor Blénessy
Tibor BlénessySprint
None
Fix versions
Priority

Sentry
Sentry
Sentry
Created May 16, 2024 at 2:39 PM
Updated October 16, 2024 at 12:53 PM
Resolved June 17, 2024 at 6:25 AM
SonarJS should expose a new entry point to allow other Sonar plugins easily invoke the JS/TS parser for test purposes. The interface should provide a
parse
function, which takescode
parameter and returns the AST in the form of the API defined in https://sonarsource.atlassian.net/browse/JS-158The entry point should be part of the bridge module, or new standalone module. It will be available as a test scope dependency to other Sonar plugins. The suggested interface should be similar to the following
public class Parser implements AutoCloseable { private final BridgeServerImpl bridge; public Parser() { // init bridge and keep the instance } public AST parse(String code) { // parse the code, idempotent } @Override public void close() throws Exception { // shutdown the bridge } }
It’s important to allow the API client to invoke the parse method repeatedly on the already initialized bridge instance so they can instantiate the bridge once per test suite and calls to parse are very fast.
There is a prototype in https://github.com/SonarSource/SonarJS/blob/armor_parser_poc/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/bridge/Parser.java#L44
Currently
BridgeServerImpl
depends too much on Sonar API, in particular onSensorContext
. We should remove the dependencies on the Sonar API by extracting all needed values to some newBridgeParameters
wrapper object. This object will be created inJsTsSensor
using data from SonarAPI and passed toBridgeServerImpl
methods as parameter (ie.startServerLazily
will takeBridgeParameters
object instead ofSensorContext
). This design will allowParser
to directly instantiateBridgeParameters
with suitable values without the need to mock whole Sonar API