Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Marc-André Lafortune
    @marcandre
    Actually I was wrong, sorry. The doc says "[If it does not end with '?'], it yield all descendants which match.". So my_node_search do |first_capture, second_capture| ...
    Alex Prokopev
    @Pr0p1k
    Hi, I have a specific question:
    Some additional gems, like rubocop-performance or rubocop-rails may be used with different versions of rubocop, can they have different cop lists in such cases? E.g.: In the first case I have rubocop-rspec version 1.42.0 and rubocop version 0.87; in the second case I have rubocop-rspec version 1.42.0 and rubocop version 0.89. Will I get the same cops in both cases?
    Phil Pirozhkov
    @pirj
    @Pr0p1k You'll have the same RSpec cops, and you'll have a different set of base cops.
    0.89 was an especially productive release with over a dozen of new cops. You can check what has been changed on the releases page https://github.com/rubocop-hq/rubocop/releases or in the https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md
    Alex Prokopev
    @Pr0p1k
    @pirj, I mean is it possible to have a situation when an additional gem (e.g. rubocop-rspec or other) will have different cops (excluding those from rubocop gem) depending on rubocop version it's run with?
    Marc-André Lafortune
    @marcandre
    AFAIK, no gem is designed to have conditionally defined cops like that. When a cop needs a new feature, the gem requirement is bumped.
    Alex Prokopev
    @Pr0p1k
    @marcandre, thanks!
    Utkarsh Gupta
    @utkarsh2102
    Hey!
    In case I want to remove the entire line with AutoCorrector, how do I do that?
    I am doing corrector.remove(node.loc.expression)at the moment, but it leaves behind an empty line. I want to remove the empty line as well.
    And I am not sure how to do that?
    Phil Pirozhkov
    @pirj
    @utkarsh2102 You're probably looking for range_by_whole_lines https://github.com/rubocop-hq/rubocop/blob/master/lib/rubocop/cop/mixin/range_help.rb#L69
    Utkarsh Gupta
    @utkarsh2102
    @pirj, aren't you just amazing? :)
    Thanks a lot! This was precisely what I needed! \o/
    Daniel Vandersluis
    @dvandersluis
    @marcandre I think %CONST in nodepattern doesn't work in ruby 2.4 if it's a Set (and it doesn't seem to work at all with an array). There's no test for that in rubocop-ast, but I'm getting this failure in rubocop-performance: https://app.circleci.com/pipelines/github/rubocop-hq/rubocop-performance/341/workflows/528ddd46-d4f6-4dc5-883c-fc02cc002540/jobs/2155
    Daniel Vandersluis
    @dvandersluis
    actually looks like there is a test for sets, but it has some gated logic so I wonder if that's to handle 2.4?
    Daniel Vandersluis
    @dvandersluis
    Yeah looks to be the case because Set#=== wasn't added until 2.5
    I'm going to open an issue on rubocop-ast
    Daniel Vandersluis
    @dvandersluis
    Never mind you fixed it already haha 🤦🏻‍♂️
    Marc-André Lafortune
    @marcandre
    I want to auto-correct a node by adding a new line of code after it (with the same indent). Is there a helper for that?
    Phil Pirozhkov
    @pirj
    @marcandre I'm not sure if there's a guideline for that, but it seems that cops work as a team, i.e. one cop can do a dirty job inserting a line of code with an improper indentation, and others would further fix it.
    A well-known LineLength cop relies on a number of other cops to further format the code https://github.com/rubocop-hq/rubocop/blob/07c21d32408ecd5713578d50445387c89341815d/lib/rubocop/cop/layout/line_length.rb#L20
    I don't have a good understanding how rubocop --only <dirty-cop-that-relies-on-others-to-clean-it-all-up> is supposed to work though.
    Marc-André Lafortune
    @marcandre
    Sure, indentation isn't a strict requirement. The rest should be easy but taking care of comments and heredocs makes it non trivial; there probably should be a helper for that.
    In any case, I gave up doing the right thing, hacked something for my use and delegated 😆 rubocop-hq/rubocop#8724
    Alex Prokopev
    @Pr0p1k
    Hi, when Rubocop is used by another tool, it works fine for highlighting issues, but it doesn't provide info about autocorrectability, and if the tool wants to provide option to fix the offence on the highlighted area, it has to know whether the exact offence can be corrected (may depend on context) to avoid false-positives and so on. Do you have any plans or concerns regarding this? It may be just an option like --autocorrect-info to include it in JSON report
    Phil Pirozhkov
    @pirj
    @Pr0p1k You can set a different output format with rubocop --format json, and e.g. this JSON format gives you information if it's auto-correctable or not. Excerpt:
    {"path":"lib/rubocop/cop/rspec/describe_class.rb","offenses":[{"severity":"convention","message":"Extra blank line detected.","cop_name":"Layout/EmptyLines","corrected":false,"correctable":true,"location":{"start_line":51,"start_column":1,"last_line":52
    Alex Prokopev
    @Pr0p1k
    @pirj Thanks! I've it in sources right now, but there's no mention in the docs, probably should be updated.
    Phil Pirozhkov
    @pirj
    @Pr0p1k A pull request to mention this option in docs is welcome!
    Bozhidar Batsov
    @bbatsov
    It's nice to see this Gitter is still alive. I had completely forgotten about it. :D
    Bozhidar Batsov
    @bbatsov
    I don't know if @bbatsov is on gitter much...
    Not really. Too many chats for me. :D
    At some point it seemed to me that Gitter was declining as many projects moved their chats to other Platforms and I stopped using it.
    Marcos de Melo
    @marcosdemelo
    Hello, can anyone guide me if the --parallel parameter can be replaced by a .rubocop configuration?
    Phil Pirozhkov
    @pirj
    @marcosdemelo Not sure how this option can be added to .rubocop.yml, even though it's mentioned in the docs https://github.com/rubocop-hq/rubocop/blame/c1b7dce1fc7af1ad13ab1fa975b31312925f6109/docs/modules/ROOT/pages/usage/basic_usage.adoc#L259
    But you should definitely give RUBOCOP_OPTS a try.
    I would suggest loading RUBOCOP_OPTS with https://github.com/direnv/direnv, but it's only my personal preference.
    Marcos de Melo
    @marcosdemelo
    I also found no references in the documentation. Searching the code I also found little reference. It appears that this has not been documented or has been experimental. Anyway, I will continue using it even from the command line. Thank you for your attention @pirj.
    Lorenzo Gabriele
    @lolgab
    Hi everyone :)
    We at Codacy use rubocop ( it works very well, I have to say ).
    Now we're adding a feature to comment on PRs with the suggested changes by tools.
    I'm trying to integrate this with rubocop.. Is there a way to have the autocorrection for a cop inside the json report? The only way out I see is to run the autocorrect, generate a diff, and manually match the diff to the cops in the json report..
    Do think it's doable to add the modified line or the changes to the json report ?
    Phil Pirozhkov
    @pirj
    Hi @lolgab
    Does --format json work for you? There is a number of different formats you can try. Check rubocop --help for a complete list.
    Lorenzo Gabriele
    @lolgab
    @pirj Thanks, I already use the json format actually.. I was asking if there was a way to include the auto-correction text inside this json report ( or something to extract it )
    Lorenzo Gabriele
    @lolgab
    At the moment you can get the diff ( by running rubocop on stdin and diffing the result with the file) but you need to guess which cop generated which diff.. Having rubocop exporting it would allow know with 100% accuracy which cop does what it does.
    ShalokShalom
    @ShalokShalom
    is there a way to check for pure functions?
    Aashish Gangwani
    @aashishg
    hi guys, thanks for this channel, i am not able to autocorrect linelength
    any way to do this?
    Oleksandr Bratashov
    @abratashov

    Hello Rubocop team!
    Could you help to find how to implement a custom Rubocop rule for checking git branch naming convention?
    I need to check the correctness of git branch naming - it should contain ticket ID.
    I see, Rubocop processes only text nodes and checks only text lines. So, is it possible to define a rule that will be run only once to check one custom condition that is not related to the code but only to business logic(state of git repository)?

    Thanks!

    P.S.

    Also created duplicates of this question here:

    1. https://stackoverflow.com/questions/71601687/how-to-implement-a-custom-rubocop-rule-for-checking-git-branch-naming-convention
    2. https://github.com/rubocop/rubocop/discussions/10470
    AVarnavskiy
    @AVarnavskiy
    Hi! i do code autocorrect with option --disable-uncorrectable https://docs.rubocop.org/rubocop/usage/autocorrect.html#generating-comments
    After that comments # rubocop:todo are generated. The next time I run the command "rubocop some_file", I want to see all offenses, even if there are comments "# rubocop:todo" in the code. Can I ignore comments "# rubocop:todo" when scanning code with command "rubocop some_file"?
    quintasan
    @quintasan:matrix.org
    [m]
    I'm confused by AutoCorrector, https://docs.rubocop.org/rubocop/development.html#autocorrect says that you only need to extend AutoCorrector and then add_offense will yield a corrector object. However, when I do that, my specs fail with undefined method autocorrect which suggests that I should implement autocorrect method in my cop. When I do, it's "automagically" called with the node as an argument, the corrector is nowhere to be seen. Am I doing it wrong? I'm running Rubocop 0.93.1
    quintasan
    @quintasan:matrix.org
    [m]

    :point_up: Edit: I'm confused by AutoCorrector, https://docs.rubocop.org/rubocop/development.html#autocorrect says that you only need to extend AutoCorrector and then add_offense will yield a corrector object. However, when I do that, my specs fail with undefined method autocorrect which suggests that I should implement autocorrect method in my cop. When I do, it's "automagically" called with the node as an argument, the corrector is nowhere to be seen. Am I doing it wrong? I'm running Rubocop 0.93.1

    EDIT: Here's the code I currently have – https://gitlab.com/-/snippets/2361004

    quintasan
    @quintasan:matrix.org
    [m]

    :point_up: Edit: <del>I'm confused by AutoCorrector, https://docs.rubocop.org/rubocop/development.html#autocorrect says that you only need to extend AutoCorrector and then add_offense will yield a corrector object. However, when I do that, my specs fail with undefined method autocorrect which suggests that I should implement autocorrect method in my cop. When I do, it's "automagically" called with the node as an argument, the corrector is nowhere to be seen. Am I doing it wrong? I'm running Rubocop 0.93.1</del>

    <del>EDIT: Here's the code I currently have – https://gitlab.com/-/snippets/2361004</del>

    It turns out I needed to inherit from Rubocop::Cop::Base

    Augusts Bautra
    @Epigene
    Hi, a question about https://docs.rubocop.org/rubocop/1.32/index.html search functionality - why doesn't it support cop documentation lookup? I try stuff like Layout/LineLength, LineLength, ParenthesesAsGroupedExpression, nada.
    Screenshot 2022-07-28 at 13.52.35.png
    Phil Pirozhkov
    @pirj
    It was certainly working before @Epigene . Do you want to take a stab at fixing it?
    Phil Pirozhkov
    @pirj
    @quintasan:matrix.org You should be looking the documentation of the version you're using, https://docs.rubocop.org/rubocop/0.93/development.html#auto-correct
    But I'd recommend updating. 1.0 is just one step away from 0.93.1.
    And you won't have to update your cops after (but if you would, see https://docs.rubocop.org/rubocop/v1_upgrade_notes to help you)