Skip to content

Commit

Permalink
Improved code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Krizhanovsky committed Mar 20, 2017
1 parent 20ba804 commit 7a668f0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 26 deletions.
4 changes: 2 additions & 2 deletions lib/puppet-lint/checkplugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def run
check

@problems.each do |problem|
if problem[:check] != :syntax && PuppetLint::Data.ignore_overrides[problem[:check]].has_key?(problem[:line])
if problem[:check] != :syntax && PuppetLint::Data.ignore_overrides[problem[:check]].key?(problem[:line])
problem[:kind] = :ignored
problem[:reason] = PuppetLint::Data.ignore_overrides[problem[:check]][problem[:line]]
next
Expand Down Expand Up @@ -166,7 +166,7 @@ def notify(kind, problem)
end

[:message, :line, :column, :check].each do |attr|
unless problem.has_key? attr
unless problem.key? attr
raise ArgumentError, "problem hash must contain #{attr.inspect}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet-lint/checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ def enabled_checks
#
# Returns the manifest as a String.
def manifest
PuppetLint::Data.tokens.map { |t| t.to_manifest }.join('')
PuppetLint::Data.tokens.map(&:to_manifest).join('')
end
end
4 changes: 2 additions & 2 deletions lib/puppet-lint/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: true, NAME: true}.include? token.type
}
else
next_token = tokens[token_idx].next_code_token
Expand Down Expand Up @@ -116,7 +116,7 @@ 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: true, RBRACE: true}.include? tokens[real_idx].type
unless tokens[real_idx].type == :SEMIC && depth > 1
depth -= 1
if depth == 0
Expand Down
14 changes: 3 additions & 11 deletions lib/puppet-lint/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,8 @@ def tokenise(code)
KNOWN_TOKENS.each do |type, regex|
if value = chunk[regex, 1]
length = value.size
if type == :NAME
if KEYWORDS.include? value
tokens << new_token(value.upcase.to_sym, value, length)
else
tokens << new_token(type, value, length)
end
if type == :NAME && KEYWORDS.include?(value)
tokens << new_token(value.upcase.to_sym, value, length)
else
tokens << new_token(type, value, length)
end
Expand Down Expand Up @@ -272,11 +268,7 @@ def possible_regex?

return true if prev_token.nil?

if REGEX_PREV_TOKENS.include? prev_token.type
true
else
false
end
REGEX_PREV_TOKENS.include? prev_token.type
end

# Internal: Create a new PuppetLint::Lexer::Token object, calculate its
Expand Down
12 changes: 2 additions & 10 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,9 @@ def matches?(problems)
@problems = problems

problems.any? do |problem|
ret = true
@expected_problem.each do |key, value|
if !problem.key?(key)
ret = false
break
elsif problem[key] != value
ret = false
break
end
@expected_problem.all? do |key, value|
problem.key?(key) && problem[key] == value
end
ret
end
end

Expand Down

0 comments on commit 7a668f0

Please sign in to comment.