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

Fix rubocop_todo link injection when YAML doc start sigil exists #9406

Merged
merged 1 commit into from Jan 24, 2021

Conversation

dduugg
Copy link
Contributor

@dduugg dduugg commented Jan 22, 2021

The rubocop --auto-gen-config script will insert inherit_from: .rubocop_todo.yml at the top of the rubocop config file if the line doesn't already exist. However, if the config file has a YAML document start sigil (---), this will elide the remainder of the config file when running rubocop. This PR resolves the issue by injecting the inherit_from entry after the first such sigil, if one exists.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

Copy link
Member

@dvandersluis dvandersluis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thanks for the fix!

f.write "inherit_from:#{file_string}\n"
f.write "\n#{rubocop_yml_contents}" if /\S/.match?(rubocop_yml_contents)
end
lines = /\S/.match?(rubocop_yml_contents) ? rubocop_yml_contents.split("\n", -1) : []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity and simplicity:

Suggested change
lines = /\S/.match?(rubocop_yml_contents) ? rubocop_yml_contents.split("\n", -1) : []
lines = rubocop_yml_contents.blank? ? [] : rubocop_yml_contents.split("\n", -1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion @dvandersluis. Unfortunately I see test failures locally with this suggestion (via rspec ./spec/rubocop/cli/cli_auto_gen_config_spec.rb). I think it's due to the nonequivalence when rubocop_yml_contents is nil. (Specifically, rubocop's blank? monkey-patch differs from rails by being undefined on nil.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, yeah looks like that's because rubocop_yml_contents can be nil if the file doesn't exist because it's not otherwise initialized in add_inheritance_from_auto_generated_file 🤔

@dduugg
Copy link
Contributor Author

dduugg commented Jan 22, 2021

Can anyone help me understand how to make cc-upload-coverage work? Looks like it has something to do with CC_TEST_REPORTER_ID being committed but not supported on forks.

@dvandersluis
Copy link
Member

Can anyone help me understand how to make cc-upload-coverage work? Looks like it has something to do with CC_TEST_REPORTER_ID being committed but not supported on forks.

I've seen this intermittently on other PRs but it often is not persistent. It won't block merging this PR.

@dvandersluis dvandersluis merged commit 2a48e65 into rubocop:master Jan 24, 2021
@dvandersluis
Copy link
Member

Thank you!

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

Successfully merging this pull request may close these issues.

None yet

2 participants