-
Notifications
You must be signed in to change notification settings - Fork 34
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
Copy c5-conventions/rubocop.yml into the new app #148
Copy c5-conventions/rubocop.yml into the new app #148
Conversation
6bbda03
to
ae0f2f4
Compare
raise "#{command} failed with status #{$CHILD_STATUS.exitstatus}." | ||
end | ||
|
||
output | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was a combo of running rubocop -a
and adding the return results to the function which i wanted to grab the SHA from the c5-conventions repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as it turns out, this didn't actually work. rolled it back to just return the output which i needed for the git ls-remote
.
If rubocop corrects this again, we may need to either suppress the rule or figure out why it's not working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! After talking with @christiannelson I think we need to have the guard clause to ensure this is done only for the C5 raygun-rails template. Otherwise I have a couple Ruby-isms to suggest; see comments below.
lib/raygun/raygun.rb
Outdated
'' | ||
].join("\n") | ||
rubocop_contents = URI.open(rubocop_file) | ||
write_file("#{@app_dir}/.rubocop.yml", prefix + rubocop_contents.string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like using Ruby heredoc for multiline strings like the prefix:
write_file("#{@app_dir}/.rubocop.yml", prefix + rubocop_contents.string) | |
write_file("#{@app_dir}/.rubocop.yml", <<~PREFIX + rubocop_contents.string) | |
# Sourced from #{C5_CONVENTIONS_REPO} @ #{sha}" | |
# | |
# If you make changes to this file, consider opening a PR to backport them to the c5-conventions repo: | |
# https://github.com/#{C5_CONVENTIONS_REPO}/blob/master/rubocop/rubocop.yml | |
PREFIX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or taking it a step further:
IO.write("#{@app_dir}/.rubocop.yml", <<~RUBOCOP_YML)
# Sourced from #{C5_CONVENTIONS_REPO} @ #{sha}"
#
# If you make changes to this file, consider opening a PR to backport them to the c5-conventions repo:
# https://github.com/#{C5_CONVENTIONS_REPO}/blob/master/rubocop/rubocop.yml
#{rubocop_contents.string}
RUBOCOP_YML
lib/raygun/raygun.rb
Outdated
def write_file(filename, contents) | ||
fp = File.open(filename, 'w') | ||
fp.write(contents) | ||
fp.close | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is equivalent to Ruby's:
IO.write(filename, contents)
lib/raygun/raygun.rb
Outdated
@@ -105,6 +107,8 @@ def copy_prototype | |||
|
|||
FileUtils.mv dirs_to_move, app_dir | |||
FileUtils.remove_dir extraneous_dir | |||
|
|||
fetch_rubocop_file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we guard this so we only do it for C5 repos? That way if raygun is used with a third-party template we are not potentially clobbering their rubocop config.
fetch_rubocop_file | |
fetch_rubocop_file if @prototype_repo == CARBONFIVE_REPO |
Sort of like we do here:
Lines 173 to 179 in 03c07eb
def print_next_steps | |
if @prototype_repo == CARBONFIVE_REPO | |
print_next_steps_carbon_five | |
else | |
print_next_steps_for_custom_repo | |
end | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Addressed PR comments
- Added
rspec
and set the default rake task tospec
- Added a test for the
fetch_rubocop_repo
function
raise "#{command} failed with status #{$CHILD_STATUS.exitstatus}." | ||
end | ||
|
||
output | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as it turns out, this didn't actually work. rolled it back to just return the output which i needed for the git ls-remote
.
If rubocop corrects this again, we may need to either suppress the rule or figure out why it's not working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! One minor suggestion below. I am going to test this out locally later today.
Rakefile
Outdated
rescue LoadError | ||
# no rspec available | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this rescue
because we have the rspec dependency listed in the gemspec. If a developer forgets to use bundle exec
that is a legitimate mistake and they should see an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this locally and ran into two issues.
The first is minor: the generated .rubocop.yml
has this header that is misleading and not very useful.
# Configuration hierarchy:
#
# 1. Rubocop defaults
# 2. Carbon Five defaults (this file)
# 3. Project overrides
#
# See http://rubocop.readthedocs.io/en/latest/configuration/#inheriting-configuration-from-a-remote-url for details.
#
It would be nice to strip this out. Or maybe update c5-conventions to just get rid of it altogether? In any case, it's not a blocker for this PR.
The bigger issue is that the generated project results in a broken RuboCop config:
Running RuboCop...
Error: unrecognized cop Rails/ApplicationRecord found in .rubocop.yml, unrecognized cop Rails/HasAndBelongsToMany found in .rubocop.yml, unrecognized cop Rails/RakeEnvironment found in .rubocop.yml
RuboCop failed!
This because the c5-conventions file specifies Rails/*
cops but does not require rubocop-rails
! I think we need to fix this upstream before we can merge this PR. What do you think?
I already fixed that. I think we just need to coordinate the merge with this carbonfive/c5-conventions#10. |
03f8c3d
to
cc37fde
Compare
As for the thing about this comment in the rubocop file
I agree with the fact that we should not include it. I read it a couple times and wondered if it even belongs where it is. If apps are actually pulling this in remotely, it is unlikely that anyone is looking at it so I wonder about the value of those comments. So I'm inclined to update comments in the C5 conventions repo so they make more sense and then they wouldn't have to be trimmed during this copy. And they might provide some valuable information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This all makes sense. I assume you will merge carbonfive/c5-conventions#10 first?
Logged a ticket for this: carbonfive/c5-conventions#12 |
cc37fde
to
39b54e9
Compare
-------- Our connection to the rubocop.yml file in https://github.com/carbonfive/c5-conventions seems fragile. Updates to that repo will affect all consumers out in the world (who we don't know) and may cause issues with their app. We've already seen it affect 1 client project in house. Solution --------- By default, pull the `rubocop.yml` from `c5-conventions` at the time the app is constructed and pin it. This will disconnect the constructed app from the possibly dynamic rubocop file. Additionally, we add some commentary to the top of the file to indcate the SHA which was the original pull and a note to suggest upgrading at the developers' discretion. Changes ------- * by default, fetch the rubocop file from github and write it to the newly created target app * add rspec * add a test for this new functionality (the pull of the rubocop from GitHub) Fixes #146
5deb520
to
860eb23
Compare
Problem
Our connection to the rubocop.yml file in https://github.com/carbonfive/c5-conventions seems fragile.
Updates to that repo will affect all consumers out in the world (who we don't know) and may cause issues with their app. We've already seen it affect 1 client project in house.
Solution
By default, pull the
rubocop.yml
fromc5-conventions
at the time theapp is constructed and pin it. This will disconnect the constructed app
from the possibly dynamic rubocop file.
Additionally, we add some commentary to the top of the file to indcate
the SHA which was the original pull and a note to suggest upgrading at
the developers' discretion.
Changes
newly created target app
rubocop
andrspec
Fixes #146