pugjs / pug-lint

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

Splitting long lines #36

Closed Ulrikop closed 8 years ago

Ulrikop commented 9 years ago

Hi, thanks for the great work with that linter.

I've got a problem with splitting long lines, when I use this rules:

"disallowMultipleLineBreaks": true,
"validateAttributeSeparator": ", "

For example if I write:

div(foo="1",
  bar="2")

div

or

div(foo="1",
  bar="2",
  batz="3")

both rules throw errors.

What is the correct way to do that with your linter? If there isn't a solution at the moment, could you fix that problem?

In this context, the additional rule "maximumLineLength" to validate the line length would be nice.

Thank you for your help. ~ Ulrikop

benedfit commented 9 years ago

Hi. Apologies this is an error. I currently haven't implemented support for attributes that wrap on multiple lines. This is a coming feature and I'll update you one its ready.

Ulrikop commented 9 years ago

Thank you!

benedfit commented 9 years ago

I'm back on the case with this and hope to have it fixed in the not so distant future

Ulrikop commented 8 years ago

Hi, disallowMultipleLineBreaks seems to work now - thank you. But validateAttributeSeparator still throws errors.

Following scenarios should be accepted:

div(foo="1",
  bar="{hello:' world',\
  666: true}",
  batz="2")

so "validateAttributeSeparator": ", " should accept ',\n' and ',\n' too.

benedfit commented 8 years ago

In this instance you can currently set the rule as follows:

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

This is because new-line characters are currently ignored. However, this is confusing, and should really be:

multiLineSeparator: ",\n  "

Please note that if you are indenting, as you are in your example, that those spaces (or tabs) will need to be included in multiLineSeparator

I'll get a fix out shortly

benedfit commented 8 years ago

I've just released v2.0.7, with which the following configuration should get what you desire (assuming you use comma-space to separate single-line attributes):

"validateAttributeSeparator":
  { "separator": ", "
  , "multiLineSeparator": ",\n  "
  }
Ulrikop commented 8 years ago

Please note that if you are indenting, as you are in your example, that those spaces (or tabs) will need to be included in multiLineSeparator

Hm, no. The indenting is dependent of indention of previous line. it is always 1 level more. Mostly we do it like the "continuation line under-indented for visual indent" rule in python:

.hello(
  foo="1",
  bar="2")
  .world(
    foo="1",
    bar="2")

or

.hello(foo="1",
       bar="2")
  .world(foo="1",
         bar="2")
benedfit commented 8 years ago

Indentation should be automatically handled, and as long as your multilingual separate matches your current indentation, and your indentation is consistent across your project this should hopefully work. If not could you share some sample files, and the confit options you are using and I'll look into this further

brettz9 commented 5 years ago

@benedfit : This is great to have that option; maybe you want to add mention of it to the docs, that indentation will be auto-handled? Thanks!