The think is that we want to write it like
def file_params
params
.require(:file)
.permit(
:description,
:user_id,
:content_type,
:created_at,
:updated_at,
:unit_id,
:document_id,
:document_type,
:sort_id,
:is_deleted
)
end
I know I could write it on one line but we want to have it like this.
In generall we think to 10 lines method like is good. For some controllers we have more then 10 parameters and need more then 10 lines.
Bit of an out there idea I'd be interested in a sanity check on. Javascript has the idea of codemods, I kinda want to try and make the same thing in Ruby. Rubocop already has a lot of work done on top of parser, including the NodePattern syntax and autocorrect capabilities.
Is there a possibility of generalizing the autocorrect capability into a code rewrite gem?
expiry_date
to and instance of Quote
object object.expiry_date
in the Quote
object? because it seems more reasonable than try to create a linter for it. Make the interface fail or warn developers about it. When they run tests they will know the api is no longer going to support it.
Dir[pat]
, some_array[x], etc
rubocop
and I don't know which those are or why anything has changed
Hi all,
I'm having some difficulties finding a good solution to my current issue. In the project I work on (cucumber-ruby), I'm getting Rubocop errors on some string formatting. We have enforced annotated
style for string formatting:
Style/FormatStringToken:
EnforcedStyle: annotated
but we also use formatting to specify number of decimals to keep in stone functions, eg:
def format_duration(seconds)
m, s = seconds.divmod(60)
"#{m}m#{format('%.3f', s)}s"
end
And of course, rubocop complains that this is not annotated style:
Style/FormatStringToken: Prefer annotated tokens (like %<foo>s) over unannotated tokens (like %s).
@io.print format_string(format('%.7f', stepdef_key.mean_duration), :skipped) + ' ' unless config.dry_run?
How to solve this kind of problem ? (hopefully I'm on the right channel :) )
Anyone happen to have a link handy for where I might learn about how to initialize and run rubocop directly in Ruby? I'm trying to build something to check snippets of ruby in some documentation so the source file is a view template not a ruby file and contains other languages. I want to pass a string in Ruby to some actor and have it return cops or some such.
For javascript, I'm doing something like
Eslintrb.lint(raw_code, :eslintrc)
Hi! I have a question.
I have a rubocop.yml
on Github, which I inherit_from
in all my projects. Some projects are pure Ruby, some Rails, and some use RSpec.
It is fine to require: rubocop-rails
in a Rails project, naturally.
But in a pure Ruby project I would not want to demand that the rubocop-rails
gem is installed (neither should other developers have to install that gem, nor is it needed on CI).
So, how would I organize my shared rubocop config?
I cannot just specify any Rails/
cop in it, because that raises an error here
Similarly, the RSpec cops should only run in projects that use RSpec.
My idea is to have a rubocop.ruby.yml
and a rubocop.rails.yml
etc. on Github and inherit only the ones I need in my project.
Is that the recommended solution? I thought it was nice to have only one yml file with all cops, but I don't see how I could achieve that without the disadvantages I tried to describe.
Thank you very much.
curious why ruby-parse considers a block that has multiple lines to be nested within a begin. I know this isn't a rubocop question, just trying to figure out how one would generically say:
this method call within a block of this type
is it easier to do that or
this block with this method call within
create_table :a_table do |z|
z.goober :name
z.string :col
end
create_table :a_table do |z|
z.goober :name
end
parsed
(begin
(block
(send nil :create_table
(sym :a_table))
(args
(procarg0
(arg :z)))
(begin
(send
(lvar :z) :goober
(sym :name))
(send
(lvar :z) :string
(sym :col))))
(block
(send nil :create_table
(sym :a_table))
(args
(procarg0
(arg :z)))
(send
(lvar :z) :goober
(sym :name))))
@myii:matrix.org
Hi, loving rubocop
, we've deployed it across over 60 of our repos under https://github.com/saltstack-formulas. Found an issue with rubocop -a --safe
, the first time it's actually caused a breakage. This is the section, before and after:
Resulting in:
test/integration/default/controls/config_spec.rb:158:35: F: Lint/Syntax: unterminated string meets end of file
Worth a bug report?