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
    Yes, no problem; they'll be from the first match, if any...
    Now that we have the descend operator "", there's less need fordef_search_node`
    Daniel Vandersluis
    @dvandersluis
    How do I access the captures?
    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!