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

Minor cleanup to regexp for correctness. #458

Merged
merged 1 commit into from
Jul 26, 2019

Conversation

zenspider
Copy link
Contributor

I'm just being a tad anal retentive here. I don't want the quotes to
be mis-matched and I don't want the \s to match NLs.

Signed-off-by: Ryan Davis zenspider@chef.io

version = suse.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join('.')
# https://rubular.com/r/b5PN3hZDxa5amV
version = suse[/VERSION\s?=\s?"?([\d\.]{2,})"?/, 1] if version == ''
version = suse[/VERSION *= *("?)([\d\.]{2,})\1$/, 2] if version == ''
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this harder to read ( *= * almost reads as an operator), and you've removed a helpful comment. Please have some mercy on your fellow developers, and keep/update explanatory comments.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think your intention was to imply malice, but 'please have some mercy' reads kinda harshly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First, I agree with @miah here. There’s another PR comment with “be kind and ...” that also reads like you’re implying malicious intent. I don’t think you are, but still... this is a public forum.

Second, The rubular comments seem very inconsistently applied to our projects... tho I can now see that they’re used more in ohai & chef, but it’s still only 18 references across 12 files (out of 3358 files).

Third, I personally don’t think this regexp is that hard to follow as far as our regexps go. I’ll add it back if you want, but I’d rather do a brown-bag (or whatever the remote equivalent would be) on regexps instead. Miah has already said that would help her and I would be happy to do it.

Finally… For fun, I wrote a quick script to find and “score” all our regexps and … well… let’s just say that there are going to be some more issues filed shortly as it is exposing some problems.

@zenspider zenspider force-pushed the zenspider/minor/regexp-cleanup branch from fa92142 to b4cc4cc Compare May 28, 2019 20:58
@codeclimate
Copy link

codeclimate bot commented May 28, 2019

Code Climate has analyzed commit b4cc4cc and detected 0 issues on this pull request.

View more on Code Climate.

I'm just being a tad anal retentive here. I don't want the quotes to
be mis-matched and I don't want the \s to match NLs.

Signed-off-by: Ryan Davis <zenspider@chef.io>
@zenspider zenspider force-pushed the zenspider/minor/regexp-cleanup branch from b4cc4cc to 0dec81d Compare July 26, 2019 20:57
@zenspider zenspider merged commit 5ccb665 into master Jul 26, 2019
@chef-ci chef-ci deleted the zenspider/minor/regexp-cleanup branch July 26, 2019 21:06
@@ -239,8 +239,8 @@ def self.load
unless (suse = unix_file_contents("/etc/SuSE-release")).nil?
# https://rubular.com/r/UKaYWolCYFMfp1
version = suse.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".")
# https://rubular.com/r/b5PN3hZDxa5amV
version = suse[/VERSION\s?=\s?"?([\d\.]{2,})"?/, 1] if version == ""
# https://rubular.com/r/xegcPXKEXJrJl5
Copy link
Contributor

Choose a reason for hiding this comment

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

😄

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

4 participants