by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Vincent
    @vincent-psarga

    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 :) )

    Vincent
    @vincent-psarga
    ok, well after bit more research, that was pretty simple in fact: format('%<duration>.7f', duration: stepdef_key.mean_duration). I did not know the numbers formatting worked as the string ones :)
    CJ Avilla
    @w1zeman1p

    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)

    I'll mostly be checking for Style cops
    halo
    @halo

    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.

    Max Schwenk
    @maschwenk

    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))))
    matrixbot
    @matrixbot

    @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?

    Michael Hagar
    @mehagar

    Hi, I believe I found a bug that has possibly been fixed in a newer version of Rubocop. In version 0.57.2, this code:

    time_period = updated_during ? updated_during : 2.days.ago..Time.now

    is autocorrected to

    time_period = updated_during || 2.days.ago..Time.now

    However, that’s incorrect if updated_during is not nil, because || has a higher precedence than .., whereas ? has a lower precedence than ...

    Ankit Kumar
    @anks333
    how to configure rubocop in vs code, tried installing ruby-rubocop but throwing error env: jruby_executable_hooks: No such file or directory
    can someone help me to configure rubocop in vscode
    Jônatas Davi Paganini
    @jonatas

    Hello friends! Is there any research or ongoing mechanism to allow us to use RuboCop combining autocorrect with user input confirmation?

    I'm asking because today a friend shared a script (https://gist.github.com/jaimerson/57847f25191f58018af06c1c1ea0e4f6) that autocorrects subject names from RSpec/NamedSubject and gives the opportunity to fix it ongoing or accept the suggestions. While cleaning up offenses it would speed up a lot the flow and we could have a default and allow people to edit it if they want through the interactive mode.

    It would also allow us to interactive fix cops that doesn't have autocorrect implementation because of some the dependency of the user input.

    paulgureghian
    @paulgureghian_gitlab
    hi
    paulgureghian
    @paulgureghian_gitlab

    Trying to find the Rubocop yml file. I looked in the .gem and .rvm folders.

    https://imgur.com/a/Hf2htqm

    Andrew Jorgensen
    @ajorgensen
    I have a rubocop question, hopefully this is the right place. I have a custom cop that compares class names to make sure there are no duplicates. The issue that i have is the class names are stored in a class level variable that gets cached in rubocop-daemon between runs so the first run is successful but the second one detects a duplicate class. Is there anything in rubocop that would allow me to clear that cache after the run or a run identifier I can make sure that names are compared within the same run and not across runs?
    The only other way i can think to do it without a before_run, after_run hook or an identifier is to time out the cache after a certain period of time
    Andrew Jorgensen
    @ajorgensen
    It looks like the cops are created new for each source which makes cross file comparison difficult
    Andrew Jorgensen
    @ajorgensen
    sorry the above was actually more of a consequence of using rubocop-daemon rather than rubocop itself
    i was able to work around it by finding the Rubocop::Runner instance and using its object_id as a unique run identifier and then invalidating the cache if the run id is different. This allows us to detect different runs and invalidate the cache. I realize that comparing across all files is probably not a typical use case for Rubocop but in our setup (lots of rails engines) it was important to make sure there were not two classes named the same
    Brandon Weaver
    @baweaver

    @marcandre RE: https://github.com/rubocop-hq/rubocop/pull/7868#issuecomment-642392984

    May not quite be the right place for it but does unlock a lot of interesting potential for really succinct corrections

    Utkarsh Gupta
    @utkarsh2102
    Hiya
    I had a quick question that I am unable to figure out
    My PATTERN can't parse the second call to git, that is, spec.executables.
    Utkarsh Gupta
    @utkarsh2102
    Any clue what am I doing wrong? Or how can I go about fixing this?
    Utkarsh Gupta
    @utkarsh2102
    CC: @marcandre, guess you'd know^ :)
    Marc-André Lafortune
    @marcandre
    @utkarsh2102 The descend operator only looks for the first descendant it encounters. You'll have to split your pattern in two
    Marc-André Lafortune
    @marcandre
    We should consider something do select all that match instead of any that match though.
    Utkarsh Gupta
    @utkarsh2102
    @marcandre, ah, didn't know this, thanks :)
    If it's not much to ask, could you also help me figure out how to do this?
    Marc-André Lafortune
    @marcandre
    I'd first look for the right module, then use def_node_search to find what you're looking for. HTH
    Utkarsh Gupta
    @utkarsh2102
    Gives me a starting point but I'm still unsure. Also, thanks :)
    Daniel Vandersluis
    @dvandersluis
    Is there a recommended way to test a def_node_matcher? Anyone have an example?
    Daniel Vandersluis
    @dvandersluis
    Never mind, I think I figured it out. When a cop is instantiated the node matchers are available publicly so I can just use that in my expectation
    Utkarsh Gupta
    @utkarsh2102
    Hi @marcandre,
    With your new API changes (wrt v1 upgrade notes ), I am not entirely sure which part is broken on my Cop (with RuboCop v0.87.x) :sweat_smile:
    Can you please do a quick PR review of utkarsh2102/rubocop-packaging#4 (whenever you're free!) and suggest the changes? :smile:
    Marc-André Lafortune
    @marcandre
    Sorry @utkarsh2102 , nothing jumps at me as problematic, I'm not sure why you are seeing a difference in behavior
    Please let me know what you find...
    Utkarsh Gupta
    @utkarsh2102
    Thank you, @marcandre, for your review (you the best! :heart:).
    When I run git bisect, I get rubocop-hq/rubocop@f8813e7 from where things started to fail for me :/
    I am still not sure what's wrong, I am trying to figure out and shall let you know in case I get something.
    But really, thank you for your review! It does help me in narrowing some things down!
    (and in case something strikes you about this problem, let me know \o/)
    Marc-André Lafortune
    @marcandre
    How can I reproduce your issue exactly?
    Utkarsh Gupta
    @utkarsh2102
    From rubocop's master, I am running this: git bisect start master v0.86.0 && git bisect run sh -c "cd /home/utkarsh/github/rubocop-packaging; RUBYLIB=/home/utkarsh/github/rubocop/lib rspec" && git bisect reset

    How can I reproduce your issue exactly?

    Or you can just run: rspec on rubocop-packaging with rubocop v0.86 and v0.87.
    With v0.86, the tests pass. With v0.87, the tests fail :disappointed:

    Marc-André Lafortune
    @marcandre
    Ok, let me check
    Utkarsh Gupta
    @utkarsh2102
    Thank you! \o/
    Phil Pirozhkov
    @pirj

    Hey!
    Two quick questions:

    Is 0.89 going to be released soon? My hands are itching to merge the PR (in rubocop-rspec) fixing offences raised by newly introduced cops.

    WDYT of bumping the version in version.rb to the next patch version? We have an edge-rubocop CI job, and it fetches RuboCop from master. It's somewhat confusing to see Using rubocop 0.88.0 from https://github.com/rubocop-hq/rubocop.git (at master@ca9483a) and failures from cops that didn't exist in 0.88.0.

    Marc-André Lafortune
    @marcandre
    👍 and 👍. Or would '0.88.0.dev' be good sufficient?
    I'd like a release of rubocop-ast too.
    Phil Pirozhkov
    @pirj
    Yes! '0.88.0-next' or what SemVer suggests.
    Thanks!
    Marc-André Lafortune
    @marcandre
    I don't know if @bbatsov is on gitter much...
    I just made a release of rubocop-ast.
    Daniel Vandersluis
    @dvandersluis
    is it possible to collect captures from def_search_node?