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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3663acc66b36254c1017c9145596504e78c39b5f
4
- data.tar.gz: 2c3b8da8980a632060b6b7c73627d5593a80aeda
3
+ metadata.gz: 94a346b76ae507c5db92f75a789160e4667e8ad1
4
+ data.tar.gz: f2ba54e52a3884ca98087c347e52c7da5b7a4e26
5
5
  SHA512:
6
- metadata.gz: f22bc8bc8e4007aa5d4dd409803e4de9d5c829c32396e3d5eba9aebc699a09e14f0706bda227e33063a5fe366761f2ee50b9191a9ac90fddcf1fb8a8482eee7e
7
- data.tar.gz: dbecaf74eabb6ca5856916b1e48dce652b83c29aba3147eead6958c64f8993fb676531de6186a2b59769b3d8b0ca192afb806650bbf717528ec81833816b0055
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', git: 'git@github.com:ryreitsma/puppet-lint-class_parameter-check.git'
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 |parameter_token|
10
- next unless parameter_token.type == :VARIABLE
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 parameter_token.next_code_token.nil? || parameter_token.next_code_token.type != :EQUALS
12
+ if param_token.next_code_token.nil? || param_token.next_code_token.type != :EQUALS
13
13
  notify :error, {
14
- :message => "Required parameters should be specified before optional parameters",
15
- :line => parameter_token.line,
16
- :column => parameter_token.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(parameter_token)
20
- elsif parameter_token.next_code_token && parameter_token.next_code_token.type == :EQUALS
21
- optional_params.push(parameter_token)
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 => "Parameters not in alphabetical order",
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(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-class_parameter-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roelof Reitsma