puppet-lint 2.2.1 → 2.3.0

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -19
  3. data/README.md +181 -174
  4. data/Rakefile +1 -1
  5. data/lib/puppet-lint/bin.rb +6 -0
  6. data/lib/puppet-lint/lexer.rb +1 -1
  7. data/lib/puppet-lint/plugins.rb +16 -10
  8. data/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +46 -0
  9. data/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +33 -0
  10. data/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +20 -0
  11. data/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb +20 -0
  12. data/lib/puppet-lint/plugins/check_classes/inherits_across_namespaces.rb +22 -0
  13. data/lib/puppet-lint/plugins/check_classes/names_containing_dash.rb +23 -0
  14. data/lib/puppet-lint/plugins/check_classes/names_containing_uppercase.rb +28 -0
  15. data/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +28 -0
  16. data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +44 -0
  17. data/lib/puppet-lint/plugins/check_classes/right_to_left_relationship.rb +15 -0
  18. data/lib/puppet-lint/plugins/check_classes/variable_scope.rb +143 -0
  19. data/lib/puppet-lint/plugins/check_comments/slash_comments.rb +22 -0
  20. data/lib/puppet-lint/plugins/{check_comments.rb → check_comments/star_comments.rb} +1 -24
  21. data/lib/puppet-lint/plugins/{check_conditionals.rb → check_conditionals/case_without_default.rb} +1 -27
  22. data/lib/puppet-lint/plugins/check_conditionals/selector_inside_resource.rb +25 -0
  23. data/lib/puppet-lint/plugins/{check_documentation.rb → check_documentation/documentation.rb} +0 -0
  24. data/lib/puppet-lint/plugins/{check_nodes.rb → check_nodes/unquoted_node_name.rb} +0 -0
  25. data/lib/puppet-lint/plugins/check_resources/duplicate_params.rb +37 -0
  26. data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +70 -0
  27. data/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +44 -0
  28. data/lib/puppet-lint/plugins/check_resources/file_mode.rb +42 -0
  29. data/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +31 -0
  30. data/lib/puppet-lint/plugins/check_resources/unquoted_resource_title.rb +22 -0
  31. data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +27 -0
  32. data/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +63 -0
  33. data/lib/puppet-lint/plugins/check_strings/puppet_url_without_modules.rb +25 -0
  34. data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +26 -0
  35. data/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +17 -0
  36. data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +23 -0
  37. data/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +21 -0
  38. data/lib/puppet-lint/plugins/{check_variables.rb → check_variables/variable_is_lowercase.rb} +0 -22
  39. data/lib/puppet-lint/plugins/check_whitespace/140chars.rb +21 -0
  40. data/lib/puppet-lint/plugins/check_whitespace/2sp_soft_tabs.rb +19 -0
  41. data/lib/puppet-lint/plugins/check_whitespace/80chars.rb +21 -0
  42. data/lib/puppet-lint/plugins/{check_whitespace.rb → check_whitespace/arrow_alignment.rb} +0 -118
  43. data/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +24 -0
  44. data/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb +28 -0
  45. data/lib/puppet-lint/tasks/puppet-lint.rb +4 -0
  46. data/lib/puppet-lint/version.rb +1 -1
  47. data/spec/puppet-lint/bin_spec.rb +18 -1
  48. data/spec/puppet-lint/lexer_spec.rb +19 -0
  49. metadata +41 -68
  50. data/lib/puppet-lint/plugins/check_classes.rb +0 -433
  51. data/lib/puppet-lint/plugins/check_resources.rb +0 -251
  52. data/lib/puppet-lint/plugins/check_strings.rb +0 -186
@@ -0,0 +1,25 @@
1
+ # Public: Check the manifest tokens for any puppet:// URL strings where the
2
+ # path section doesn't start with modules/ and record a warning for each
3
+ # instance found.
4
+ #
5
+ # No style guide reference
6
+ PuppetLint.new_check(:puppet_url_without_modules) do
7
+ def check
8
+ tokens.select { |token|
9
+ (token.type == :SSTRING || token.type == :STRING || token.type == :DQPRE) && token.value.start_with?('puppet://')
10
+ }.reject { |token|
11
+ token.value[/puppet:\/\/.*?\/(.+)/, 1].start_with?('modules/') unless token.value[/puppet:\/\/.*?\/(.+)/, 1].nil?
12
+ }.each do |token|
13
+ notify :warning, {
14
+ :message => 'puppet:// URL without modules/ found',
15
+ :line => token.line,
16
+ :column => token.column,
17
+ :token => token,
18
+ }
19
+ end
20
+ end
21
+
22
+ def fix(problem)
23
+ problem[:token].value.gsub!(/(puppet:\/\/.*?\/)/, '\1modules/')
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ # Public: Check the manifest tokens for any double or single quoted strings
2
+ # containing only a boolean value and record a warning for each instance
3
+ # found.
4
+ #
5
+ # No style guide reference
6
+ PuppetLint.new_check(:quoted_booleans) do
7
+ STRING_TYPES = Set[:STRING, :SSTRING]
8
+ BOOLEANS = Set['true', 'false']
9
+
10
+ def check
11
+ tokens.select { |r|
12
+ STRING_TYPES.include?(r.type) && BOOLEANS.include?(r.value)
13
+ }.each do |token|
14
+ notify :warning, {
15
+ :message => 'quoted boolean value found',
16
+ :line => token.line,
17
+ :column => token.column,
18
+ :token => token,
19
+ }
20
+ end
21
+ end
22
+
23
+ def fix(problem)
24
+ problem[:token].type = problem[:token].value.upcase.to_sym
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ # Public: Check the manifest tokens for any single quoted strings containing
2
+ # a enclosed variable and record an error for each instance found.
3
+ #
4
+ # https://docs.puppet.com/guides/style_guide.html#quoting
5
+ PuppetLint.new_check(:single_quote_string_with_variables) do
6
+ def check
7
+ tokens.select { |r|
8
+ r.type == :SSTRING && r.value.include?('${') && (! r.prev_token.prev_token.value.match(%r{inline_(epp|template)}) )
9
+ }.each do |token|
10
+ notify :error, {
11
+ :message => 'single quoted string containing a variable found',
12
+ :line => token.line,
13
+ :column => token.column,
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ # Public: Check the manifest tokens for any variables in a string that have
2
+ # not been enclosed by braces ({}) and record a warning for each instance
3
+ # found.
4
+ #
5
+ # https://docs.puppet.com/guides/style_guide.html#quoting
6
+ PuppetLint.new_check(:variables_not_enclosed) do
7
+ def check
8
+ tokens.select { |r|
9
+ r.type == :UNENC_VARIABLE
10
+ }.each do |token|
11
+ notify :warning, {
12
+ :message => 'variable not enclosed in {}',
13
+ :line => token.line,
14
+ :column => token.column,
15
+ :token => token,
16
+ }
17
+ end
18
+ end
19
+
20
+ def fix(problem)
21
+ problem[:token].type = :VARIABLE
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ # Public: Test the manifest tokens for variables that contain a dash and
2
+ # record a warning for each instance found.
3
+ #
4
+ # No style guide reference
5
+ PuppetLint.new_check(:variable_contains_dash) do
6
+ VARIABLE_DASH_TYPES = Set[:VARIABLE, :UNENC_VARIABLE]
7
+
8
+ def check
9
+ tokens.select { |r|
10
+ VARIABLE_DASH_TYPES.include? r.type
11
+ }.each do |token|
12
+ if token.value.gsub(/\[.+?\]/, '').match(/-/)
13
+ notify :warning, {
14
+ :message => 'variable contains a dash',
15
+ :line => token.line,
16
+ :column => token.column,
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,25 +1,3 @@
1
- # Public: Test the manifest tokens for variables that contain a dash and
2
- # record a warning for each instance found.
3
- #
4
- # No style guide reference
5
- PuppetLint.new_check(:variable_contains_dash) do
6
- VARIABLE_DASH_TYPES = Set[:VARIABLE, :UNENC_VARIABLE]
7
-
8
- def check
9
- tokens.select { |r|
10
- VARIABLE_DASH_TYPES.include? r.type
11
- }.each do |token|
12
- if token.value.gsub(/\[.+?\]/, '').match(/-/)
13
- notify :warning, {
14
- :message => 'variable contains a dash',
15
- :line => token.line,
16
- :column => token.column,
17
- }
18
- end
19
- end
20
- end
21
- end
22
-
23
1
  # Public: Test the manifest tokens for variables that contain an uppercase
24
2
  # letter and record a warning for each instance found.
25
3
  #
@@ -0,0 +1,21 @@
1
+ # Public: Test the raw manifest string for lines containing more than 140
2
+ # characters and record a warning for each instance found. The only exceptions
3
+ # to this rule are lines containing URLs and template() calls which would hurt
4
+ # readability if split.
5
+ #
6
+ # https://docs.puppet.com/guides/style_guide.html#spacing-indentation-and-whitespace
7
+ PuppetLint.new_check(:'140chars') do
8
+ def check
9
+ manifest_lines.each_with_index do |line, idx|
10
+ unless line =~ /:\/\// || line =~ /template\(/
11
+ if line.scan(/./mu).size > 140
12
+ notify :warning, {
13
+ :message => 'line has more than 140 characters',
14
+ :line => idx + 1,
15
+ :column => 140,
16
+ }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ # Public: Check the manifest tokens for any indentation not using 2 space soft
2
+ # tabs and record an error for each instance found.
3
+ #
4
+ # https://docs.puppet.com/guides/style_guide.html#spacing-indentation-and-whitespace
5
+ PuppetLint.new_check(:'2sp_soft_tabs') do
6
+ def check
7
+ tokens.select { |r|
8
+ r.type == :INDENT
9
+ }.reject { |r|
10
+ r.value.length % 2 == 0
11
+ }.each do |token|
12
+ notify :error, {
13
+ :message => 'two-space soft tabs not used',
14
+ :line => token.line,
15
+ :column => token.column,
16
+ }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ # Public: Test the raw manifest string for lines containing more than 80
2
+ # characters. This is DISABLED by default and behaves like the default
3
+ # 140chars check by excepting URLs and template() calls.
4
+ #
5
+ # https://docs.puppet.com/guides/style_guide.html#spacing-indentation-and-whitespace (older version)
6
+ PuppetLint.new_check(:'80chars') do
7
+ def check
8
+ manifest_lines.each_with_index do |line, idx|
9
+ unless line =~ /:\/\// || line =~ /template\(/
10
+ if line.scan(/./mu).size > 80
11
+ notify :warning, {
12
+ :message => 'line has more than 80 characters',
13
+ :line => idx + 1,
14
+ :column => 80,
15
+ }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ PuppetLint.configuration.send("disable_80chars")
@@ -1,121 +1,3 @@
1
- # Public: Check the raw manifest string for lines containing hard tab
2
- # characters and record an error for each instance found.
3
- #
4
- # https://docs.puppet.com/guides/style_guide.html#spacing-indentation-and-whitespace
5
- PuppetLint.new_check(:hard_tabs) do
6
- WHITESPACE_TYPES = Set[:INDENT, :WHITESPACE]
7
-
8
- def check
9
- tokens.select { |r|
10
- WHITESPACE_TYPES.include?(r.type) && r.value.include?("\t")
11
- }.each do |token|
12
- notify :error, {
13
- :message => 'tab character found',
14
- :line => token.line,
15
- :column => token.column,
16
- :token => token,
17
- }
18
- end
19
- end
20
-
21
- def fix(problem)
22
- problem[:token].value.gsub!("\t", ' ')
23
- end
24
- end
25
-
26
- # Public: Check the manifest tokens for lines ending with whitespace and record
27
- # an error for each instance found.
28
- #
29
- # https://docs.puppet.com/guides/style_guide.html#spacing-indentation-and-whitespace
30
- PuppetLint.new_check(:trailing_whitespace) do
31
- def check
32
- tokens.select { |token|
33
- [:WHITESPACE, :INDENT].include?(token.type)
34
- }.select { |token|
35
- token.next_token.nil? || token.next_token.type == :NEWLINE
36
- }.each do |token|
37
- notify :error, {
38
- :message => 'trailing whitespace found',
39
- :line => token.line,
40
- :column => token.column,
41
- :token => token,
42
- }
43
- end
44
- end
45
-
46
- def fix(problem)
47
- prev_token = problem[:token].prev_token
48
- next_token = problem[:token].next_token
49
- prev_token.next_token = next_token
50
- next_token.prev_token = prev_token unless next_token.nil?
51
- tokens.delete(problem[:token])
52
- end
53
- end
54
-
55
- # Public: Test the raw manifest string for lines containing more than 140
56
- # characters and record a warning for each instance found. The only exceptions
57
- # to this rule are lines containing URLs and template() calls which would hurt
58
- # readability if split.
59
- #
60
- # https://docs.puppet.com/guides/style_guide.html#spacing-indentation-and-whitespace
61
- PuppetLint.new_check(:'140chars') do
62
- def check
63
- manifest_lines.each_with_index do |line, idx|
64
- unless line =~ /:\/\// || line =~ /template\(/
65
- if line.scan(/./mu).size > 140
66
- notify :warning, {
67
- :message => 'line has more than 140 characters',
68
- :line => idx + 1,
69
- :column => 140,
70
- }
71
- end
72
- end
73
- end
74
- end
75
- end
76
-
77
- # Public: Test the raw manifest string for lines containing more than 80
78
- # characters. This is DISABLED by default and behaves like the default
79
- # 140chars check by excepting URLs and template() calls.
80
- #
81
- # https://docs.puppet.com/guides/style_guide.html#spacing-indentation-and-whitespace (older version)
82
- PuppetLint.new_check(:'80chars') do
83
- def check
84
- manifest_lines.each_with_index do |line, idx|
85
- unless line =~ /:\/\// || line =~ /template\(/
86
- if line.scan(/./mu).size > 80
87
- notify :warning, {
88
- :message => 'line has more than 80 characters',
89
- :line => idx + 1,
90
- :column => 80,
91
- }
92
- end
93
- end
94
- end
95
- end
96
- end
97
- PuppetLint.configuration.send("disable_80chars")
98
-
99
- # Public: Check the manifest tokens for any indentation not using 2 space soft
100
- # tabs and record an error for each instance found.
101
- #
102
- # https://docs.puppet.com/guides/style_guide.html#spacing-indentation-and-whitespace
103
- PuppetLint.new_check(:'2sp_soft_tabs') do
104
- def check
105
- tokens.select { |r|
106
- r.type == :INDENT
107
- }.reject { |r|
108
- r.value.length % 2 == 0
109
- }.each do |token|
110
- notify :error, {
111
- :message => 'two-space soft tabs not used',
112
- :line => token.line,
113
- :column => token.column,
114
- }
115
- end
116
- end
117
- end
118
-
119
1
  # Public: Check the manifest tokens for any arrows (=>) in a grouping ({}) that
120
2
  # are not aligned with other arrows in that grouping.
121
3
  #
@@ -0,0 +1,24 @@
1
+ # Public: Check the raw manifest string for lines containing hard tab
2
+ # characters and record an error for each instance found.
3
+ #
4
+ # https://docs.puppet.com/guides/style_guide.html#spacing-indentation-and-whitespace
5
+ PuppetLint.new_check(:hard_tabs) do
6
+ WHITESPACE_TYPES = Set[:INDENT, :WHITESPACE]
7
+
8
+ def check
9
+ tokens.select { |r|
10
+ WHITESPACE_TYPES.include?(r.type) && r.value.include?("\t")
11
+ }.each do |token|
12
+ notify :error, {
13
+ :message => 'tab character found',
14
+ :line => token.line,
15
+ :column => token.column,
16
+ :token => token,
17
+ }
18
+ end
19
+ end
20
+
21
+ def fix(problem)
22
+ problem[:token].value.gsub!("\t", ' ')
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ # Public: Check the manifest tokens for lines ending with whitespace and record
2
+ # an error for each instance found.
3
+ #
4
+ # https://docs.puppet.com/guides/style_guide.html#spacing-indentation-and-whitespace
5
+ PuppetLint.new_check(:trailing_whitespace) do
6
+ def check
7
+ tokens.select { |token|
8
+ [:WHITESPACE, :INDENT].include?(token.type)
9
+ }.select { |token|
10
+ token.next_token.nil? || token.next_token.type == :NEWLINE
11
+ }.each do |token|
12
+ notify :error, {
13
+ :message => 'trailing whitespace found',
14
+ :line => token.line,
15
+ :column => token.column,
16
+ :token => token,
17
+ }
18
+ end
19
+ end
20
+
21
+ def fix(problem)
22
+ prev_token = problem[:token].prev_token
23
+ next_token = problem[:token].next_token
24
+ prev_token.next_token = next_token
25
+ next_token.prev_token = prev_token unless next_token.nil?
26
+ tokens.delete(problem[:token])
27
+ end
28
+ end
@@ -68,6 +68,10 @@ class PuppetLint
68
68
  @ignore_paths = PuppetLint.configuration.ignore_paths
69
69
  end
70
70
 
71
+ if PuppetLint.configuration.pattern
72
+ @pattern = PuppetLint.configuration.pattern
73
+ end
74
+
71
75
  RakeFileUtils.send(:verbose, true) do
72
76
  linter = PuppetLint.new
73
77
  matched_files = FileList[@pattern]
@@ -1,3 +1,3 @@
1
1
  class PuppetLint
2
- VERSION = '2.2.1'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -272,7 +272,24 @@ describe PuppetLint::Bin do
272
272
  its(:exitstatus) { is_expected.to eq(0) }
273
273
  its(:stdout) do
274
274
  if respond_to?(:include_json)
275
- is_expected.to include_json([{'KIND' => 'WARNING'}])
275
+ is_expected.to include_json([[{'KIND' => 'WARNING'}]])
276
+ else
277
+ is_expected.to match(/\[\n \{/)
278
+ end
279
+ end
280
+ end
281
+
282
+ context 'when displaying results for multiple targets as json' do
283
+
284
+ let(:args) { [
285
+ '--json',
286
+ 'spec/fixtures/test/manifests/fail.pp',
287
+ 'spec/fixtures/test/manifests/warning.pp',
288
+ ] }
289
+ its(:exitstatus) { is_expected.to eq(1) }
290
+ its(:stdout) do
291
+ if respond_to?(:include_json)
292
+ is_expected.to include_json([[{'KIND' => 'ERROR'}],[{'KIND' => 'WARNING'}]])
276
293
  else
277
294
  is_expected.to match(/\[\n \{/)
278
295
  end
@@ -546,6 +546,25 @@ describe PuppetLint::Lexer do
546
546
  expect(token.type).to eq(:FARROW)
547
547
  expect(token.column).to eq(12)
548
548
  end
549
+
550
+ it 'should calculate the column number correctly after an enclosed variable starting with a string' do
551
+ token = @lexer.tokenise(' "bar${foo}" =>').last
552
+ expect(token.type).to eq(:FARROW)
553
+ expect(token.column).to eq(15)
554
+ end
555
+
556
+ it 'should calculate the column number correctly after an enclosed variable ending with a string' do
557
+ token = @lexer.tokenise(' "${foo}bar" =>').last
558
+ expect(token.type).to eq(:FARROW)
559
+ expect(token.column).to eq(15)
560
+ end
561
+
562
+ it 'should calculate the column number correctly after an enclosed variable surround by a string' do
563
+ token = @lexer.tokenise(' "foo${bar}baz" =>').last
564
+ expect(token.type).to eq(:FARROW)
565
+ expect(token.column).to eq(18)
566
+ end
567
+
549
568
  end
550
569
 
551
570
  [