Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linter to detect scripts that should not be split over multiple lines #64

Closed
himdel opened this issue Feb 20, 2015 · 3 comments
Closed

Comments

@himdel
Copy link

himdel commented Feb 20, 2015

Hi,
if you have a multiline if statement in haml, for example:

- if false ||
-    true
    Wheee!

haml-lint outputs a bogus

foo.haml:1 [W] RuboCop: Syntax: unexpected token kEND

(In some cases it's $end instead of kEND.)

It's probably in RuboCop but since I can't figure out what actually gets passed to rubocop (the --debug output doesn't trigger it), I'm making an issue here.

Any thoughs please?

@sds sds added bug and removed bug labels Feb 25, 2015
@sds
Copy link
Owner

sds commented Feb 25, 2015

I don't know if writing code this way always does what you want, and I would advise against it. I think haml-lint is actually doing the right thing here given the quick investigation I've done.

Consider the following code:

- if false ||
-    true
  Wheee!
- else
  Something else!

The above code fails to compile when run via haml itself:

haml test.haml
Syntax error on line 4: Got "else" with no preceding "if"

Why this works without the else is beyond the time I have to spare for this right now.

Just to drive the point home, consider another example:

= 1 +
= 2

Given your example above this should work, but it fails to compile. Spanning scripts across multiple lines doesn't do what you expect.

This does suggest we should add a linter for this situation, however. :)

@himdel
Copy link
Author

himdel commented Feb 26, 2015

Hi, I actually noticed the else problem with haml, and I obviously agree with your = 1 + counter-example, it's just that .. well, sometimes you really want to be able to do a multiline if, and the | haml operator doesn't seem to do the trick. But oh well, what can you do, back to rewriting.. :) I guess something like - tmp ||= subcondition might do the trick.

I do agree that there should be a linter since this is apparently not supported nor even mentioned in haml docs. Also, please note that code like - if foo || without any subsequent - line passes haml-lint checks as well.

@sds sds changed the title multiline if - [W] RuboCop: Syntax: unexpected token kEND Add linter to detect scripts that should not be split over multiple lines Mar 11, 2015
@sds
Copy link
Owner

sds commented Mar 11, 2015

Quickly whipped together a solution that will probably catch most cases in 11ca42a.

@sds sds closed this as completed Mar 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants