-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Conversation
# Offense count: 32747 | ||
# Cop supports --auto-correct. | ||
# Configuration parameters: EnforcedStyle, SupportedStyles. | ||
Style/StringLiterals: |
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.
Style/StringLiterals
: This one has the most offenses. I seemed to notice the homebrew style is to prefer double quotes in most cases, except when too much escape sequences come in. This can be set up by using EnforcedStyle: double_quotes
instead of the default.
Default rubocop configuration can be seen here, including possible alternative settings for each cop. |
We're using the Ruby Style Guide in case that helps at all. |
Most of Rubocop defaults follow that guide already. It seems |
@@ -82,7 +82,7 @@ class ExampleFormula < Formula | |||
# 64bit binary/library). TODO: better explain what this means for PPC. | |||
option :universal | |||
option "with-spam", "The description goes here without a dot at the end" | |||
option "with-qt", "Text here overwrites the autogenerated one from `depends_on "qt"`" | |||
option "with-qt", 'Text here overwrites the autogenerated one from `depends_on "qt"`' |
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.
Needed a nudge here, else the file was unparsable.
After enforcing double quotes, 19k violations remain on that one. Many of them are C-style single-char strings. |
|
||
# Offense count: 54 | ||
# Cop supports --auto-correct. | ||
Style/CharacterLiteral: |
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.
All of them are in the same file. Rubocop recommends using string delimiters instead (I didn't even know about this syntax)
See https://github.com/Homebrew/homebrew/blob/290934c096c25482a89500c7ce1c95c7043e434c/Library/Homebrew/cmd/doctor.rb#L73; most of the code in that file predates the |
08365a7
to
b805c16
Compare
Just a quick note that I'm still working on this, but I have a few deadlines not to miss. |
Just FYI: I'm wanting to integrate something like this into our CI for new formulae/files so I'd be interested in pushing whatever's ready. |
OK, turns out I'll have some spare time tomorrow, so I'll dive into this again and push some stuff for you. |
One thing that might help move this along quicker is if we only enable it on the formula directory for now. Is that something that can be done? We have a pretty good idea of what formula style should look like, but the style guidelines for the "core" may differ somewhat, as it is more like actual application code than the domain-specific code in formulae. Perhaps we can enable it for formulae now and worry about core later? |
Yeh, I'm planning on setting it up so, initially at least, we're running it on individual (new) files rather than all of them. |
@jacknagel that's totally possible to set up, we just need to have one |
I noticed this perl backref pattern: version_info = `#{emacs_binary} --version`
version_info =~ /GNU Emacs (\d+)\./
major = $1 There are only a few occurrences in formulas (vs ~90 in the core) and some of them may be dangerous to the untrained eye, or its intrinsic untested branching quickly overlooked. It could be useful to enforce the rule on Formula. |
Please note that due to a rubocop bug it may be needed to write |
Need your feedback on x = [
"foo",
"bar"
]
# vs
x = [
"foo",
"bar", # final comma presence makes things easy to reorder, insert or delete
] See gcc formula for a concrete example. Ruby style guide is mute on that point, and currently it's about 40 vs 20 respectively. I personally prefer the latter style very much (for pragmatic reasons, as it's very editor friendly). What's your opinion on this? |
Let's just disable these.
I prefer the latter here, actually, as it's more obvious what it's doing to non-Ruby folks.
Definitely prefer the trailing comma too. |
Enforcing SpaceAroundOperators is very useful for readability and recommended by the style guide. Yet it may conflict with the current use of bin/"foo"
# vs
bin / "foo" # seems striking at first, but mostly because we're not used to it Disabling SpaceAroundOperators comes at the cost of people landing random space presence around operators, as each one seems (violations do show frequent inconsistencies, although spacing things is favored) to have its own preferences, or rather, tolerance. On the other side of the coin, no-space-around- |
There's no way currently to enforce forbidden use of |
I prefer the prior wrt |
Pushed an update. As we said before, please disregard the formula fixes as only |
This needs rebased on |
825cec6
to
6cb0a88
Compare
Removed formula fixes, and squash-rebased rubocop files. I had to remove the simple inheritance thingy because it seems to make things a bit flaky since I named both levels |
An issue is opened upstream to enforce |
|
Style/Tab: | ||
Enabled: false | ||
Style/TrailingBlankLines: | ||
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.
This can't live in the Formula directory, unfortunately, as everything in there is treated as a formula. Let's just do a single file in Library
instead.
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.
OK I'll move it up, although please note it'll apply to the whole tree. I'm surprised there's no globbing though: what if I happen to have a go.rb~
or .DS_Store
in there?
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.
There's a bunch of known issues with this but it is what it is for now, sadly.
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.
May as well consolidate the two in this case: I'm not convinced we need separate rules (for now) for Library/Formula
and Library/Homebrew
.
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 core of Homebrew ignores non-.rb files, but things like test-bot that read paths from diff output do not.
# excerpts:
assert (output_dir/"url.txt").read.include?("http://brew.sh")
rm_rf (couchdb_share/"www/script/test/geocouch")
assert (Pathname.pwd/"foo").read.include? "hello homebrew!"
inreplace (share/"geocouch/geocouch.plist"), "%bindir%/%couchdb_command_name%", \
cd ("yara-python") do
cd (buildpath+"Ghcsource/tests") do I can understand the will of consistently not using parentheses for method calls and spacing things like we're the shell, but from an outsider point of view not intimate with ruby's parser, this can be highly confusing, and given the low number of occurences I'd favor leaving the cop active. What's your take on this one? |
system "make", "-C", "ace", "-f", "GNUmakefile.ACE",
"INSTALL_PREFIX=#{prefix}",
"LDFLAGS=",
"DESTDIR=",
"INST_DIR=/ace",
"debug=0",
"shared_libs=1",
"static_libs=0",
"install"
# into
system "make",
"-C", "ace", "-f", "GNUmakefile.ACE",
"INSTALL_PREFIX=#{prefix}",
"LDFLAGS=",
"DESTDIR=",
"INST_DIR=/ace",
"debug=0",
"shared_libs=1",
"static_libs=0",
"install" Do you think the second style is suitable for formulas or should I disable the cop (created an issue upstream)? It sounds sensible to have |
Yeh, disable the second cop. With parens I don't think we want to consistently enforce them and the errors when they are ambigious are relatively obvious. We can always tweak these things later, thanks! |
|
6cb0a88
to
9848319
Compare
9848319
to
960c9e6
Compare
This last push marks the completion of the analysis from the formulas, moves |
For a little bit of statistics, this totals 17262 violations, of which 13644 are double quotes and 2858 are line length, the remainder being a long tail of small, inconsequential violations mostly counted in the single (or barely double) digits, that will be easily fixed one formula at a time. |
Thanks for the work here @lloeki! Will try and get this hooked up when I get the chance. |
Neat. This is awesome. I presume we can just |
Yep. I'm going to tweak it a bit further though. |
Yes |
As someone who once flippantly asked "why am I being told that I need to use double quotes for everything instead of your project having a rubocop file?" I am happy to see Homebrew finally get a rubocop file 👍. |
A Rubocop file that'll fail submissions of new formulae that don't meet the style guidelines, too. Glad to hear you appreciate it, thanks @jasonmp85 and @lloeki for getting us there! |
This PR initially contains an empty .rubocop.yml and a freshly-generated .rubocop-todo.yml at the root.
In this PR we can discuss about each cop (disabling, enabling as is or setting parameters and variants) possibly even straight in the todo file code. I'm not going to be picky, if a cop does not make sense, it gets disabled: no need to be too stringent as it would encourage bad code.
For each decision that is taken, the selected cop configuration is written to
.rubocop.yml
and removed from the todo file, updating the PR branch.Once the todo file is empty, it gets removed and we have our target style documented in
rubocop.yml
. At this point the goal is not to have zero violations but to have a file that will support us into making code more conformant and uniform in later PRs either automatically with autocorrect or on a case by case basis, according to homebrew's management team policies and preferences.From then on anyway, the mere presence of the file will entice people having rubocop installed and creating new files or edit existing files fix those files one by one as time goes by.