Skip to content

Commit

Permalink
Add fix
Browse files Browse the repository at this point in the history
  • Loading branch information
raphink committed Feb 10, 2015
1 parent dc64cc6 commit 96e2817
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
source 'https://rubygems.org'

gemspec
gem 'pry'
12 changes: 12 additions & 0 deletions lib/puppet-lint/plugins/check_trailing_comma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@ def check
end
end
end

def fix(problem)
comma = PuppetLint::Lexer::Token.new(
:COMMA,
',',
problem[:token].line,
problem[:token].column
)

idx = tokens.index(problem[:token])
tokens.insert(idx, comma)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,79 @@ class { '::apache':
end
end
end

context 'with fix enabled' do
before do
PuppetLint.configuration.fix = true
end

after do
PuppetLint.configuration.fix = false
end

context 'trailing comma present' do
let (:code) {
<<-EOS
class { '::apache':
timeout => '100',
docroot => '/var/www',
}
file { '/etc/fstab':
ensure => 'file',
content => 'foo',
}
EOS
}

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

it 'should not modify the manifest' do
expect(manifest).to eq(code)
end
end

context 'trailing comma absent' do
let (:code) {
<<-EOS
class { '::apache':
timeout => '100',
docroot => '/var/www'
}
file { '/etc/fstab':
ensure => 'file',
content => 'foo'
}
EOS
}

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

it 'should create a warning' do
expect(problems).to contain_fixed(msg).on_line(3).in_column(32)
expect(problems).to contain_fixed(msg).on_line(8).in_column(27)
end

it 'should add trailing commas' do
expect(manifest).to eq(
<<-EOS
class { '::apache':
timeout => '100',
docroot => '/var/www',
}
file { '/etc/fstab':
ensure => 'file',
content => 'foo',
}
EOS
)
end
end
end
end

0 comments on commit 96e2817

Please sign in to comment.