Skip to content

[IDEA] Add the ability to format javascript code #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sbraconnier opened this issue May 14, 2025 · 3 comments
Open

[IDEA] Add the ability to format javascript code #87

sbraconnier opened this issue May 14, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@sbraconnier
Copy link

sbraconnier commented May 14, 2025

Is your feature request related to a problem? Please describe.
When editing javascript code, it's not possible to format the code using a quick action (not that I'm aware of). It would be useful to be able to format the code using a context menu and/or a keyboard shortcut.

Describe your use case
na.

Describe the solution you'd like
The provided js-beautify library could be used to create an new action for the rsta that will allow the user to format the javascript code.

Describe alternatives you've considered
na.

Additional context
I would be happy to contribute for this one.

@sbraconnier sbraconnier added the enhancement New feature or request label May 14, 2025
@tonygermano
Copy link
Member

I think that's a great idea. Do you know if js-beautify works with rhino code containing all of the odd e4x syntax and operators? That seems to be the issue with most beautifiers and js written for mirth.

@tonygermano
Copy link
Member

Looks viable. I just tried the following at https://js-beautify.com

const val = 1

default         xml namespace = 'uri://test'
  var x = <xml>
      <a val={val}/>
 </xml>
  
 for each (var a in x   ..a) { var b = a.*::b
               }

There was a setting at the top I had to change for e4x/jsx support or it really messed up the xml literal. It still didn't change the indents for the xml, but otherwise it seemed to work fine and cleaned it up to

const val = 1

default xml namespace = 'uri://test'
var x = <xml>
      <a val={val}/>
 </xml>

for each(var a in x..a) {
    var b = a.*::b
}

@sbraconnier
Copy link
Author

This option is set programmatically here in the OIE source code. I would also set the indent_with_tabs to true as it seems to be the default behavior of the editor.

At the moment, the function JavaScriptSharedUtil#prettyPrint is only used to pretty print the read-only "Generated Script" tab of a transformer step (or filter rule). It could be easily used as an action to manually format the code. I've already started working on a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants