puppet-lint-duplicate_class_parameters-check 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bbac51812f5327f9031fe74febda0f51332cd150
4
+ data.tar.gz: 22b89ff9affe12e6b1ecf7edfd4fc15fbeaaebe8
5
+ SHA512:
6
+ metadata.gz: 76c7e7bcf168666e38b68861d4ecc44c1d4ea41a48d85fe3dd2b366428f6fa8a830edb15b700a03fc7baf916cb33df95a0f7fbbf151bb4e9bd5705691d031256
7
+ data.tar.gz: 60b2655f22bb6f1fbf9a395116095f29847b78b1a77475b46d718160af2063ef48027ee6b38b63c71de16c9790c757e833ca25df6aec32ebe8a733047dd62570
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dean Wilson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # puppet-lint duplicate_class_parameters check #
2
+
3
+ A puppet-lint extension that ensures class parameter names are unique.
4
+
5
+ [![Build Status](https://travis-ci.org/deanwilson/puppet-lint_duplicate_class_parameters-check.svg?branch=master)](https://travis-ci.org/deanwilson/puppet-lint_duplicate_class_parameters-check)
6
+
7
+ Until Puppet 3.8.5 it was possible to have the same parameter name specified
8
+ multiple times in a class definition without error. This could cause
9
+ confusion as only the last value for that name was taken and it was decided in
10
+ [No error on duplicate parameters on classes and resources](https://tickets.puppetlabs.com/browse/PUP-5590)
11
+ that this behaviour should change and now return an error. This `puppet-lint`
12
+ plugin will help you catch those issues before you upgrade and suffer failures
13
+ in your puppet runs.
14
+
15
+ An exaggerated example of the previously valid, but awkward, behaviour can be found below -
16
+
17
+ class file_resource(
18
+ $duplicated = { 'a' => 1 },
19
+ $duplicated = 'foo',
20
+ $not_unique = 'bar',
21
+ $not_unique = '2nd bar',
22
+ $unique = 'baz'
23
+ ) {
24
+
25
+ file { '/tmp/my-file':
26
+ mode => '0600',
27
+ }
28
+
29
+ }
30
+
31
+ With this extension installed `puppet-lint` will return
32
+
33
+ found duplicate parameter 'duplicated' in class 'file_resource'
34
+
35
+ ## Installation ##
36
+
37
+ To use this plugin add the following line to your Gemfile
38
+
39
+ gem 'puppet-lint-duplicate_class_parameters-check'
40
+
41
+ and then run `bundle install`
42
+
43
+ ### Author ###
44
+ [Dean Wilson](http://www.unixdaemon.net)
@@ -0,0 +1,29 @@
1
+ PuppetLint.new_check(:duplicate_class_parameters) do
2
+ def check
3
+ class_indexes.each do |class_idx|
4
+ seen = Hash.new(0)
5
+
6
+ # if there are no params there is nothing to do, return early.
7
+ return if class_idx[:param_tokens].nil?
8
+
9
+ class_idx[:param_tokens].each do |token|
10
+ class_name = class_idx[:name_token].value
11
+
12
+ if token.type == :VARIABLE
13
+ param_name = token.value
14
+ seen[param_name] += 1
15
+
16
+ if seen[param_name] > 1
17
+ # warning output shows the parameter location each additional time it's seen
18
+ notify :warning, {
19
+ :message => "found duplicate parameter '#{param_name}' in class '#{class_name}'",
20
+ :line => token.line,
21
+ :column => token.column,
22
+ }
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'duplicate_class_parameters' do
4
+
5
+ context 'class with no parameters' do
6
+ let(:code) do
7
+ <<-EOS
8
+ class file_resource {
9
+ file { '/tmp/my-file':
10
+ mode => '0600',
11
+ }
12
+ }
13
+ EOS
14
+ end
15
+
16
+ it 'should not detect any problems' do
17
+ expect(problems).to have(0).problems
18
+ end
19
+ end
20
+
21
+ context 'class without duplicate parameter' do
22
+ let(:code) do
23
+ <<-EOS
24
+ class file_resource(
25
+ $unique = 'bar',
26
+ ) {
27
+
28
+ file { '/tmp/my-file':
29
+ mode => '0600',
30
+ }
31
+
32
+ $baz = 'xxzzy'
33
+ }
34
+ EOS
35
+ end
36
+
37
+ it 'should not detect any problems' do
38
+ expect(problems).to have(0).problems
39
+ end
40
+ end
41
+
42
+ context 'class with duplicate parameters' do
43
+ let(:msg) { 'found duplicate parameter \'duplicated\' in class \'file_resource\'' }
44
+ let(:code) do
45
+ <<-EOS
46
+ class file_resource(
47
+ $duplicated = { 'a' => 1 },
48
+ $duplicated = 'foo',
49
+ $not_unique = 'bar',
50
+ $not_unique = '2nd bar',
51
+ $unique = 'baz'
52
+ ) {
53
+
54
+ file { '/tmp/my-file':
55
+ mode => '0600',
56
+ }
57
+
58
+ $baz = 'xxzzy'
59
+ }
60
+ EOS
61
+ end
62
+
63
+ it 'should detect two problems' do
64
+ expect(problems).to have(2).problems
65
+ end
66
+
67
+ it 'should create a warning' do
68
+ expect(problems).to contain_warning(msg).on_line(3).in_column(11)
69
+ end
70
+
71
+ it 'should create two warnings' do
72
+ expect(problems).to contain_warning(msg).on_line(3).in_column(11)
73
+ expect(problems).to contain_warning(msg.sub('duplicated', 'not_unique')).on_line(5).in_column(11)
74
+ end
75
+
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ require 'puppet-lint'
2
+
3
+ PuppetLint::Plugins.load_spec_helper
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-lint-duplicate_class_parameters-check
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dean Wilson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: puppet-lint
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-its
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-collection_matchers
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.36.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.36.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |2
98
+ A puppet-lint extension that ensures class parameter names
99
+ are unique.
100
+ email: dean.wilson@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - LICENSE
106
+ - README.md
107
+ - lib/puppet-lint/plugins/duplicate_class_parameters.rb
108
+ - spec/puppet-lint/plugins/puppet-lint_duplicate_class_parameters_spec.rb
109
+ - spec/spec_helper.rb
110
+ homepage: https://github.com/deanwilson/puppet-lint_duplicate_class_parameters-check
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.4.8
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: puppet-lint duplicate class parameters check
134
+ test_files:
135
+ - spec/spec_helper.rb
136
+ - spec/puppet-lint/plugins/puppet-lint_duplicate_class_parameters_spec.rb
137
+ has_rdoc: