pugjs / pug-lint

An unopinionated and configurable linter and style checker for Pug
ISC License
228 stars 51 forks source link

validateAttributeSeparator multiLineSeparator doesn't support variable indenting #157

Open GPetrites opened 6 years ago

GPetrites commented 6 years ago

This rule is probably the most important for us. When you use Angular you eventually learn that Pug doesn't recognize the Angular binding attributes correctly unless you separate them with a comma. Missing a comma has bitten us numerous times.

currently when you configure the rule using:

"validateAttributeSeparator": {
    "separator": ", ",
    "multiLineSeparator": ",\n  "
}

The pug is only considered valid if the white space on the second line matches EXACTLY the white space included in the rule. As I have it above, there are two spaces after the newline so the rule only passed if the pug looks like:

div(
    aaa="111",
  bbb="222"
)

Note that there are exactly two spaces before the 'bbb' attribute. If I add or remove a space, the rule reports it as an error.

If I replace the spaces with tabs in both the rule and the pug, I get the same results. The number of tabs in the rule must match exactly the number of tabs in the pug.

As a result, it's not possible to create a rule that allows the following pug to be recognized as valid:

div(
    aaa="aaa",
    bbb="bbb"
)
    div(
        aaa="aaa",
        bbb="bbb"
    )
        div(
            aaa="aaa",
            bbb="bbb"
        )

In order to be usable, the multiLineSeparator needs to support various levels of indenting on the following line.

adrienverge commented 6 years ago

I just did a test and confirm what you experience. A new option would be great, for instance:

"validateAttributeSeparator": {
    "separator": ", ",
    "allowMultiLine": true  # `allowMultiLine` and `multiLineSeparator` should be mutually exclusive
}

Contributions are welcome!