Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regenerating .rubocop_todo.yml can modify .rubocop.yml #11652

Closed
Earlopain opened this issue Mar 2, 2023 · 0 comments
Closed

Regenerating .rubocop_todo.yml can modify .rubocop.yml #11652

Earlopain opened this issue Mar 2, 2023 · 0 comments

Comments

@Earlopain
Copy link
Contributor

Earlopain commented Mar 2, 2023

I'm ignoring rubocop violations in CI by only including the rubocop todo file when an environment variable is set.
I'm still interested in these failures locally, but don't want them to cause the jobs to fail.

When I recreate the todo file it shifts the include out of the conditional, which changes the meaning.


Expected behavior

It should leave the existing file alone.

Actual behavior

The file gets modified to the following:

inherit_from: .rubocop_todo.yml

<% if ENV["CI"] %>

<% end %>

Steps to reproduce the problem

Have the following at the top in your .rubocop.yml and run rubocop --auto-gen-config

<% if ENV["CI"] %>
inherit_from: .rubocop_todo.yml
<% end %>

RuboCop version

$ [bundle exec] rubocop -V
1.46.0 (using Parser 3.2.1.0, rubocop-ast 1.26.0, running on ruby 3.1.3) [x86_64-linux-musl]
  - rubocop-erb 0.2.3
  - rubocop-rails 2.17.4
jonas054 added a commit to jonas054/rubocop that referenced this issue Oct 21, 2023
The problem with the existing algorithm, for generating the inherit_from line
in --auto-gen-config runs, was that we started by removing the inherit_from
(if present) and then inserted it later.

The things we must deal with in the algorithm are
* there could be a pre-existing inherit_from in .rubocop.yml, or not
* there could be a YAML doc start ---, or not
* there could be inheritance from one or multiple files

A more robust approach to the removing, generating, and re-inserting is to
assume that any pre-existing inherit_from directive is already in the right
place. By replacing it with a placeholder and later replacing the placeholder
with the new inheritance directive, we will get it right without much effort.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant