Skip to content

Commit

Permalink
Merge pull request #418 from rothsa/camelcase
Browse files Browse the repository at this point in the history
Check that variables are lowercase
  • Loading branch information
rnelson0 authored Jun 24, 2016
2 parents 9d561e4 + fda0829 commit 2a2fa3d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/puppet-lint/plugins/check_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ def check
end
end
end

PuppetLint.new_check(:variable_is_lowercase) do
VARIABLE_TYPES = Set[:VARIABLE, :UNENC_VARIABLE]

def check
tokens.select { |r|
VARIABLE_TYPES.include? r.type
}.each do |token|
if token.value.gsub(/\[.+?\]/, '').match(/[A-Z]/)
notify :warning, {
:message => 'variable contains an uppercase letter',
:line => token.line,
:column => token.column,
}
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'spec_helper'

describe 'variable_is_lowercase' do
let(:msg) { 'variable contains an uppercase letter' }

context 'a variable containing an uppercase letter' do
let(:code) { '$fooBar' }

it 'should only detect a single problem' do
expect(problems).to have(1).problem
end

it 'should create a warning' do
expect(problems).to contain_warning(msg).on_line(1).in_column(1)
end
end

context 'a variable containing only lowercase letters' do
let(:code) { '$foobar' }

it 'should not detect any problems' do
expect(problems).to have(0).problems
end
end
end

0 comments on commit 2a2fa3d

Please sign in to comment.