Reformat JS code problem in *.vm files

When I try to reformat JavaScript code in a Velocity file, IDEA makes an error:

if ($saisieRemboursementForm.dossierFormationStdEtatSubrogation == 1) {

becomes


          if ($saisieRemboursementForm.dossierFormationStdEtatSubrogation == 1
        )
        {

which is invalid JS code.

I thought it would probably be because IDEA doesn't recognize the code validity and highlights the following inspection alerts on '1':
- Expression statement is not assignment or call
- Unterminated Statement

But suppressing the alert using code annotation doesn't solve the reformat problem and create weird curly braces (could be the way to add the //noinspections in JS but I've never seen it like that before).

The JS function as it should be formated (as it is if put in a JS type file):


function calculerMontantsTvaEtTtc(champ, typeFraisCode) {
    var precision = 2;
    if (isDecimalPositifWithTwoDecimals(champ)) {
        if (champ.value == 0 || isDecimalWithTwoDecimals(champ)) {
            // Déclaration objets Number          
               (...)
            if ($saisieRemboursementForm.dossierFormationStdEtatSubrogation == 1) {
                (...)
            } else {
                (...)
            }
          (...)
        }
    }
}

the same function reformated by IDEA:


function calculerMontantsTvaEtTtc(champ, typeFraisCode) {
    var precision = 2;
    if (isDecimalPositifWithTwoDecimals(champ)) {
        if (champ.value == 0 || isDecimalWithTwoDecimals(champ)) {
            // Déclaration objets Number
                (...)
            if ($saisieRemboursementForm.dossierFormationStdEtatSubrogation == 1
        )
        {
            (...)
        }
        else
        {
            (...)
        }
          (...)
        }
    }
}

result if I do a 'Suppress for Statement' on 'Expression statement is not assignment or call' error + reformat: (the alert is still here, reformat still produce the same error, the Suppress add weird curly braces)


function calculerMontantsTvaEtTtc(champ, typeFraisCode) {
    var precision = 2;
    if (isDecimalPositifWithTwoDecimals(champ)) {
        if (champ.value == 0 || isDecimalWithTwoDecimals(champ)) { //noinspection BadExpressionStatementJS
        {
            // Déclaration objets Number
            (...)
            if ($saisieRemboursementForm.dossierFormationStdEtatSubrogation == 1
        )
        {
            (...)
        }
        else
        {
            (...)
        }
            (...)
        }
        }
    }
}


cheers



Please sign in to leave a comment.