RuboCop: Fix infinite loop in autocorrection in Graphql/Descriptions

Problem

The cop Graphql/Descriptions auto-corrects the missing full stop at the end of a sentence. The missing auto-correction won't check if period was inserted. leading to an infinite loop when running rubocop -a --only Graphql/Descriptions.

The stacktrace looks like:

rubocop -a app/graphql/types/alert_management/alert_type.rb
Inspecting 1 file
C

Offenses:

app/graphql/types/alert_management/alert_type.rb:83:7: C: [Corrected] Graphql/Descriptions: description strings should not contain the demonstrative "this". See the description style guide: https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#description-style-guide
      field :event_count, ...
      ^^^^^^^^^^^^^^^^^^^
app/graphql/types/alert_management/alert_type.rb:86:121: C: Layout/LineLength: Line is too long. [258/120]
            description: 'Number of events of this alert........................................................................................................................................................................................................',
                                                                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 files inspected, 2 offenses detected, 1 offense corrected
Infinite loop detected in /home/ashvith/Projects/gitlab-development-kit/gitlab/app/graphql/types/alert_management/alert_type.rb and caused by Layout/LineLength, Graphql/Descriptions
/home/ashvith/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.38.0/lib/rubocop/runner.rb:290:in `block in iterate_until_no_changes'
/home/ashvith/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.38.0/lib/rubocop/runner.rb:286:in `loop'
/home/ashvith/.asdf/installs/ruby/2.7.5/lib/ruby/gems/2.7.0/gems/rubocop-1.38.0/lib/rubocop/runner.rb:286:in `iterate_until_no_changes'

Proposed solution

  • 1️⃣ Disable autocorrection (currently done via AutoCorrect: false In any case we need to add specs to cover these edge cases (maintenancetest-gap)

  • 2️⃣ Autocorrect each check

Prior discussions

The following discussion from !104940 (merged) should be addressed:

  • @splattael started a discussion: (+2 comments)

    Question (non-blocking) It seems this cop does support autocorrect only for appending the full stop at the end of an sentence.

    I wonder what happens if the cops complains about, say, "this". Does it append the full stop anyway when used with rubocop -a? 🤔

    Moreover, we could autocorrect this to the 🤷

    Again, non-blocking and just a thought for future us.

Edited by Ashvith