puppet-lint 2.3.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +74 -0
- data/.rubocop_todo.yml +89 -0
- data/.travis.yml +11 -9
- data/CHANGELOG.md +54 -0
- data/Gemfile +3 -0
- data/Rakefile +14 -3
- data/appveyor.yml +1 -4
- data/bin/puppet-lint +1 -1
- data/lib/puppet-lint.rb +25 -21
- data/lib/puppet-lint/bin.rb +15 -19
- data/lib/puppet-lint/checkplugin.rb +24 -17
- data/lib/puppet-lint/checks.rb +42 -31
- data/lib/puppet-lint/configuration.rb +11 -8
- data/lib/puppet-lint/data.rb +236 -164
- data/lib/puppet-lint/lexer.rb +225 -203
- data/lib/puppet-lint/lexer/token.rb +34 -18
- data/lib/puppet-lint/optparser.rb +33 -30
- data/lib/puppet-lint/plugins.rb +42 -38
- data/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +26 -28
- data/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +21 -20
- data/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +8 -9
- data/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb +9 -8
- data/lib/puppet-lint/plugins/check_classes/inherits_across_namespaces.rb +12 -11
- data/lib/puppet-lint/plugins/check_classes/names_containing_dash.rb +13 -12
- data/lib/puppet-lint/plugins/check_classes/names_containing_uppercase.rb +14 -13
- data/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +9 -10
- data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +40 -31
- data/lib/puppet-lint/plugins/check_classes/right_to_left_relationship.rb +3 -2
- data/lib/puppet-lint/plugins/check_classes/variable_scope.rb +21 -24
- data/lib/puppet-lint/plugins/check_comments/slash_comments.rb +3 -2
- data/lib/puppet-lint/plugins/check_comments/star_comments.rb +6 -5
- data/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb +21 -20
- data/lib/puppet-lint/plugins/check_conditionals/selector_inside_resource.rb +10 -13
- data/lib/puppet-lint/plugins/check_documentation/documentation.rb +26 -17
- data/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb +11 -11
- data/lib/puppet-lint/plugins/check_resources/duplicate_params.rb +4 -3
- data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +17 -18
- data/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +17 -16
- data/lib/puppet-lint/plugins/check_resources/file_mode.rb +22 -23
- data/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +14 -13
- data/lib/puppet-lint/plugins/check_resources/unquoted_resource_title.rb +9 -8
- data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +8 -8
- data/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +29 -42
- data/lib/puppet-lint/plugins/check_strings/puppet_url_without_modules.rb +5 -4
- data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +3 -2
- data/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +4 -3
- data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +3 -2
- data/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +9 -8
- data/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb +9 -8
- data/lib/puppet-lint/plugins/check_whitespace/140chars.rb +9 -9
- data/lib/puppet-lint/plugins/check_whitespace/2sp_soft_tabs.rb +4 -3
- data/lib/puppet-lint/plugins/check_whitespace/80chars.rb +10 -10
- data/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +23 -22
- data/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +3 -2
- data/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb +3 -2
- data/lib/puppet-lint/tasks/puppet-lint.rb +3 -3
- data/lib/puppet-lint/version.rb +1 -1
- data/puppet-lint.gemspec +4 -4
- data/spec/puppet-lint/bin_spec.rb +268 -140
- data/spec/puppet-lint/checks_spec.rb +229 -0
- data/spec/puppet-lint/configuration_spec.rb +10 -9
- data/spec/puppet-lint/data_spec.rb +84 -0
- data/spec/puppet-lint/ignore_overrides_spec.rb +71 -40
- data/spec/puppet-lint/lexer/token_spec.rb +1 -1
- data/spec/puppet-lint/lexer_spec.rb +306 -73
- data/spec/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb +12 -6
- data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +10 -10
- data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +15 -11
- data/spec/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb +26 -21
- data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +3 -3
- data/spec/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb +4 -5
- data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +13 -0
- data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +33 -25
- data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +80 -55
- data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +2 -2
- data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +165 -130
- data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +2 -2
- data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +53 -35
- data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +59 -49
- data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +18 -14
- data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +14 -10
- data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +7 -7
- data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +54 -44
- data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +114 -89
- data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +41 -30
- data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +46 -40
- data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +46 -40
- data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +95 -71
- data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +28 -24
- data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +11 -9
- data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +1 -2
- data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +18 -14
- data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +1 -1
- data/spec/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb +1 -1
- data/spec/puppet-lint/plugins/check_whitespace/140chars_spec.rb +22 -15
- data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +8 -6
- data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +23 -29
- data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +588 -494
- data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +1 -1
- data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +27 -19
- data/spec/puppet-lint_spec.rb +2 -12
- data/spec/spec_helper.rb +35 -30
- metadata +6 -5
- data/lib/puppet-lint/monkeypatches.rb +0 -2
- data/lib/puppet-lint/monkeypatches/string_percent.rb +0 -52
- data/lib/puppet-lint/monkeypatches/string_prepend.rb +0 -13
@@ -5,7 +5,7 @@ describe 'trailing_whitespace' do
|
|
5
5
|
|
6
6
|
context 'with fix disabled' do
|
7
7
|
context 'line with trailing whitespace' do
|
8
|
-
let(:code) {
|
8
|
+
let(:code) { 'foo ' }
|
9
9
|
|
10
10
|
it 'should only detect a single problem' do
|
11
11
|
expect(problems).to have(1).problem
|
@@ -17,18 +17,20 @@ describe 'trailing_whitespace' do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'line without code and trailing whitespace' do
|
20
|
-
let(:code)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
let(:code) do
|
21
|
+
[
|
22
|
+
'class {',
|
23
|
+
' ',
|
24
|
+
'}',
|
25
|
+
].join("\n")
|
26
|
+
end
|
25
27
|
|
26
28
|
it 'should only detect a single problem' do
|
27
29
|
expect(problems).to have(1).problem
|
28
30
|
end
|
29
31
|
|
30
32
|
it 'should create an error' do
|
31
|
-
expect(problems).to contain_error(msg).on_line(
|
33
|
+
expect(problems).to contain_error(msg).on_line(2).in_column(1)
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -43,7 +45,7 @@ class {
|
|
43
45
|
end
|
44
46
|
|
45
47
|
context 'single line with trailing whitespace' do
|
46
|
-
let(:code) {
|
48
|
+
let(:code) { 'foo ' }
|
47
49
|
|
48
50
|
it 'should only detect a single problem' do
|
49
51
|
expect(problems).to have(1).problem
|
@@ -75,22 +77,28 @@ class {
|
|
75
77
|
end
|
76
78
|
|
77
79
|
context 'line without code and trailing whitespace' do
|
78
|
-
let(:code)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
80
|
+
let(:code) do
|
81
|
+
[
|
82
|
+
'class foo {',
|
83
|
+
' ',
|
84
|
+
'}',
|
85
|
+
].join("\n")
|
86
|
+
end
|
87
|
+
|
88
|
+
let(:fixed) do
|
89
|
+
[
|
90
|
+
'class foo {',
|
91
|
+
'',
|
92
|
+
'}',
|
93
|
+
].join("\n")
|
94
|
+
end
|
95
|
+
|
88
96
|
it 'should only detect a single problem' do
|
89
97
|
expect(problems).to have(1).problem
|
90
98
|
end
|
91
99
|
|
92
100
|
it 'should create an error' do
|
93
|
-
expect(problems).to contain_fixed(msg).on_line(
|
101
|
+
expect(problems).to contain_fixed(msg).on_line(2).in_column(1)
|
94
102
|
end
|
95
103
|
|
96
104
|
it 'should remove the trailing whitespace' do
|
data/spec/puppet-lint_spec.rb
CHANGED
@@ -4,23 +4,13 @@ describe PuppetLint do
|
|
4
4
|
subject { PuppetLint.new }
|
5
5
|
|
6
6
|
it 'should accept manifests as a string' do
|
7
|
-
subject.code =
|
7
|
+
subject.code = 'class foo { }'
|
8
8
|
expect(subject.code).to_not be_nil
|
9
9
|
end
|
10
10
|
|
11
|
-
it 'should have support for % with a hash' do
|
12
|
-
string = 'replace %{hash}' % {:hash => 'replaced'}
|
13
|
-
expect(string).to match('replace replaced')
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should not break regular % support' do
|
17
|
-
string = 'replace %s %s' % ['get','replaced']
|
18
|
-
expect(string).to match('replace get replaced')
|
19
|
-
end
|
20
|
-
|
21
11
|
it 'should return empty manifest when empty one given as the input' do
|
22
12
|
subject.code = ''
|
23
13
|
subject.run
|
24
|
-
expect(subject.manifest).to eq
|
14
|
+
expect(subject.manifest).to eq('')
|
25
15
|
end
|
26
16
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter('/spec/')
|
4
|
+
add_filter('/vendor/')
|
5
|
+
add_group('Checks', 'lib/puppet-lint/plugins')
|
6
|
+
end
|
7
|
+
|
1
8
|
require 'puppet-lint'
|
2
9
|
require 'rspec/its'
|
3
10
|
require 'rspec/collection_matchers'
|
@@ -12,7 +19,7 @@ module RSpec
|
|
12
19
|
class HaveProblem
|
13
20
|
def initialize(method, message)
|
14
21
|
@expected_problem = {
|
15
|
-
:kind => method.to_s.gsub(
|
22
|
+
:kind => method.to_s.gsub(%r{\Acontain_}, '').to_sym,
|
16
23
|
:message => message,
|
17
24
|
}
|
18
25
|
@description = ["contain a #{@expected_problem[:kind]}"]
|
@@ -40,17 +47,9 @@ module RSpec
|
|
40
47
|
@problems = problems
|
41
48
|
|
42
49
|
problems.any? do |problem|
|
43
|
-
|
44
|
-
|
45
|
-
if !problem.key?(key)
|
46
|
-
ret = false
|
47
|
-
break
|
48
|
-
elsif problem[key] != value
|
49
|
-
ret = false
|
50
|
-
break
|
51
|
-
end
|
50
|
+
@expected_problem.all? do |key, value|
|
51
|
+
problem.key?(key) && problem[key] == value
|
52
52
|
end
|
53
|
-
ret
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
@@ -59,19 +58,19 @@ module RSpec
|
|
59
58
|
end
|
60
59
|
|
61
60
|
def check_attr(attr, prefix)
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
return if @expected_problem[attr] == @problems.first[attr]
|
62
|
+
|
63
|
+
expected = @expected_problem[attr].inspect
|
64
|
+
actual = @problems.first[attr].inspect
|
65
|
+
"#{prefix} #{expected}, but it was #{actual}"
|
67
66
|
end
|
68
67
|
|
69
68
|
def failure_message
|
70
69
|
case @problems.length
|
71
70
|
when 0
|
72
|
-
|
71
|
+
'expected that the check would create a problem but it did not'
|
73
72
|
when 1
|
74
|
-
messages = [
|
73
|
+
messages = ['expected that the problem']
|
75
74
|
|
76
75
|
messages << check_attr(:kind, 'would be of kind')
|
77
76
|
messages << check_attr(:message, 'would have the message')
|
@@ -82,24 +81,28 @@ module RSpec
|
|
82
81
|
messages.compact.join("\n ")
|
83
82
|
else
|
84
83
|
[
|
85
|
-
|
84
|
+
'expected that the check would create',
|
86
85
|
PP.pp(@expected_problem, '').strip,
|
87
|
-
|
86
|
+
'but it instead created',
|
88
87
|
PP.pp(@problems, ''),
|
89
88
|
].join("\n")
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
93
92
|
def failure_message_when_negated
|
94
|
-
|
93
|
+
'expected that the check would not create the problem, but it did'
|
95
94
|
end
|
96
95
|
end
|
97
96
|
|
98
97
|
def method_missing(method, *args, &block)
|
99
|
-
return HaveProblem.new(method, args.first) if method.to_s
|
98
|
+
return HaveProblem.new(method, args.first) if method.to_s.start_with?('contain_')
|
100
99
|
super
|
101
100
|
end
|
102
101
|
|
102
|
+
def respond_to_missing?(method, *)
|
103
|
+
method.to_s.start_with?('contain_') || super
|
104
|
+
end
|
105
|
+
|
103
106
|
def problems
|
104
107
|
subject.problems
|
105
108
|
end
|
@@ -110,14 +113,14 @@ module RSpec
|
|
110
113
|
|
111
114
|
def subject
|
112
115
|
klass = PuppetLint::Checks.new
|
113
|
-
filepath =
|
116
|
+
filepath = respond_to?(:path) ? path : ''
|
114
117
|
klass.load_data(filepath, code)
|
115
118
|
check_name = self.class.top_level_description.to_sym
|
116
119
|
check = PuppetLint.configuration.check_object[check_name].new
|
117
120
|
klass.problems = check.run
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
+
|
122
|
+
klass.problems = check.fix_problems if PuppetLint.configuration.fix
|
123
|
+
|
121
124
|
klass
|
122
125
|
end
|
123
126
|
end
|
@@ -125,11 +128,13 @@ end
|
|
125
128
|
|
126
129
|
RSpec.configure do |config|
|
127
130
|
config.mock_framework = :rspec
|
128
|
-
config.include
|
131
|
+
config.include(
|
132
|
+
RSpec::LintExampleGroup,
|
129
133
|
:type => :lint,
|
130
|
-
:file_path => Regexp.compile(%w
|
131
|
-
|
132
|
-
|
134
|
+
:file_path => Regexp.compile(%w[spec puppet-lint plugins].join('[\\\/]')),
|
135
|
+
)
|
136
|
+
|
137
|
+
config.expect_with(:rspec) do |c|
|
133
138
|
c.syntax = :expect
|
134
139
|
end
|
135
140
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Sharpe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Checks your Puppet manifests against the Puppetlabs
|
@@ -21,6 +21,8 @@ extra_rdoc_files: []
|
|
21
21
|
files:
|
22
22
|
- ".gitignore"
|
23
23
|
- ".rspec"
|
24
|
+
- ".rubocop.yml"
|
25
|
+
- ".rubocop_todo.yml"
|
24
26
|
- ".travis.yml"
|
25
27
|
- CHANGELOG.md
|
26
28
|
- Gemfile
|
@@ -37,9 +39,6 @@ files:
|
|
37
39
|
- lib/puppet-lint/data.rb
|
38
40
|
- lib/puppet-lint/lexer.rb
|
39
41
|
- lib/puppet-lint/lexer/token.rb
|
40
|
-
- lib/puppet-lint/monkeypatches.rb
|
41
|
-
- lib/puppet-lint/monkeypatches/string_percent.rb
|
42
|
-
- lib/puppet-lint/monkeypatches/string_prepend.rb
|
43
42
|
- lib/puppet-lint/optparser.rb
|
44
43
|
- lib/puppet-lint/plugins.rb
|
45
44
|
- lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb
|
@@ -94,7 +93,9 @@ files:
|
|
94
93
|
- spec/fixtures/test/manifests/url_interpolation.pp
|
95
94
|
- spec/fixtures/test/manifests/warning.pp
|
96
95
|
- spec/puppet-lint/bin_spec.rb
|
96
|
+
- spec/puppet-lint/checks_spec.rb
|
97
97
|
- spec/puppet-lint/configuration_spec.rb
|
98
|
+
- spec/puppet-lint/data_spec.rb
|
98
99
|
- spec/puppet-lint/ignore_overrides_spec.rb
|
99
100
|
- spec/puppet-lint/lexer/token_spec.rb
|
100
101
|
- spec/puppet-lint/lexer_spec.rb
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# If we are using an older ruby version, we back-port the basic functionality
|
2
|
-
# we need for formatting output: 'somestring' % <hash>
|
3
|
-
begin
|
4
|
-
if ('%{test}' % {:test => 'replaced'} == 'replaced')
|
5
|
-
# If this works, we are all good to go.
|
6
|
-
end
|
7
|
-
rescue
|
8
|
-
# If the test failed (threw a error), monkeypatch String.
|
9
|
-
# Most of this code came from http://www.ruby-forum.com/topic/144310 but was
|
10
|
-
# simplified for our use.
|
11
|
-
|
12
|
-
# Basic implementation of 'string' % { } like we need it. needs work.
|
13
|
-
class String
|
14
|
-
Percent = instance_method '%' unless defined? Percent
|
15
|
-
def % *a, &b
|
16
|
-
a.flatten!
|
17
|
-
|
18
|
-
string = case a.last
|
19
|
-
when Hash
|
20
|
-
expand a.pop
|
21
|
-
else
|
22
|
-
self
|
23
|
-
end
|
24
|
-
|
25
|
-
if a.empty?
|
26
|
-
string
|
27
|
-
else
|
28
|
-
Percent.bind(string).call(a, &b)
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
def expand! vars = {}
|
33
|
-
loop do
|
34
|
-
changed = false
|
35
|
-
vars.each do |var, value|
|
36
|
-
var = var.to_s
|
37
|
-
var.gsub! %r/[^a-zA-Z0-9_]/, ''
|
38
|
-
[
|
39
|
-
%r/\%\{#{ var }\}/,
|
40
|
-
].each do |pat|
|
41
|
-
changed = gsub! pat, "#{ value }"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
break unless changed
|
45
|
-
end
|
46
|
-
self
|
47
|
-
end
|
48
|
-
def expand opts = {}
|
49
|
-
dup.expand! opts
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
unless String.respond_to?('prepend')
|
2
|
-
# Internal: Monkey patching String.
|
3
|
-
class String
|
4
|
-
# Internal: Prepends a String to self.
|
5
|
-
#
|
6
|
-
# lead - The String to prepend self with.
|
7
|
-
#
|
8
|
-
# Returns a String which is lead and self concatenated.
|
9
|
-
def prepend(lead)
|
10
|
-
self.replace "#{lead}#{self}"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|