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.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +74 -0
  3. data/.rubocop_todo.yml +89 -0
  4. data/.travis.yml +11 -9
  5. data/CHANGELOG.md +54 -0
  6. data/Gemfile +3 -0
  7. data/Rakefile +14 -3
  8. data/appveyor.yml +1 -4
  9. data/bin/puppet-lint +1 -1
  10. data/lib/puppet-lint.rb +25 -21
  11. data/lib/puppet-lint/bin.rb +15 -19
  12. data/lib/puppet-lint/checkplugin.rb +24 -17
  13. data/lib/puppet-lint/checks.rb +42 -31
  14. data/lib/puppet-lint/configuration.rb +11 -8
  15. data/lib/puppet-lint/data.rb +236 -164
  16. data/lib/puppet-lint/lexer.rb +225 -203
  17. data/lib/puppet-lint/lexer/token.rb +34 -18
  18. data/lib/puppet-lint/optparser.rb +33 -30
  19. data/lib/puppet-lint/plugins.rb +42 -38
  20. data/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +26 -28
  21. data/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +21 -20
  22. data/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +8 -9
  23. data/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb +9 -8
  24. data/lib/puppet-lint/plugins/check_classes/inherits_across_namespaces.rb +12 -11
  25. data/lib/puppet-lint/plugins/check_classes/names_containing_dash.rb +13 -12
  26. data/lib/puppet-lint/plugins/check_classes/names_containing_uppercase.rb +14 -13
  27. data/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +9 -10
  28. data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +40 -31
  29. data/lib/puppet-lint/plugins/check_classes/right_to_left_relationship.rb +3 -2
  30. data/lib/puppet-lint/plugins/check_classes/variable_scope.rb +21 -24
  31. data/lib/puppet-lint/plugins/check_comments/slash_comments.rb +3 -2
  32. data/lib/puppet-lint/plugins/check_comments/star_comments.rb +6 -5
  33. data/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb +21 -20
  34. data/lib/puppet-lint/plugins/check_conditionals/selector_inside_resource.rb +10 -13
  35. data/lib/puppet-lint/plugins/check_documentation/documentation.rb +26 -17
  36. data/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb +11 -11
  37. data/lib/puppet-lint/plugins/check_resources/duplicate_params.rb +4 -3
  38. data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +17 -18
  39. data/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +17 -16
  40. data/lib/puppet-lint/plugins/check_resources/file_mode.rb +22 -23
  41. data/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +14 -13
  42. data/lib/puppet-lint/plugins/check_resources/unquoted_resource_title.rb +9 -8
  43. data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +8 -8
  44. data/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +29 -42
  45. data/lib/puppet-lint/plugins/check_strings/puppet_url_without_modules.rb +5 -4
  46. data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +3 -2
  47. data/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +4 -3
  48. data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +3 -2
  49. data/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +9 -8
  50. data/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb +9 -8
  51. data/lib/puppet-lint/plugins/check_whitespace/140chars.rb +9 -9
  52. data/lib/puppet-lint/plugins/check_whitespace/2sp_soft_tabs.rb +4 -3
  53. data/lib/puppet-lint/plugins/check_whitespace/80chars.rb +10 -10
  54. data/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +23 -22
  55. data/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +3 -2
  56. data/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb +3 -2
  57. data/lib/puppet-lint/tasks/puppet-lint.rb +3 -3
  58. data/lib/puppet-lint/version.rb +1 -1
  59. data/puppet-lint.gemspec +4 -4
  60. data/spec/puppet-lint/bin_spec.rb +268 -140
  61. data/spec/puppet-lint/checks_spec.rb +229 -0
  62. data/spec/puppet-lint/configuration_spec.rb +10 -9
  63. data/spec/puppet-lint/data_spec.rb +84 -0
  64. data/spec/puppet-lint/ignore_overrides_spec.rb +71 -40
  65. data/spec/puppet-lint/lexer/token_spec.rb +1 -1
  66. data/spec/puppet-lint/lexer_spec.rb +306 -73
  67. data/spec/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb +12 -6
  68. data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +10 -10
  69. data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +15 -11
  70. data/spec/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb +26 -21
  71. data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +3 -3
  72. data/spec/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb +4 -5
  73. data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +13 -0
  74. data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +33 -25
  75. data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +80 -55
  76. data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +2 -2
  77. data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +165 -130
  78. data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +2 -2
  79. data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +53 -35
  80. data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +59 -49
  81. data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +18 -14
  82. data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +14 -10
  83. data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +7 -7
  84. data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +54 -44
  85. data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +114 -89
  86. data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +41 -30
  87. data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +46 -40
  88. data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +46 -40
  89. data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +95 -71
  90. data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +28 -24
  91. data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +11 -9
  92. data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +1 -2
  93. data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +18 -14
  94. data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +1 -1
  95. data/spec/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb +1 -1
  96. data/spec/puppet-lint/plugins/check_whitespace/140chars_spec.rb +22 -15
  97. data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +8 -6
  98. data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +23 -29
  99. data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +588 -494
  100. data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +1 -1
  101. data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +27 -19
  102. data/spec/puppet-lint_spec.rb +2 -12
  103. data/spec/spec_helper.rb +35 -30
  104. metadata +6 -5
  105. data/lib/puppet-lint/monkeypatches.rb +0 -2
  106. data/lib/puppet-lint/monkeypatches/string_percent.rb +0 -52
  107. data/lib/puppet-lint/monkeypatches/string_prepend.rb +0 -13
@@ -38,7 +38,7 @@ describe 'hard_tabs' do
38
38
  end
39
39
 
40
40
  it 'should convert the tab characters into spaces' do
41
- expect(manifest).to eq(" foo => bar,")
41
+ expect(manifest).to eq(' foo => bar,')
42
42
  end
43
43
  end
44
44
  end
@@ -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) { "foo " }
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
- class {
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(3).in_column(1)
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) { "foo " }
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
- class foo {
80
-
81
- }
82
- " }
83
- let(:fixed) { "
84
- class foo {
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(3).in_column(1)
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
@@ -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 = "class foo { }"
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(/\Acontain_/, '').to_sym,
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
- ret = true
44
- @expected_problem.each do |key, value|
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
- unless @expected_problem[attr] == @problems.first[attr]
63
- expected = @expected_problem[attr].inspect
64
- actual = @problems.first[attr].inspect
65
- "#{prefix} #{expected}, but it was #{actual}"
66
- end
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
- "expected that the check would create a problem but it did not"
71
+ 'expected that the check would create a problem but it did not'
73
72
  when 1
74
- messages = ["expected that the problem"]
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
- "expected that the check would create",
84
+ 'expected that the check would create',
86
85
  PP.pp(@expected_problem, '').strip,
87
- "but it instead created",
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
- "expected that the check would not create the problem, but it did"
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 =~ /\Acontain_/
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 = self.respond_to?(:path) ? path : ''
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
- if PuppetLint.configuration.fix
119
- klass.problems = check.fix_problems
120
- end
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 RSpec::LintExampleGroup, {
131
+ config.include(
132
+ RSpec::LintExampleGroup,
129
133
  :type => :lint,
130
- :file_path => Regexp.compile(%w{spec puppet-lint plugins}.join('[\\\/]')),
131
- }
132
- config.expect_with :rspec do |c|
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.0
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-07-12 00:00:00.000000000 Z
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,2 +0,0 @@
1
- require 'puppet-lint/monkeypatches/string_prepend'
2
- require 'puppet-lint/monkeypatches/string_percent'
@@ -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