rubocop / rubocop Goto Github PK
View Code? Open in Web Editor NEWA Ruby static code analyzer and formatter, based on the community Ruby style guide.
Home Page: https://docs.rubocop.org
License: MIT License
A Ruby static code analyzer and formatter, based on the community Ruby style guide.
Home Page: https://docs.rubocop.org
License: MIT License
After upgrading to version 0.5.0, rubocop started to fail with the following error:
xxxx$ rubocop app
/Users/xxxx/.rvm/gems/ruby-2.0.0-p0/gems/rubocop-0.5.0/lib/rubocop/cli.rb:182:in `block in ruby_files': invalid byte sequence in UTF-8 (ArgumentError)
from /Users/xxxx/.rvm/gems/ruby-2.0.0-p0/gems/rubocop-0.5.0/lib/rubocop/cli.rb:180:in `select'
from /Users/xxxx/.rvm/gems/ruby-2.0.0-p0/gems/rubocop-0.5.0/lib/rubocop/cli.rb:180:in `ruby_files'
from /Users/xxxx/.rvm/gems/ruby-2.0.0-p0/gems/rubocop-0.5.0/lib/rubocop/cli.rb:157:in `block in target_files'
from /Users/xxxx/.rvm/gems/ruby-2.0.0-p0/gems/rubocop-0.5.0/lib/rubocop/cli.rb:155:in `each'
from /Users/xxxx/.rvm/gems/ruby-2.0.0-p0/gems/rubocop-0.5.0/lib/rubocop/cli.rb:155:in `target_files'
from /Users/xxxx/.rvm/gems/ruby-2.0.0-p0/gems/rubocop-0.5.0/lib/rubocop/cli.rb:44:in `run'
from /Users/xxxx/.rvm/gems/ruby-2.0.0-p0/gems/rubocop-0.5.0/bin/rubocop:13:in `block in <top (required)>'
from /Users/xxxx/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
from /Users/xxxx/.rvm/gems/ruby-2.0.0-p0/gems/rubocop-0.5.0/bin/rubocop:12:in `<top (required)>'
from /Users/xxxx/.rvm/gems/ruby-2.0.0-p0/bin/rubocop:23:in `load'
from /Users/xxxx/.rvm/gems/ruby-2.0.0-p0/bin/rubocop:23:in `<main>'
from /Users/xxxx/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `eval'
from /Users/xxxx/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `<main>'
Version 0.4.6 worked with no issues on the same set of source code.
Scanning this:
class Foo
def <=> other
name <=> other.name
end
end
produces undefined method '[]' for nil:NilClass
this exception:
/Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/op_method.rb:11:in `block in inspect': undefined method `[]' for nil:NilClass (NoMethodError)
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:82:in `each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cop/op_method.rb:9:in `inspect'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cli.rb:74:in `block (2 levels) in run'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cli.rb:66:in `each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cli.rb:66:in `block in run'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cli.rb:44:in `each'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/lib/rubocop/cli.rb:44:in `run'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/bin/rubocop:13:in `block in <top (required)>'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.6.0/bin/rubocop:12:in `<top (required)>'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/bin/rubocop:23:in `load'
from /Users/lloeki/.rbenv/versions/2.0.0-p0/bin/rubocop:23:in `<main>'
See Travis CI
The version number is stored in two places, lib/rubocop/version.rb
and VERSION
. It has not been updated in version.rb
the last few times.
Currently the absence of a .ruboconf.yml
file isn't tested because all tests create directories in the rubocop
dir itself, which contains a .ruboconf.yml
file.
I think it is better to move all those tests into a temporary directory using tmpdir
so none of the tests are influenced by the supplied .ruboconf.yml
file
This is an awesome tool. We want to include it as a git pre-commit hook.
But we only wanted it to scan the lines that were changed in the git commit.
Rubocop currently scans the whole file. If rubocop could take a line numbers argument we could probably feed the output of git diff to rubocop.
Thanks!
This pattern is extremely common:
class MyError < StandardError; end
It should probably find its way into the style guide, and rubocop should handle the following new cases:
Currently we're not checking the style of hash literals. As mentioned in the guide there are two acceptable styles:
# with spaces
{ one: 1, two: 2 }
# without spaces
{one: 1, two: 2}
I think we need to introduce a cop named HashLiteralBraces (or something similar) and it should have a config option RequireOpeningAndClosingSpace
(or something similar) set to true by default (since it's the more popular of the two styles). @jonas054, how does that sound?
Something like: foo(3,4,)
or foo(a: 3, b: 4,)
crashes.
gems/rubocop-0.4.2/lib/rubocop/cop/align_parameters.rb:46:in `get_args': (RuntimeError)
app/helpers/categories_helper.rb: [:method_add_arg, [:fcall, [:@ident, "link_to", #<struct Rubocop::Cop::Position lineno=23, column=4>]], [:arg_paren, [[:method_add_arg, [:fcall, [:@ident, "t", #<struct Rubocop::Cop::Position lineno=24, column=6>]], [:arg_paren, [:args_add_block, [[:string_literal, [:string_content, [:@tstring_content, "shared.categories.reset-link", #<struct Rubocop::Cop::Position lineno=24, column=9>]]], [:bare_assoc_hash, [[:assoc_new, [:@label, "default:", #<struct Rubocop::Cop::Position lineno=24, column=40>], [:string_literal, [:string_content, [:@tstring_content, "Reset Filters", #<struct Rubocop::Cop::Position lineno=24, column=50>]]]]]]], false]]], [:vcall, [:@ident, "collection_path", #<struct Rubocop::Cop::Position lineno=25, column=6>]], [:bare_assoc_hash, [[:assoc_new, [:@label, "class:", #<struct Rubocop::Cop::Position lineno=26, column=6>], [:string_literal, [:string_content, [:@tstring_content, "reset disabled", #<struct Rubocop::Cop::Position lineno=26, column=14>]]]], [:assoc_new, [:@label, "title:", #<struct Rubocop::Cop::Position lineno=27, column=6>], [:method_add_arg, [:fcall, [:@ident, "t", #<struct Rubocop::Cop::Position lineno=27, column=13>]], [:arg_paren, [:args_add_block, [[:string_literal, [:string_content, [:@tstring_content, "tooltips.filtering.reset", #<struct Rubocop::Cop::Position lineno=27, column=16>]]], [:bare_assoc_hash, [[:assoc_new, [:@label, "default:", #<struct Rubocop::Cop::Position lineno=27, column=43>], [:string_literal, [:string_content, [:@tstring_content, "Return filters to the default view", #<struct Rubocop::Cop::Position lineno=27, column=53>]]]]]]], false]]]]]]]]]
from gems/rubocop-0.4.2/lib/rubocop/cop/align_parameters.rb:16:in `block in inspect'
require 'logger'
logger = Logger.new(STDOUT)
logger.debug { "foo #{logger}" }
Fails on line 4 column 13 with the message "missing brace not found". Curiously, column 13 is the space character before the first brace on that line, not the brace itself. Could there also be an off-by-one error in calculating the column for exceptions?
Just an example:
Code:
[1,2,3].map { |r| "s-#{r}" }.join(',')
Exception:
/usr/local/var/lib/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.4.0/lib/rubocop/cop/blocks.rb:32:in `check': (RuntimeError)
1.rb:1:9: Matching brace not found
from /usr/local/var/lib/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.4.0/lib/rubocop/cop/blocks.rb:17:in `block in inspect'
from /usr/local/var/lib/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.4.0/lib/rubocop/cop/blocks.rb:17:in `each_index'
from /usr/local/var/lib/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.4.0/lib/rubocop/cop/blocks.rb:17:in `inspect'
from /usr/local/var/lib/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.4.0/lib/rubocop/cli.rb:62:in `block (2 levels) in run'
from /usr/local/var/lib/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.4.0/lib/rubocop/cli.rb:57:in `each'
from /usr/local/var/lib/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.4.0/lib/rubocop/cli.rb:57:in `block in run'
from /usr/local/var/lib/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.4.0/lib/rubocop/cli.rb:48:in `each'
from /usr/local/var/lib/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.4.0/lib/rubocop/cli.rb:48:in `run'
from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.4.0/bin/rubocop:12:in `block in <top (required)>'
from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
from /usr/local/opt/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.4.0/bin/rubocop:11:in `<top (required)>'
from /usr/local/opt/rbenv/versions/2.0.0-p0/bin/rubocop:23:in `load'
from /usr/local/opt/rbenv/versions/2.0.0-p0/bin/rubocop:23:in `<main>'
Seems like an bug for me.
By the way, if I add braces around the block (making this code invalid)
[1,2,3].map({ |r| "s-#{r}" }).join(',')
i get:
/usr/local/var/lib/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.4.0/lib/rubocop/cop/syntax.rb:13:in `block in inspect': undefined method `captures' for nil:NilClass (NoMethodError)
from /usr/local/var/lib/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.4.0/lib/rubocop/cop/syntax.rb:12:in `each_line'
from /usr/local/var/lib/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.4.0/lib/rubocop/cop/syntax.rb:12:in `inspect'
Is this a correct behavior for invalid syntax?
Next one - reduce
.
[1,2,3].reduce(0) { |memo, n| memo += n * n }
I get:
C: 1: Space missing after comma.
C: 1: Space missing after comma.
Ehm? What comma? I've already had that comma here.
Hope that helps!
Should one line methods be discouraged?
def foo; 'bar' end
They require a semicolon after method name when parens are absent, and rubocop points that as an offense.
I'm not really advocating in favour of (or against) them, in fact I'm just pointing out it may have passed unnoticed.
Not all error lines in the output from ruby -wc
contain the word warning, which leads to an exception being rasied in syntax.rb
.
For example:
jonas@jonas-laptop:~/.rvm/gems$ ruby -wc ~/.rvm/gems/ruby-1.9.3-p194/gems/activeadmin-0.5.0/lib/generators/active_admin/resource/templates/admin.rb
/home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/activeadmin-0.5.0/lib/generators/active_admin/resource/templates/admin.rb:1: unterminated string meets end of file
/home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/activeadmin-0.5.0/lib/generators/active_admin/resource/templates/admin.rb:1: warning: possibly useless use of < in void context
So I get this exception:
jonas@jonas-laptop:~/.rvm/gems$ rubocop ruby-1.9.3-p194/gems/activeadmin-0.5.0/lib/generators/active_admin/resource/templates/admin.rb
/home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.4.1/lib/rubocop/cop/syntax.rb:13:in `block in inspect': undefined method `captures' for nil:NilClass (NoMethodError)
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.4.1/lib/rubocop/cop/syntax.rb:12:in `each_line'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.4.1/lib/rubocop/cop/syntax.rb:12:in `inspect'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.4.1/lib/rubocop/cli.rb:62:in `block (2 levels) in run'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.4.1/lib/rubocop/cli.rb:57:in `each'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.4.1/lib/rubocop/cli.rb:57:in `block in run'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.4.1/lib/rubocop/cli.rb:48:in `each'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.4.1/lib/rubocop/cli.rb:48:in `run'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.4.1/bin/rubocop:12:in `block in <top (required)>'
from /home/jonas/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.4.1/bin/rubocop:11:in `<top (required)>'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/bin/rubocop:19:in `load'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/bin/rubocop:19:in `<main>'
Maybe I've found a bug (?)... it seems that rubocop (version 0.5.0) doesn't like so much a snippet of code like this one:
alias has_foo? foo?
alias has_bar? bar?
I will do a PR...
As comments aren't code, I don't think they should be part of the 80 characters rule which tells me that the Line is too long
. I don't know about you?
In fact, let me rephrase. Do you think that comments should be part of the 80 characters per line rule as they're not code?
We need to extend the README file a bit, since newcomers will likely miss out some of the things they can do with rubocop.
While scanning one of my projects, I came across the following RescueException Cop error:
Scanning /Users/ryan/www/articles/app/lib/url_validator.rb
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/rescue_exception.rb:13:in `block in inspect': undefined method `lineno' for nil:NilClass (NoMethodError)
from /Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:82:in `each'
...
Here is url_validator.rb:
class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value.blank? || check_url_format(value)
record.errors[attribute] << (options[:message] || I18n.t("activerecord.errors.models.user.correctly_enter_url"))
end
end
private
def check_url_format(url)
uri = URI.parse(url)
uri.kind_of?(URI::HTTP)
rescue URI::InvalidURIError
false
end
end
Hey guys,
Here's a list of the more important rules that we should implement in the future.
Kernel#loop
with break rather than begin/end/until
or begin/end/while
for post-loop tests.return
where not required for flow of control.self
where not required. (It is only required when calling a self write accessor.)(\)
where not required. In practice, avoid using line continuations at all~~.reduce
with short blocks, name the arguments |a, e| (accumulator, element)
.def +(other)
)# TODO improve performance
).module_function
over extend self when you want to turn a module's instance methods into class methods.attr
family of functions to define trivial accessors or mutators.def self.method
to define singleton methods. This makes the code easier to refactor since the class name is not repeated.fail
method. Use raise
only when catching an exception and re-raising it (because here you're not failing, but explicitly and purposefully raising an exception).return
from an ensure block. If you explicitly return from a method inside an ensure block, the return will take precedence over any exception being raised, and the method will return as if no exception had been raised at all. In effect, the exception will be silently thrown away.begin
blocks where possible.Exception
class. This will trap signals and calls to exit, requiring you to kill -9 the process.%w
to the literal array syntax when you need an array of strings.%r
only for regular expressions matching more than one '/' character.alias_method
will do.if
, unless
, etc.private
and protected
.private
and protected
as much as method definitions.Details and examples about most rules are available in the guide itself.
I'm opening this ticket mostly so we can discuss who would like to implement what, so that we don't end up with two people working on the same cop. When somebody(me included) starts to work on a cop he'd write a comment here; when he's done - we'd scratch the rule from the list.
So, who'd like to pick a task first? :-)
I ran into an issue today where some code was triggering a cop but upon reviewing the code I could find no preferable way to rewrite it, so I decided to disable that cop for just those few lines. (Thanks @jonas054 for this fabulous feature!) Unfortunately, I'm not as familiar with which cops do what ... so I had to go digging through the code to figure out which cop name to specify in the rubocop:disable
comment. This process should be easier. I suggest that we change the output to something like the following:
C: 30: MethodLength: Method has too many lines. [12/10]
C: 86: ParameterLists: Avoid parameter lists longer than four parameters.
Does rubocop work with Ruby 2.0.0? I'm getting the following error in a Rail project that's on Ruby-2.0.0
/Users/davidragone/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.5.0/lib/rubocop/cli.rb:182:in block in ruby_files': invalid byte sequence in UTF-8 (ArgumentError) from /Users/davidragone/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.5.0/lib/rubocop/cli.rb:180:in
select'
from /Users/davidragone/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.5.0/lib/rubocop/cli.rb:180:in ruby_files' from /Users/davidragone/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.5.0/lib/rubocop/cli.rb:151:in
target_files'
from /Users/davidragone/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.5.0/lib/rubocop/cli.rb:44:in run' from /Users/davidragone/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.5.0/bin/rubocop:13:in
block in <top (required)>'
from /Users/davidragone/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/benchmark.rb:296:in realtime' from /Users/davidragone/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rubocop-0.5.0/bin/rubocop:12:in
<top (required)>'
from /Users/davidragone/.rbenv/versions/2.0.0-p0/bin/rubocop:23:in load' from /Users/davidragone/.rbenv/versions/2.0.0-p0/bin/rubocop:23:in
We are a french dev shop, and we need to write comments in french. Still, we want to enforce identifiers to be ascii only.
The current AsciiIdentifiersAndComments cop checks both identifiers and comments. It should be configurable to check only one of them, or both, or neither.
As we add more and more checks the performance naturally regresses a bit. Luckily the things we're doing are pretty parallelizable - we can simply split the cops into 3 groups, run them in 3 threads and just merge the results in the end. Even though Ruby's threading is not exactly its strong suite I still think we might be able to get some benefit out of this.
JRuby is inching closer to supporting Ripper(https://gist.github.com/enebo/4548938) and there the performance boost should be even bigger.
This issue is here mostly for discussion purposes. If anyone has the time to run a few simple experiments with basic parallelization and share the results that'd be great.
Today I learned that Coveralls offers a service that's free for open source Github projects, much like Travis-CI. It shows coverage data with many details. See for example guard-rubocop by @yujinakayama. It would be nice to get that for RuboCop.
See Travis CI
This piece of code will not register an offence:
def some_method(param='')
The problem is that '' has no positions associated with it in the resulting sexp
.
[[[:@ident, "param", [1, 9]], [:string_literal, [:string_content]]]]
@jonas054, would you please take care of this?
~ $ cat bug.rb
p :==, :<=>, :>, :<, :>=, :<=
~ $ rubocop bug.rb
== bug.rb ==
C: 1: Use snake_case for symbols.
C: 1: Use snake_case for symbols.
C: 1: Use snake_case for symbols.
C: 1: Use snake_case for symbols.
C: 1: Use snake_case for symbols.
C: 1: Use snake_case for symbols.
1 files inspected, 6 offences detected
~ $ ruby --version; rubocop --version
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
0.5.0
/Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:99:in whitespace?': undefined method
type' for nil:NilClass (NoMethodError)
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/space_after_comma_etc.rb:11:in block in inspect' from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/space_after_comma_etc.rb:9:in
each_index'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/space_after_comma_etc.rb:9:in inspect' from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cli.rb:74:in
block (2 levels) in run'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cli.rb:66:in each' from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cli.rb:66:in
block in run'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cli.rb:44:in each' from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cli.rb:44:in
run'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/bin/rubocop:13:in block in <top (required)>' from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/benchmark.rb:295:in
realtime'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/bin/rubocop:12:in <top (required)>' from /Users/matt/.rbenv/versions/1.9.3-p327/bin/rubocop:23:in
load'
from /Users/matt/.rbenv/versions/1.9.3-p327/bin/rubocop:23:in `
Would be good to exclude the db folder for example
Like this question I wonder how rubocop can be integrated with Rake. Is there support for integration between rubocop and Rake so that one can run rubocop along with other tests in Rake?
Hey Guys,
I wanted to brainstorm about adding the ability for users to create custom cops. I think this would be a great feature. If the project/organization is concerned with style consistency, they likely have some differing opinions on what/how things should be checked.
Thinking about my own projects, I personally would like to create cops to check rspec method usage (expect
instead of should
, etc).
The way I can see this working is allowing users to create files (exactly the same as within the rubocop/cops source code) and place them in, for example, in a .rubocop
folder within their project.
If you guys are onboard with this idea, I'd like to code it up and create a gist covering the basics of implementing a Cop.
When you interpolate global, instance or class variables in strings you can omit the enclosing braces. But RuboCop does not notice variables not enclosed in braces and gives a misleading warnings of
Prefer single-quoted strings when you don't need string interpolation or special symbols.
as double-quotation is required for the strings in question.
For example, consider the following code:
# -*- coding: utf-8 -*-
class Klass
def meth
@bar = @@bar = $bar = 'baz'
puts "foo#@bar"
puts "foo#@@bar"
puts "foo#$bar"
end
end
When inspecting this rubocop says
C: 5: Replace class var @@bar with a class instance var.
C: 6: Prefer single-quoted strings when you don't need string interpolation or special symbols.
C: 7: Prefer single-quoted strings when you don't need string interpolation or special symbols.
C: 7: Replace class var @@bar with a class instance var.
C: 8: Prefer single-quoted strings when you don't need string interpolation or special symbols.
But replacing the strings with single-quoted ones will not allow for interpolation.
I would like for an additional parameter to be definable for the LineLength configuration so that I could overwrite the default line length of 79 in some cases.
Offence
interface asks for severity as first arg:
https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/cop/offence.rb#L10
Cop
instead provides filename as first arg:
https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/cop/cop.rb#L68
This code:
class Base
def func
"Hello"
end
end
class Derived < Base
def func
super.slice(1..2)
end
end
puts Derived.new.func
gives this stack dump:
/home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cop/hash_literal.rb:12:in `block in inspect': undefined method `[]' for nil:NilClass (NoMethodError)
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
[...]
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cop/hash_literal.rb:9:in `inspect'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cli.rb:74:in `block (2 levels) in run'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cli.rb:66:in `each'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cli.rb:66:in `block in run'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cli.rb:44:in `each'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/lib/rubocop/cli.rb:44:in `run'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/bin/rubocop:13:in `block in <top (required)>'
from /home/jonas/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/gems/rubocop-0.6.0/bin/rubocop:12:in `<top (required)>'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/bin/rubocop:19:in `load'
from /home/jonas/.rvm/gems/ruby-1.9.3-p194/bin/rubocop:19:in `<main>'
So HashLiteral
crashes. The same goes for ArrayLiteral
if HashLiteral
is disabled. I have a fix for the problem.
Many specs from cli_spec.rb are failing currently. See Travis-CI. This started with the introduction of the Coveralls code coverage gem.
All the failing specs fail for the same reason. A colored text is uncolored, which doesn't work, and then compared to an expected string without ANSI escape sequences. The comparison fails.
First I thought that the reason was that Coveralls and RuboCop both use ANSI coloring, but that they use different gems to achieve this. I tried changing RuboCop to use colorize
(used by Coveralls) instead of term-ansicolor
. That didn't help one bit.
Since it's the calls to String#uncolored
that don't work, we could remove them and colorize all the expected strings instead. This fails to address the root cause, but it works. Should I implement this solution, or can anybody else find a better, more thorough solution?
I use RVM with Ruby 1.9.2
I installed Rubocop 0.2.0
When I try to run it by command 'rubocop' in terminal i get that error
/home/user/.rvm/gems/ruby-1.9.2-p318/gems/rubocop-0.2.0/lib/rubocop/cli.rb:36:in
'*encode!': code converter not found (UTF-8 to UTF-16) (Encoding::ConverterNotFoundError) from /home/user/.rvm/gems/ruby-1.9.2-p318/gems/rubocop-0.2.0/lib/rubocop/cli.rb:36:in
block (2 levels) in run'
from /home/user/.rvm/gems/ruby-1.9.2-p318/gems/rubocop-0.2.0/lib/rubocop/cli.rb:33:inmap' from /home/user/.rvm/gems/ruby-1.9.2-p318/gems/rubocop-0.2.0/lib/rubocop/cli.rb:33:in
block in run'
from /home/user/.rvm/gems/ruby-1.9.2-p318/gems/rubocop-0.2.0/lib/rubocop/cli.rb:31:ineach' from /home/user/.rvm/gems/ruby-1.9.2-p318/gems/rubocop-0.2.0/lib/rubocop/cli.rb:31:in
run'
from /home/user/.rvm/gems/ruby-1.9.2-p318/gems/rubocop-0.2.0/bin/rubocop:12:inblock in <top (required)>' from /home/user/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/benchmark.rb:310:in
realtime'
from /home/user/.rvm/gems/ruby-1.9.2-p318/gems/rubocop-0.2.0/bin/rubocop:11:in<top (required)>' from /home/user/.rvm/gems/ruby-1.9.2-p318/bin/rubocop:19:in
load'
from /home/user/.rvm/gems/ruby-1.9.2-p318/bin/rubocop:19:in<main>' from /home/user/.rvm/gems/ruby-1.9.2-p318/bin/ruby_noexec_wrapper:14:in
eval'
from /home/user/.rvm/gems/ruby-1.9.2-p318/bin/ruby_noexec_wrapper:14:in `
/Users/michael.hogg/.rvm/gems/ruby-1.9.3-p392@fig/gems/rubocop-0.4.0/lib/rubocop/cop/offence.rb:17:in
%': malformed format string - %[ (ArgumentError)
from /Users/michael.hogg/.rvm/gems/ruby-1.9.3-p392@fig/gems/rubocop-0.4.0/lib/rubocop/cop/offence.rb:17:in to_s' from /Users/michael.hogg/.rvm/gems/ruby-1.9.3-p392@fig/gems/rubocop-0.4.0/lib/rubocop/report/plain_text.rb:10:in
join'
from /Users/michael.hogg/.rvm/gems/ruby-1.9.3-p392@fig/gems/rubocop-0.4.0/lib/rubocop/report/plain_text.rb:10:in generate' from /Users/michael.hogg/.rvm/gems/ruby-1.9.3-p392@fig/gems/rubocop-0.4.0/lib/rubocop/report/plain_text.rb:14:in
display'
from /Users/michael.hogg/.rvm/gems/ruby-1.9.3-p392@fig/gems/rubocop-0.4.0/lib/rubocop/cli.rb:67:in block in run' from /Users/michael.hogg/.rvm/gems/ruby-1.9.3-p392@fig/gems/rubocop-0.4.0/lib/rubocop/cli.rb:48:in
each'
from /Users/michael.hogg/.rvm/gems/ruby-1.9.3-p392@fig/gems/rubocop-0.4.0/lib/rubocop/cli.rb:48:in run' from /Users/michael.hogg/.rvm/gems/ruby-1.9.3-p392@fig/gems/rubocop-0.4.0/bin/rubocop:12:in
block in <top (required)>'
from /Users/michael.hogg/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/benchmark.rb:295:in realtime' from /Users/michael.hogg/.rvm/gems/ruby-1.9.3-p392@fig/gems/rubocop-0.4.0/bin/rubocop:11:in
<top (required)>'
from /Users/michael.hogg/.rvm/gems/ruby-1.9.3-p392@fig/bin/rubocop:19:in load' from /Users/michael.hogg/.rvm/gems/ruby-1.9.3-p392@fig/bin/rubocop:19:in
eval' from /Users/michael.hogg/.rvm/gems/ruby-1.9.3-p392@fig/bin/ruby_noexec_wrapper:14:in
'rubocop lib/rubocop.rb
Registering cop Rubocop::Cop::LineLength
Registering cop Rubocop::Cop::Tab
Registering cop Rubocop::Cop::TrailingWhitespace
/Users/zhaocai/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rubocop-0.0.1/lib/rubocop/cli.rb:25:in `run': undefined method `each' for nil:NilClass (NoMethodError)
from /Users/zhaocai/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rubocop-0.0.1/bin/rubocop:11:in `block in <top (required)>'
from /Users/zhaocai/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
from /Users/zhaocai/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rubocop-0.0.1/bin/rubocop:10:in `<top (required)>'
from /Users/zhaocai/.rbenv/versions/1.9.3-p194/bin/rubocop:23:in `load'
from /Users/zhaocai/.rbenv/versions/1.9.3-p194/bin/rubocop:23:in `<main>'
Integration with flycheck will make rubocop much more appealing to Emacs users. Integration with other editors would be a good idea as well.
Using Ruby 2.0, the following code block will trigger the "Use def with parentheses when there are arguments" message.
def get_list
@request.get '/user/list', @credentials
end
Currently stuff like a==b?c:d
does not register an offence for the missing whitespace around ?
and :
.
I think I have a fix for it, a pull request coming in shortly.
I've been working on a simple landing page for this project and just finished it. It's a little rough but I think it'll do. I'm not able to make a Pull Request because I've created a new branch (gh-pages
) with only the site source code in it. So you'd have to create a new blank branch (called gh-pages
) so I can make a Pull Request. Of course, if you want to and like the page.
The site is live on my fork of this project. You can have a look at it here. Nothing super, just a simple landing page with some text, built with Bootstrap and based on Intro.js's site. The site is also responsive and as far as I'm concerned IE7 compatible.
As you can see, the site includes some information about what Rubocop is, what it supports, how to install it, and finally how to use it. All of this content is taken from this project's README
and in some parts slightly modified.
Running bundle exec rubocop is a magnitude slower than running rubocop for me.
I'm not sure where this might come from, but I do not experience it with other commands like cane, rails_best_practices or brakeman.
cane 0,34s user 0,01s system 93% cpu 0,378 total
bundle exec cane 1,25s user 0,04s system 99% cpu 1,295 total
rubocop 2,78s user 0,87s system 94% cpu 3,868 total
bundle exec rubocop 95,85s user 3,80s system 99% cpu 1:40,10 total
Is it just me or can you confirm this?
Using ruby 2.0.0-p0 via rbenv.
When i have '$/' in file i get cop 'Prefer
However if replace $/ with $INPUT_RECORD_SEPARATOR
I get warning
W: 15: Global variable `$input_record_separator' not initialized
(wich is true as such variable seems not to exist, returning nil when queried in irb)
Offending file example
/Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/array_literal.rb:12:in `block in inspect': undefined method `[]' for nil:NilClass (NoMethodError)
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block (2 levels) in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:82:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:84:in `block in each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/cop.rb:83:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cop/array_literal.rb:9:in `inspect'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cli.rb:74:in `block (2 levels) in run'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cli.rb:66:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cli.rb:66:in `block in run'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cli.rb:44:in `each'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/lib/rubocop/cli.rb:44:in `run'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/bin/rubocop:13:in `block in <top (required)>'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
from /Users/matt/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rubocop-0.6.0/bin/rubocop:12:in `<top (required)>'
from /Users/matt/.rbenv/versions/1.9.3-p327/bin/rubocop:23:in `load'
from /Users/matt/.rbenv/versions/1.9.3-p327/bin/rubocop:23:in `<main>
I received this error:
An error occurred while TrivialAccessors cop was inspecting /Users/ryan/www/articles/app/models/user.rb.
To see the complete backtrace run rubocop -d.
undefined method `[]' for nil:NilClass
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/trivial_accessors.rb:36:in `is_trivial_reader'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/trivial_accessors.rb:23:in `find_trivial_accessors'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/trivial_accessors.rb:12:in `block in inspect'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:89:in `block (2 levels) in each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:89:in `block (2 levels) in each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:89:in `block (2 levels) in each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:89:in `block (2 levels) in each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:89:in `block (2 levels) in each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:87:in `each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:89:in `block in each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:88:in `each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:88:in `each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:89:in `block in each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:88:in `each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:88:in `each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:89:in `block in each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:88:in `each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:88:in `each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:89:in `block in each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:88:in `each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:88:in `each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:89:in `block in each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:88:in `each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/cop.rb:88:in `each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cop/trivial_accessors.rb:11:in `inspect'
/Users/ryan/www/gems/rubocop/lib/rubocop/cli.rb:89:in `block in inspect_file'
/Users/ryan/www/gems/rubocop/lib/rubocop/cli.rb:80:in `each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cli.rb:80:in `inspect_file'
/Users/ryan/www/gems/rubocop/lib/rubocop/cli.rb:55:in `block in run'
/Users/ryan/www/gems/rubocop/lib/rubocop/cli.rb:37:in `each'
/Users/ryan/www/gems/rubocop/lib/rubocop/cli.rb:37:in `run'
../gems/rubocop/bin/rubocop:14:in `block in <main>'
/Users/ryan/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
../gems/rubocop/bin/rubocop:13:in `<main>'
While scanning this file:
class User < ActiveRecord::Base
extend FriendlyId
friendly_id :username, use: :slugged
include ActiveModel::ForbiddenAttributesProtection
devise :database_authenticatable, :registerable, :lockable, :timeoutable,
:omniauthable, :recoverable, :rememberable, :trackable, :confirmable,
:validatable
belongs_to :avatar_image # Foreign key in users
has_many :articles
has_many :comments
validates :username, presence: true, uniqueness: { case_sensitive: false },
format: { with: /^[\p{L}0-9]{3,15}$/iu }
validates :facebook_page, url: true, length: { maximum: 240 }
validates :website, url: true, length: { maximum: 240 }
validates :blog, url: true, length: { maximum: 240 }
alias_attribute :admin?, :admin
alias_attribute :banned?, :banned
def facebook_account?
provider.present?
end
def picture?
avatar_image.present?
end
def picture_url
picture? ? avatar_image.url : 'placeholder.jpeg'
end
def total_views
published_articles.joins('INNER JOIN views '\
'ON views.article_id = articles.id').count
end
def published_articles
articles.published
end
def paginated_articles(page, per_page)
published_articles.paginate(page: page, per_page: per_page)
end
# Require password to update account if email or password has changed
def update_with_password(params, *options)
password_or_email_changed = (email != params[:email] ||
params[:password].present?)
if password_or_email_changed && !facebook_account?
super
else
params.delete(:current_password)
update_without_password(params, *options)
end
end
# Password isn't required if it's a facebook account
def password_required?
super && !facebook_account?
end
# Create or find a user record from Omniauth Hash
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize do |user|
user.provider = auth.provider
user.uid = auth.uid
user.username = auth.info.nickname.gsub('.', '') if auth.info
user.email = auth.info.email if auth.info
end
end
# create a user for registration based on devise-provided session
def self.new_with_session(params, session)
if session['devise.user_attributes']
new(session['devise.user_attributes'],
without_protection: true) do |user|
user.attributes = params
user.valid?
end
else
super
end
end
protected
# No confirmation if it's a facebook account
def confirmation_required?
facebook_account? ? false : super
end
end
Eg. I don't want to have to worry about cops harassing autogenerated migrations and schemas for not using proper hash syntax. Would be good as a command line switch or something but might be nicer in the .yml! I'm new to ruby so you wouldn't want me near your codebase (hence me using the tool) but this would be a nice addition.
I think we need to handle configuration files in a better way. The problems with the current implementation are:
Enabled
, has a default value. This means that when users update the rubocop gem and get a number of new cops, their old .rubocop.yml
files in the projects should be updated too, but they might forget and they won't see the need for filling in more configuration values because of the defaults..rubocop.yml
files, you have a lot of duplication.I have an idea for a solution. We add a config
directory to the rubocop root. Here we store default configuration files such as all_enabled.yml
which will look like the .rubocop.yml
in the root today. Then we add an include mechanism called based_on
. E.g.:
# .rubocop.yml
based_on: RUBOCOP_HOME/config/all_enabled.yml
LineLength:
Enabled: true
Max: 100
So everything after based_on
will override settings in the included yml file. If you override the settings for a cop, you must specify all parameters, i.e. you can't just set Max
and expect to inherit Enabled
.
And we remove the default handling. Everything must be specified.
For various reasons outlined here http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax it's preferable to use the new expect
syntax instead of should
(which might even be removed in RSpec 3, though this doesn't seem very likely).
JRuby 1.7.2, Found this testing out flycheck:
Checker ruby-rubocop returned non-zero exit code 1, but no errors from output: the `ripper' lib is not supported on JRuby
LoadError: no such file to load -- ripper
require at org/jruby/RubyKernel.java:1027
require at /home/sme/.rbenv/versions/jruby-1.7.2/lib/ruby/shared/rubygems/custom_require.rb:36
(root) at /home/sme/.rbenv/versions/jruby-1.7.2/lib/ruby/1.9/ripper/core.rb:11
require at org/jruby/RubyKernel.java:1027
(root) at /home/sme/.rbenv/versions/jruby-1.7.2/lib/ruby/shared/rubygems/custom_require.rb:1
require at /home/sme/.rbenv/versions/jruby-1.7.2/lib/ruby/shared/rubygems/custom_require.rb:36
require at org/jruby/RubyKernel.java:1027
(root) at /home/sme/.rbenv/versions/jruby-1.7.2/lib/ruby/1.9/ripper.rb:3
(root) at /home/sme/.rbenv/versions/jruby-1.7.2/lib/ruby/shared/rubygems/custom_require.rb:1
require at org/jruby/RubyKernel.java:1027
require at /home/sme/.rbenv/versions/jruby-1.7.2/lib/ruby/shared/rubygems/custom_require.rb:36
(root) at /home/sme/.rbenv/versions/jruby-1.7.2/lib/ruby/gems/shared/gems/rubocop-0.6.1/bin/../lib/rubocop.rb:3
load at org/jruby/RubyKernel.java:1046
(root) at /home/sme/.rbenv/versions/jruby-1.7.2/lib/ruby/shared/rubygems/custom_require.rb:1
Checker definition probably flawed.
1.9 mode is the default, so I wouldn't expect ripper to even be needed. Likely just a jruby issue, but reporting for tracking anyway.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.