rrdelaney / jadelint

:dragon: A linter for the Jade templating language
https://rrdelaney.github.io/jadelint
MIT License
6 stars 1 forks source link

Rule: whitespace between tags #11

Open patwork opened 9 years ago

patwork commented 9 years ago

So, how to deal with whitespace? Sadly, p.two has best compiled version but is poorly readable in jade.

p.one this
    strong is
    | madness
buf.push("<p class=\"one\">this<strong>is</strong>madness</p>");
p.two this
    strong  is
    |  madness
buf.push("<p class=\"two\">this<strong> is</strong> madness</p>");
p.three this
    = " "
    strong is
    = " "
    | madness
buf.push("<p class=\"three\">this" + (jade.escape(null == (jade_interp = " ") ? "" : jade_interp)) + "<strong>is</strong>" + (jade.escape(null == (jade_interp = " ") ? "" : jade_interp)) + "madness</p>");
p.four this
    != " "
    strong is
    != " "
    | madness
buf.push("<p class=\"four\">this" + (null == (jade_interp = " ") ? "" : jade_interp) + "<strong>is</strong>" + (null == (jade_interp = " ") ? "" : jade_interp) + "madness</p>");
rrdelaney commented 9 years ago

My personal preference is to use

p.one this #[strong is] madness

but I know other people use different ways. I would recommend against using

p.one ...
    = " "
    | ...

I think the best solution is disallowing string literals like that in code blocks. Do you have any other ideas?

patwork commented 9 years ago

Well... ;) I must say I've always used

= " "
| ...

and propably will use

!= " "
| ...

in my next project (without unnecessary attempt to escape/sanitize this one space). Yes, I know it looks ugly, but it's pure jade, without html tags in text. is harmless, but let's say I need anchor inside text with href, title, rel, etc.

| lorem ipsum
a.some-class(href="/some-page", title="blah blah", rel="nofollow", ......)
| dolor sit amet

I don't see a satisfying solution.

edit: I see you've changed to to jade's #[strong] ;)

rrdelaney commented 9 years ago

With all that said, do you have a recommendation for a whitespace rule?

patwork commented 9 years ago

I was thinking about suggesting != " " over = " ", but that's propably too pedantic and since you're against those type of constructions we can return to this topic after some better solution will come to mind.

not only jade, but they solved it eventually:

rrdelaney commented 9 years ago

I'll consider the options, and I'll see if there's a good solution. For now, enjoy the new rule, RequireStatementInCodeBock :)

patwork commented 9 years ago

yea, about that... https://github.com/rrdelaney/jadelint/issues/13 ;)