-
Notifications
You must be signed in to change notification settings - Fork 206
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
Code style improvements #661
Conversation
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.
It's going to be hard to break the muscle memory of using 1.8 style hashes, but I can't really argue with the change :)
A couple of changes I'd like to see in regards to the proposed changes from Hash#include? to Array#include? though
lib/puppet-lint/data.rb
Outdated
@@ -81,7 +81,7 @@ def title_tokens | |||
} | |||
title_array_tokens = tokens[(array_start_idx + 1)..(token_idx - 2)] | |||
result += title_array_tokens.select { |token| | |||
{:STRING => true, :NAME => true}.include? token.type | |||
[:STRING, :NAME].include? token.type |
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 reason I went with hashes here is because Array#include? is O(n) and Hash#include? is O(1). If we're going to clean this up, I'd like to see this become a Set instead of an Array so that we don't slow things down.
lib/puppet-lint/data.rb
Outdated
@@ -116,16 +116,16 @@ def resource_indexes | |||
real_idx = token_idx + idx + 1 | |||
if tokens[real_idx].type == :LBRACE | |||
depth += 1 | |||
elsif {:SEMIC => true, :RBRACE => true}.include? tokens[real_idx].type | |||
elsif [:SEMIC, :RBRACE].include? tokens[real_idx].type |
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 reason I went with hashes here is because Array#include? is O(n) and Hash#include? is O(1). If we're going to clean this up, I'd like to see this become a Set instead of an Array so that we don't slow things down.
859bea1
to
7a668f0
Compare
Thanks for noting the performance consideration. |
I'm going to rebase this and remove the hash syntax updates, as currently we need to maintain Ruby 1.8.7 support in 2.x as it hasn't officially been deprecated. We'll come back to the hash syntax changes later and drop ruby 1.8.7 support during the major version bump to 3.x. |
7a668f0
to
c6fc417
Compare
This mostly converts hashes to 1.9 style (following #647) and also makes some minor code style corrections (in a separate commit)