-
-
Notifications
You must be signed in to change notification settings - Fork 36
General refactoring. #56
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
Conversation
@@ -0,0 +1,6 @@ | |||
StringLiterals: | |||
Enabled: false |
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.
You're missing the Style/
prefix in the preceding line and instead of simply disabling the check, it's better to reconfigure it to our preferred style:
Style/StringLiterals:
EnforcedStyle: double_quotes
You also most likely want to add the following for consistency with the above and with Homebrew code in general:
Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes
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.
The second part will also take care of some of the complaints that remained in the RuboCop output.
Sorry for the rookie mistakes regarding RuboCop - this is my first time configuring/using it 😅. |
No worries, I'm happy to point you into the right direction (or what I believe to be the right direction). I certainly had more experience tweaking those rules in the context of Homebrew. Overall I'm very happy that you came up with this PR on your own. 👍 |
Some of them will already vanish after addressing my comments. Others, like the length and complexity metrics are something I'm less convinced of (or at least I find the limits to be quite harsh), thus I'd be personally alright with: Metrics/AbcSize:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/ModuleLength:
Enabled: false
Metrics/ParameterLists:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false We can sort out most of the remaining items either in the next iteration of this PR or just ignore them for the time being and deal with them in a later PR. Pro Tip: Use |
This looks good to me! I'm going to make all the changes you've recommended tonight. Thanks for the tip about the additional RuboCop flags 😄 |
39b8e03
to
2eb518a
Compare
RuboCop still complains about unaligned parameters/arrays/cases, so I'm probably going to add those to the There's also the matter of the unfortunately named |
I just went ahead and pushed a few commits that address these, partially to see for myself how this will change the code. I'd say that we should address them (I only focused my attention on the
I'm in favor of |
lib/macho/macho_file.rb
Outdated
MachO::Section64 | ||
else | ||
raise ArgumentError, "not a valid segment" | ||
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.
If this looks unappealing to you, we could steal the following snippet from Homebrew's .rubocop.yml
to gain a bit more flexibility with these:
# we prefer compact if-else-end/case-when-end alignment
Lint/EndAlignment:
AlignWith: variable
Style/CaseIndentation:
IndentWhenRelativeTo: 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.
Yeah, I do generally prefer the original form.
I'll add those instructions to the .rubocop.yml
.
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 can see arguments for both styles, but I'm happy with either (but more used to the unindented style due to my Homebrew work).
Looks great to me! I'll squash these down into the RuboCop and general refactoring commits in a moment.
As did I. It might make sense at some point in the future to align the unit tests with our RuboCop enforced style, but that's not particularly high on my list of priorities for |
lib/macho/macho_file.rb
Outdated
segments.each do |seg| | ||
sections(seg).each do |sect| | ||
next if sect.size == 0 | ||
next if sect.size == 0 # rubocop:disable Style/ZeroLengthPredicate |
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 like RuboCop still complains here about a Style/NumericPredicate
violation. I'd personally just prefer zero?
here, since it's equally readable (IMO, of course) and we don't have to disable two checks in-line.
(Ignore all of that, replacing this with Section#empty?
)
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.
👍 To quote from the other related code comment:
I was still on RuboCop 0.41.2. That's why I didn't notice this was now causing multiple complaints and this suggestion isn't exactly practical.
6f753fc
to
d169801
Compare
Great! I think it's sufficient to tweak those style issues incrementally as the code gets modified (or maybe in a follow-up PR for the test suite as a whole). A good way to improve incrementally is to let your editor highlight RuboCop style violations for you while coding. I'm using SublimeLinter with its RuboCop plugin for that and loving it. |
.rubocop.yml
Outdated
Style/TrailingCommaInArguments: | ||
EnforcedStyleForMultiline: no_comma | ||
|
||
# TODO: disable in the future |
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.
Should that be “re-enable in the future”?
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.
Yep. I was thinking disable as in "disable these lines", but re-enable makes much more sense.
Thanks! I knew about SublimeLinter, but I didn't know about its RuboCop plugin. I'll install it now 😄 |
d169801
to
a4eecf8
Compare
lib/macho/load_commands.rb
Outdated
raw_string = view.raw_data.slice(lc_str_abs..lc_end) | ||
@string, null_byte, _ = raw_string.partition("\x00") | ||
raise LCStrMalformedError.new(lc) if null_byte.empty? | ||
@string, null_byte, = raw_string.partition("\x00") |
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'm not liking this resolution. The trailing comma on the left-hand side is too easy to overlook. How about the following?
@string, null_byte, _padding = raw_string.partition("\x00")
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 was thinking the same thing. _padding
sounds good to me!
a4eecf8
to
5ac8025
Compare
72613bc
to
6891bcd
Compare
6891bcd
to
e0adad9
Compare
Rebased; I'm happy with the state of this PR if you are 🎉 |
Rebased … and checked whether |
Hmm, RuboCop doesn't like that we never use the |
e0adad9
to
e089598
Compare
Could you try and adopt a workflow that looks something like this?
Sorry if I'm wronging you with this, but it feels like you're sometimes skipping the second step. I don't think I should be pointing out stuff like in the following terminal output and we could be both more productive if I didn't have to, not only because of the incurred roundtrip delay. $ rubocop -D -f simple lib
== lib/macho/load_commands.rb ==
C:403: 1: Style/EmptyLines: Extra blank line detected.
== lib/macho/open.rb ==
C: 1: 1: Style/Documentation: Missing top-level module documentation comment.
12 files inspected, 2 offenses detected (And if in doubt: No, I'm not referring to the second offense that has been there from the start. I'm talking about the other one that has been introduced due to the rebase.) |
You're not, I haven't been proactive about checking work that I think is correct. Sorry for imposing the extra burden on you, it's not fair of me to do. (That last offense looks like another one of RuboCop's screw-ups - the |
Bring code in line with RuboCop. Freeze constant objects, raise exceptions without #new where possible. Eliminate unnecessary `self` prefixes and correct formatting. Use 1.9-style hashes where possible. Align parameters and array items. Rename 'set_*' methods to 'update_*'. Rename 'get_*' methods to 'populate_*'
e089598
to
cba3369
Compare
Thanks! 🙇
We can look into this later. I'm not 100% sure how RuboCop is performing the check, but I'm relatively confident it works on a file by file basis and thus cannot correlate information from different files. (It's perfectly normal to let it check one file only.) Since modules and classes can be reopened any time, I suspect it's using some heuristics to determine whether the module is new (and thus needs to be documented) or is just being reopened and added to … |
Yeah, that would make sense. For the time being I'm happy with just ignoring that line in |
Yes, agreed. It's not exactly bothering me and we can ignore it for the time being. Slightly off topic, but I guess you'd like to cut a new release soon? Even if it's not 1.0 time yet, I think we have accumulated quite a few important changes since the last release and it would make sense to cut a new one. I think it would also makes sense to bring this new release to Homebrew proper, so that the test bot can throw some real world binaries at it and we can see how this goes, not to mention that we'll need to make some minor adjustments to the code that is bridging between the Homebrew-internal API and the |
I was just about to! It'll be up in a moment. |
I'll also open a PR on |
Another low-priority PR, just cleans up the code a bit and adds a
.rubocop.yml
for future style enforcement.rubocop
complains about roughly 100 other things in thelib/
tree, although most of them are even less significant (methods over 10 lines, for example).All of the unresolved violations are here: ruby-macho-rubocop.txt
cc @UniqMartin