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

How to un-ignore the ignored rubocop cops? #77

Closed
maxjacobson opened this issue Jun 10, 2015 · 6 comments
Closed

How to un-ignore the ignored rubocop cops? #77

maxjacobson opened this issue Jun 10, 2015 · 6 comments
Labels

Comments

@maxjacobson
Copy link

haml-lint ignores some rubocop cops (https://github.com/brigade/haml-lint/blob/master/config/default.yml#L56-L70)

Let's say I didn't want it to...

I tried figuring out how to configure haml-lint to enable those cops but couldn't quite figure it out. Is it possible?

Thanks!

@sds sds added the question label Jun 10, 2015
@sds
Copy link
Owner

sds commented Jun 10, 2015

Hey @maxjacobson,

Those cops are ignored for a good reason: haml-lint takes some shortcuts when extracting Ruby code from a HAML template, which necessarily results in noise from those cops.

Can you give a specific example of a cop you want to disable?

If you still REALLY want to do this, you just need to redefine the entire list in your local .haml-lint.yml:

linters:
  RuboCop:
    ignored_cops: [] # NOT RECOMMENDED!

@maxjacobson
Copy link
Author

Hey @sds thanks for getting back to me!

there are a few nitpicky things I was hoping haml-lint would catch:

are you saying it doesn't analyze the file as it is, but first transforms it into some other ruby file, so it wouldn't catch those things necessarily anyway?

thanks!

@sds
Copy link
Owner

sds commented Jun 10, 2015

Yes, as part of its preprocessing, haml-lint will convert HAML like this:

- if signed_in?(viewer)
  %span Stuff
  = link_to 'Sign Out', sign_out_path
- else
  .some-class{ class: my_method }= my_method
  = link_to 'Sign In', sign_in_path

...into Ruby like this:

if signed_in?(viewer)
  link_to 'Sign Out', sign_out_path
else
  { class: my_method }
  my_method
  link_to 'Sign In', sign_in_path
end

Notice that the Ruby is somewhat nonsensical. All haml-lint tries to do is preserve the ordering of declarations and uses of variables, as well as the order Ruby that code appears in the template. This means you probably won't have a translation that makes perfect sense.

For things like indentation, it may be possible to munge things into shape but I haven't looked too deeply into that. Right now if you have HAML like the following:

%tag{ some: 'hash', 
      attributes: 'here' }

...it will get extracted as:

{ some: 'hash', attributes: 'here' }

...losing some of the whitespace in the process. This makes it difficult to have it generate correct indentation.

For your request about final newlines, I think it's reasonable for haml-lint to support that first hand via a FinalNewline linter, since RuboCop won't have any idea whether your HAML template ends with a newline or not.

@maxjacobson
Copy link
Author

Makes total sense, thanks for explaining.

Adding a newline check would be super helpful! What do you think about checking for the presence of a tab character? I think most Rubyists are using spaces, not tabs, so checking for the presence of a tab file character in the source haml file might be useful as well 😄

@sds
Copy link
Owner

sds commented Jun 23, 2015

Added a final newline check in 1635c07. Enforcing spaces instead of tabs in indentation was added in #81.

@sds sds closed this as completed Jun 23, 2015
@maxjacobson
Copy link
Author

Awesome! Thanks a lot @sds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants