Using a Rails 4 app I would like Rubocop to ignore lines with comments (just a comment or some code with an end of line comment) when checking if a line is to long. Is there a way to do this?
相关问题
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
- ruby 1.9 wrong file encoding on windows
- gem cleanup shows error: Unable to uninstall bundl
相关文章
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- Segmentation fault with ruby 2.0.0p247 leading to
- How to detect if an element exists in Watir
- uninitialized constant Mysql2::Client::SECURE_CONN
- ruby - simplify string multiply concatenation
You can use the following comment with rubocop to ignore a specific rule:
You can also ignore whole files by adding them to
.rubocop.yml
:i think the basic idea here is that you want to enforce line length, no matter what is after n characters. the default to 80 characters is some cargo cult for old terminal windows that could only hold that number of chars. the only option that i saw in the code is an option to allow urls that might exceed the character limit.
you can ignore whole files, i guess that's not what you are looking for.
There is a way to ignore cops on a per line basis.
There is also a way to do it via configuration file.
Run
rubocop --auto-gen-config
and it will generate a file that you can use to disable the offenses.The command also gives a hint on what to do to load those options.
On a line per line basis, you can enable and disable the cops as well.
You can also do more than one rule at a time in your code.
By using an inline directive, the directive becomes valid only for that line, and it would look like this:
You can read a ton more about RuboCop in its official manual.
To find all the rule names its worth looking in the rubocop config files
cyberwiz says - "run
rubocop -D
when I need the rule names rather than looking in the documentation." Update: This is now the default behavior without the flag.It's possible to define regex patterns to automatically ignore certain lines in
rubocop.yml
, so you could choose to ignore all lines starting with a#
character:This could be improved so that "indented" comment lines (i.e. whitespace followed by a
#
character) are also ignored, if that's what you want.Note that this doesn't account for lines of code that end with a comment, though: