puppet-lint-class_parameter-check 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +1 -1
- data/lib/puppet-lint/plugins/check_class_parameter.rb +10 -10
- data/spec/puppet-lint/plugins/check_class_parameter_spec.rb +26 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94a346b76ae507c5db92f75a789160e4667e8ad1
|
4
|
+
data.tar.gz: f2ba54e52a3884ca98087c347e52c7da5b7a4e26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3a5e3e6635291883e3b58faf49a40ae4520532b0a0e5bb52b24bb9204a105cfb75f3282ca6e347f30e0ce631af9113bfa70a866e0af169cfed740ff94bfd19a
|
7
|
+
data.tar.gz: 2f5e8dd8de2d17b2b7dd9dbfe5f6ab9fe90082292aca1cca83833a86146bd91a1875a549f9ce6646e249db3301a0bbbe3772ddfdad9c63b1ef55a3bb3bac7292
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ A puppet-lint plugin that checks class parameters. Class parameters should be sp
|
|
7
7
|
To use this plugin, add the following like to the Gemfile in your Puppet code base and run `bundle install`.
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'puppet-lint-class_parameter-check'
|
10
|
+
gem 'puppet-lint-class_parameter-check'
|
11
11
|
```
|
12
12
|
## Usage
|
13
13
|
This plugin provides a new check to `puppet-lint`.
|
@@ -6,19 +6,19 @@ PuppetLint.new_check(:class_parameter) do
|
|
6
6
|
params = []
|
7
7
|
optional_params = []
|
8
8
|
|
9
|
-
class_index[:param_tokens].each do |
|
10
|
-
next unless
|
9
|
+
class_index[:param_tokens].each do |param_token|
|
10
|
+
next unless param_token.type == :VARIABLE && param_token.prev_code_token.type != :EQUALS
|
11
11
|
|
12
|
-
if
|
12
|
+
if param_token.next_code_token.nil? || param_token.next_code_token.type != :EQUALS
|
13
13
|
notify :error, {
|
14
|
-
:message => "Required
|
15
|
-
:line =>
|
16
|
-
:column =>
|
14
|
+
:message => "Required parameter #{param_token.value} should be specified before optional parameters",
|
15
|
+
:line => param_token.line,
|
16
|
+
:column => param_token.column
|
17
17
|
} if optional_params.any?
|
18
18
|
|
19
|
-
params.push(
|
20
|
-
elsif
|
21
|
-
optional_params.push(
|
19
|
+
params.push(param_token)
|
20
|
+
elsif param_token.next_code_token && param_token.next_code_token.type == :EQUALS
|
21
|
+
optional_params.push(param_token)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -32,7 +32,7 @@ PuppetLint.new_check(:class_parameter) do
|
|
32
32
|
|
33
33
|
if parameter_names != parameter_names.sort
|
34
34
|
notify :error, {
|
35
|
-
:message => "
|
35
|
+
:message => "Parameter list not in alphabetical order",
|
36
36
|
:line => params.first.line,
|
37
37
|
:column => params.first.column
|
38
38
|
}
|
@@ -28,6 +28,32 @@ describe 'class_parameter' do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
context 'class with only optional parameters' do
|
32
|
+
let(:code) { <<-EOF
|
33
|
+
class puppet_module(
|
34
|
+
String $alphabetical = default
|
35
|
+
) { }
|
36
|
+
EOF
|
37
|
+
}
|
38
|
+
|
39
|
+
it 'has no problems' do
|
40
|
+
expect(problems).to have(0).problems
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'optional parameter from inherited class' do
|
44
|
+
let(:code) { <<-EOF
|
45
|
+
class puppet_module(
|
46
|
+
String $alphabetical = $puppet_module::params::alphabetical
|
47
|
+
) inherits puppet_module::params { }
|
48
|
+
EOF
|
49
|
+
}
|
50
|
+
|
51
|
+
it 'has no problems' do
|
52
|
+
expect(problems).to have(0).problems
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
31
57
|
context 'not sorted alphabetically' do
|
32
58
|
let(:code) { <<-EOF
|
33
59
|
class puppet_module(
|