puppet-lint-class_parameter-check 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/model/parameter.rb +13 -6
- data/lib/puppet-lint/plugins/check_class_parameter.rb +4 -0
- data/spec/puppet-lint/plugins/check_class_parameter_spec.rb +14 -0
- metadata +32 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a1424d519f31f7e5324cd29be719b7631113624
|
4
|
+
data.tar.gz: 4856bd7161747732ce8d7287927c44ec758f6bf3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7849f33bca1d49b2a1ad21531cb86d4bab80438109376c97c3eaa890963e3904bdbdcd6f05c3a6b93e9f75435ef795c179acecd5197babf29ad8cb8447b14426
|
7
|
+
data.tar.gz: 4dd399a06ff5a3165536b5126745a9a509919db405273ce64cbef575e6eeca5b88e2a4287982783ca449268c224aef86041dcefbb0fef72ffa715d51d0867ea1
|
data/README.md
CHANGED
@@ -3,6 +3,8 @@ A puppet-lint plugin that checks class parameters. Class parameters should be sp
|
|
3
3
|
|
4
4
|
[ ![Codeship Status for ryreitsma/puppet-lint-class_parameter-check](https://codeship.com/projects/61472600-279e-0131-879c-36bc4bd39c71/status?branch=master)](https://codeship.com/projects/9002)
|
5
5
|
|
6
|
+
[![forthebadge](http://forthebadge.com/images/badges/made-with-ruby.svg)](http://forthebadge.com)
|
7
|
+
|
6
8
|
## Installation
|
7
9
|
To use this plugin, add the following like to the Gemfile in your Puppet code base and run `bundle install`.
|
8
10
|
|
data/lib/model/parameter.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class Parameter
|
2
|
+
class SyntaxError < StandardError; end
|
2
3
|
attr_accessor :documentation
|
3
4
|
|
4
5
|
def initialize
|
@@ -20,15 +21,16 @@ class Parameter
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def add(token)
|
23
|
-
# A parameter never starts with a newline token
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
# A parameter never starts with a newline token, so skip that one
|
25
|
+
return if @tokens.empty? && token.type == :NEWLINE
|
26
|
+
# Raise a syntax error if the parameter starts with a comma.
|
27
|
+
raise SyntaxError, "Syntax error: Expected a parameter definition, found comma on line #{token.line}, column #{token.column}" if @tokens.empty? && token.type == :COMMA
|
28
|
+
|
29
|
+
@tokens << token
|
27
30
|
end
|
28
31
|
|
29
32
|
def tokens
|
30
|
-
|
31
|
-
return strip_ending_newlines(sanitized_tokens)
|
33
|
+
strip_newlines(@tokens)
|
32
34
|
end
|
33
35
|
|
34
36
|
def line
|
@@ -50,6 +52,11 @@ class Parameter
|
|
50
52
|
end
|
51
53
|
|
52
54
|
private
|
55
|
+
def strip_newlines(tokens)
|
56
|
+
stripped_tokens = strip_starting_newlines(tokens)
|
57
|
+
strip_ending_newlines(stripped_tokens)
|
58
|
+
end
|
59
|
+
|
53
60
|
def strip_starting_newlines(tokens)
|
54
61
|
tokens.inject([]) do |memo, token|
|
55
62
|
unless memo.empty? && token.type == :NEWLINE
|
@@ -13,9 +13,13 @@ PuppetLint.new_check(:class_parameter) do
|
|
13
13
|
puppet_class.parameter_list.errors.each { |error| notify :error, error }
|
14
14
|
end
|
15
15
|
end
|
16
|
+
rescue Parameter::SyntaxError => error
|
17
|
+
notify :error, { message: error, line: nil, column: nil }
|
16
18
|
end
|
17
19
|
|
18
20
|
def fix(problem)
|
21
|
+
# Puppet linter wants to fix each problem. This method fixes all problems
|
22
|
+
# at once. Checking the @fixed makes sure code is executed only once.
|
19
23
|
return if @fixed
|
20
24
|
|
21
25
|
resorted_tokens = []
|
@@ -167,6 +167,20 @@ describe 'class_parameter' do
|
|
167
167
|
expect(problems).to have(3).problems
|
168
168
|
end
|
169
169
|
end
|
170
|
+
|
171
|
+
context 'with a double comma syntax error' do
|
172
|
+
let(:code) { <<-EOF
|
173
|
+
class puppet_module(
|
174
|
+
String $alphabetical,
|
175
|
+
String $alphabetical_optional = "default",,
|
176
|
+
) { }
|
177
|
+
EOF
|
178
|
+
}
|
179
|
+
|
180
|
+
it 'has a problem' do
|
181
|
+
expect(problems).to have(1).problems
|
182
|
+
end
|
183
|
+
end
|
170
184
|
end
|
171
185
|
end
|
172
186
|
|
metadata
CHANGED
@@ -1,83 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-lint-class_parameter-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roelof Reitsma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet-lint
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec-its
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - ~>
|
59
|
+
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
61
|
version: '1.0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - ~>
|
66
|
+
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '1.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rspec-collection_matchers
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- - ~>
|
73
|
+
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
75
|
version: '1.0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- - ~>
|
80
|
+
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '1.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- -
|
87
|
+
- - ">="
|
74
88
|
- !ruby/object:Gem::Version
|
75
89
|
version: '0'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- -
|
94
|
+
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
description: |2
|
@@ -89,8 +103,8 @@ executables: []
|
|
89
103
|
extensions: []
|
90
104
|
extra_rdoc_files: []
|
91
105
|
files:
|
92
|
-
- README.md
|
93
106
|
- LICENSE
|
107
|
+
- README.md
|
94
108
|
- lib/model/documentation_list.rb
|
95
109
|
- lib/model/parameter.rb
|
96
110
|
- lib/model/parameter_documentation.rb
|
@@ -109,17 +123,17 @@ require_paths:
|
|
109
123
|
- lib
|
110
124
|
required_ruby_version: !ruby/object:Gem::Requirement
|
111
125
|
requirements:
|
112
|
-
- -
|
126
|
+
- - ">="
|
113
127
|
- !ruby/object:Gem::Version
|
114
128
|
version: '0'
|
115
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
130
|
requirements:
|
117
|
-
- -
|
131
|
+
- - ">="
|
118
132
|
- !ruby/object:Gem::Version
|
119
133
|
version: '0'
|
120
134
|
requirements: []
|
121
135
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.5.1
|
123
137
|
signing_key:
|
124
138
|
specification_version: 4
|
125
139
|
summary: Puppet lint check for class parameters
|