Skip to content

Latest commit

 

History

History
47 lines (38 loc) · 978 Bytes

melted-constructs.md

File metadata and controls

47 lines (38 loc) · 978 Bytes

Enforce the use of melted constructs when possible (melted-constructs)

Rule Details

The "compatible constructs" are if, while, do, switch, try, and with.

Not melting the else branch is allowed if the last statement of the if branch is also a compatible construct (in such a case, it is assumed that you may want your code to look similar).

The following patterns are considered warnings:

if (!Array.isArray(result)) {
    // do something
} else {
    for (var item of results) {
        // do something else
    }
}

The following patterns are not warnings:

if (!Array.isArray(results)) {
    // do something
} else for (var item of results) {
    // do something else
}

if (test) {
    if (anotherTest) {
        // do something
    }
} else {
    if (yetAnotherTest) {
        // do something else
    }
}

if (test) {
    if (anotherTest) {
        // do something
    }
} else if (yetAnotherTest) {
    // do something else
}