Rubocop: Warnings in Ruby verbose mode

Created on 30 Aug 2016  路  6Comments  路  Source: rubocop-hq/rubocop

I suspect you've already dealt with this issue, but I couldn't find a previous one. Sorry if this is a dupe!

Rubocop outputs lots of warnings when run with RUBYOPT="-w":

/Users/nateberkopec/Code/rubocop/lib/rubocop/cop/performance/string_replacement.rb:24: warning: character class has duplicated range
/Users/nateberkopec/Code/rubocop/lib/rubocop/cop/style/and_or.rb:124: warning: character class has duplicated range: /\?[!\S]/
/Users/nateberkopec/Code/rubocop/lib/rubocop/cop/style/block_comments.rb:31: warning: Unknown escape \z is ignored: /\n(?=[^\z#])/
/Users/nateberkopec/Code/rubocop/lib/rubocop/cop/style/line_end_concatenation.rb:43: warning: literal in condition
/Users/nateberkopec/Code/rubocop/lib/rubocop/cop/style/method_missing.rb:72: warning: assigned but unused variable - temp2

...etc, etc.

Many think that Ruby libraries should not output any warnings when Ruby is running in verbose mode. What say you? Will you accept PRs to fix some of these warnings?

I discovered this while trying to remove some warnings from raven-ruby - we use require 'rubocop/rake_task', so rubocop's warnings were cluttering up the warnings from our own library.

Also, as a side note, how do you see Rubocop interacting with verbose mode? Does Rubocop completely supercede verbose mode, or should they be able to work together?

RuboCop version

$ rubocop -V
0.16.0 (using Parser 2.1.2, running on ruby 2.0.0 x86_64-darwin12.4.0)
bug

Most helpful comment

Unless we institute some kind of "no new warnings" check, there's nothing to do for this issue.

I've implemented a "No new warnings" check for a few open source projects I've contributed to that could be helpful here. For example, see https://github.com/backus/mutest/blob/c4765390103b514b066c2a1e59ee81c98bafe3d2/spec/spec_helper.rb#L66-L69 https://github.com/backus/mutest/blob/c4765390103b514b066c2a1e59ee81c98bafe3d2/spec/support/warning.rb. Basically it compares ruby warnings against warnings listed in a config file and then asserts at the end of the test suite that there weren't any new warnings. It is a bit of a hack but it works very nicely

All 6 comments

Guess we'll have to look into this. Btw, the current RuboCop version is 0.42. :-)

Also, as a side note, how do you see Rubocop interacting with verbose mode? Does Rubocop completely supercede verbose mode, or should they be able to work together?

That's actually not a verbose mode, but "warnings" mode. Yes, RuboCop is supposed to supersede it.

Derp, I just copied the version from the issue template. I'm using 0.42/2.3.0.

The Ruby manpage describes it as verbose mode, not warnings mode:

nodachi:raven-ruby nateberkopec$ man ruby | grep verbose
     -W[level=2]    Turns on verbose mode at the specified level without
                          2 (default) Verbose mode is "verbose". It sets the
     -v             Enables verbose mode.  Ruby will print its version at the
     -w             Enables verbose mode without printing version message at
     --verbose      Enables verbose mode without printing version message a

The reported warnings are all gone. https://github.com/bbatsov/rubocop/pull/3698 cleared them up.

When I run Rubocop on itself (RUBYOPT="-w" bin/rubocop lib) I get a warning out of the Parser gem:

/usr/local/bundle/gems/parser-2.3.3.1/lib/parser/lexer.rb:10922: warning: assigned but unused variable - testEof

and an unavoidable warning from a comment about magic comments in MagicComment (so meta):

lib/rubocop/magic_comment.rb:124: warning: `frozen_string_literal' is ignored after any tokens

Unless we institute some kind of "no new warnings" check, there's nothing to do for this issue.

and an unavoidable warning from a comment about magic comments in MagicComment (so meta):

I'd be fine with just tweaking or removing this comment. If it emits warnings for all users then it is probably not worth it.

Unless we institute some kind of "no new warnings" check, there's nothing to do for this issue.

I've implemented a "No new warnings" check for a few open source projects I've contributed to that could be helpful here. For example, see https://github.com/backus/mutest/blob/c4765390103b514b066c2a1e59ee81c98bafe3d2/spec/spec_helper.rb#L66-L69 https://github.com/backus/mutest/blob/c4765390103b514b066c2a1e59ee81c98bafe3d2/spec/support/warning.rb. Basically it compares ruby warnings against warnings listed in a config file and then asserts at the end of the test suite that there weren't any new warnings. It is a bit of a hack but it works very nicely

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bbatsov picture bbatsov  路  3Comments

david942j picture david942j  路  3Comments

Ana06 picture Ana06  路  3Comments

mikegee picture mikegee  路  3Comments

AndreiMotinga picture AndreiMotinga  路  3Comments