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

Check that variables are lowercase #418

Merged
merged 3 commits into from
Jun 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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