Wow, the title is quite a mouth full. Let me explain. I have a .jsp page, on this page is a JavaScript <script ..> element and inside the JavaScript there is an EL expression (${..}). The code looks like this:
<script type="text/javascript">
jQuery(document).ready(function() {
var HOST_ID = ${host.id};
...
});
</script>
The Problem:
The Eclipse JavaScript formatter will per default expand ${host.id} over multiple lines. I am guessing that the EL expression is somehow interpreted as a JavaScript object. Anyway, the tag will make end up looking like this:
var HOST_ID = $
{
host.id
}
;
=> This actually breaks the code!
If split over multiple lines the tag is no longer recognized as valid EL expression and execution of the JavaScript code will stop throwing around exceptions.
I know about a way to turn off formatting adhoc in the Java formatter using tags (// @formatter:off or on) but there is no such option for the JavaScript formatter in Eclipse.
The only way to fix (read workaround) this is to force the JavaScript formatter to never expand objects. But this is problematic in two ways:
- Not expanding objects can be very messy and lead to extremely unreadable code.
- Expanding objects over multiple lines is a default in the Eclipse JavaScript formatter.
This means if any member of my team accidentially auto-formats a .jsp file containing the described construct the code will silently break. It still looks like valid JS, and passes build etc, but at execution time it won't work.
Does anyone have any solution for this? The best solution would be to somehow disable formatting with a tag like the one used in the Java formatter (this solution works without enforcing company/teamwide formatter standards or hoping no one will accidentally hit Shift+Ctrl+F).