r7kamura / rubocop-erb

RuboCop plugin for ERB template.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

More comprehensive analysation

Earlopain opened this issue · comments

There are a few cops which I feel would provide value, like Lint/UselessAssignment or Lint/SyntaxError for example. I think they are disabled because the code is looked at line by line and as such can't know if the variable is consequently used.

Consider this simple example:

<% a = "test" # Never used %>

It would be cool if this extension could extract the whole ruby code from a template and provide more information through context like rubocop does.

@Earlopain Thanks for sharing your opinion. I wish I could do that too, but I don't think that is possible with the current system. We might be able to force them to deal with just inspections, but considering the support for autocorrection, I think it would be better to give up on that and keep the current simple system. What do you think?

If you have an idea to make it happen, I am open to merging it if you create a pull request for that.

I'm not entirely sure what the problem you're referring to is. Is it the incompatibility with autocorrection?

For example, if you want to apply some cops to the following ERB code

<% if a %>
b
<%= c %>
<% end %>

you could first take out only the Ruby code part, and then use RuboCop to inspect it, as follows.

if a
c
end

This will tell you if there is any offense or not, but there is no mechanism to successfully tell RuboCop where the offending code was on the original ERB file.

Furthermore, this method would make it difficult to deal with autocorrection. If the autocorrection spans multiple lines, how can the substituted result be written back to the original ERB file?

Hm, the first will probably need changes to rubocop. Maybe something like being able to pass RubyClips which would then report the correct original location. That would probably also be useful for other templating languages as well.

The autocomplete seems more complicated and I can't think of how that would work. Personally I don't care that much about it and would be happy with it just being reported. There should be an option to turn autocomplete off per cop, but that would apply globally I believe.
I'm thinking about something like this:

rubocop-erb:
  Lint/UselessAssignment:
    Autocomplete: false

That would also allow you to lint your .erb differently that your .rb, though I can't actually think of why you'd want that. Mostly thinking about extension authors.