20

I have the following code in rails

<% @post.errors.full_messages.each do |msg| %>                                                                                                     
             <li><%= msg %></li>                                                                                                                              
<% end %>  

SyntasticCheck VIM plug in keeps displaying this error

app/views/posts/new.html.erb[Syntax: line:12 (1)]
1 app/views/posts/new.html.erb|12 warning| possibly useless use of a variable in void context

CodeCrack
  • 5,253
  • 11
  • 44
  • 72
  • 3
    I am not sure there is much you can do about this especially since it is merely a warning telling you that you might not actually use `msg`. Probably has something to do with how it parses ruby blocks and the difference between `<%` and `<%=` tags. To be honest I would expect this as `<%` will not render anything which means in the context of the parser it is very possible that this line is useless. Obviously it is not in this use case but I can understand the warning about it being **possible**. – engineersmnky Apr 14 '15 at 18:54
  • @engineersmnky yea I guess that makes sense. Just kind of annoying working in a file when that error is showing up. Even if you do "lclose" it will disappear but when you open another file and return it pops up again. – CodeCrack Apr 14 '15 at 19:56
  • such tools have ability to skip selected warnings. otherwise you should patch this tool, but it will be more difficult – beornborn Apr 14 '15 at 21:33

2 Answers2

23

If all you want is not to see these messages again:

let g:syntastic_eruby_ruby_quiet_messages =
    \ {'regex': 'possibly useless use of a variable in void context'}
lcd047
  • 5,731
  • 2
  • 28
  • 38
  • Improvement: under CentOS 5.8, there is no "possibly" at the start of the message. If the message still appears, remove the first word from the regular expression. – Gabor Garami Jul 22 '16 at 12:17
  • 'possibly useless use of .* in void context' matches other similar warnings – Lluís Jan 03 '17 at 13:43
  • @lluis Then you need to use a more specific pattern. – lcd047 Jan 04 '17 at 15:44
  • @lcd047 no, I used ".*" to match them :) – Lluís Jan 05 '17 at 09:52
  • @lcd47 IMO it's not a good practice to silence warnings, if that warning shouldn't be there, file a bug to the Syntastic project – Stoic Alchemist Mar 23 '18 at 21:08
  • @StoicAlchemist You do realise syntastic itself is a Vim script, which doesn't know anything about Ruby syntax and doesn't care about the contents of the files it checks, right? – lcd047 Mar 24 '18 at 10:11
  • @lcd047 exactly my point, it's not syntastic the one checking for syntax, it's your ruby/eruby syntax checker telling you that as syntastic is just checking for the filetype and exeucuting whatever you have as syntax checker. On the next link, this issue is mentioned and cleary states that Ruby is the one telling you about the warning: https://github.com/vim-syntastic/syntastic/wiki/Syntax-Checker-Guide#checkeranatomy – Stoic Alchemist Mar 25 '18 at 13:41
  • @StoicAlchemist I'm aware of that link, I wrote most of that page. :) My point is, you have three ways to remove the message: (1) change the code so that it won't trigger it, (2) configure the linter so that it won't emit it, or (3) tell syntastic to kill it after the fact. (1) and (2) don't involve syntastic, but (3) (and the question) does. – lcd047 Mar 25 '18 at 14:20
  • @lcd047 You are right, I guess I prefer to not mess around the checker and just add the `.to_s` so it doesn't hide the warning whenever I see it in other places. – Stoic Alchemist Mar 25 '18 at 15:48
17

If there is a posibility that the warning will help in the future, the best thing to do is add .to_s to the msg so it makes the warning go away but you don't filter future warnings.

Stoic Alchemist
  • 389
  • 5
  • 16