puppet-lint 2.3.0 → 2.3.1

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 (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
@@ -5,7 +5,7 @@ describe 'slash_comments' do
5
5
 
6
6
  context 'with fix disabled' do
7
7
  context 'slash comments' 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
@@ -38,7 +38,7 @@ describe 'slash_comments' do
38
38
  end
39
39
 
40
40
  it 'should replace the double slash with a hash' do
41
- expect(manifest).to eq("# foo")
41
+ expect(manifest).to eq('# foo')
42
42
  end
43
43
  end
44
44
  end
@@ -5,17 +5,19 @@ describe 'star_comments' do
5
5
 
6
6
  context 'with fix disabled' do
7
7
  context 'multiline comment w/ one line of content' do
8
- let(:code) { "
9
- /* foo
10
- */
11
- "}
8
+ let(:code) do
9
+ <<-END
10
+ /* foo
11
+ */
12
+ END
13
+ end
12
14
 
13
15
  it 'should only detect a single problem' do
14
16
  expect(problems).to have(1).problem
15
17
  end
16
18
 
17
19
  it 'should create a warning' do
18
- expect(problems).to contain_warning(msg).on_line(2).in_column(9)
20
+ expect(problems).to contain_warning(msg).on_line(1).in_column(11)
19
21
  end
20
22
  end
21
23
  end
@@ -30,13 +32,21 @@ describe 'star_comments' do
30
32
  end
31
33
 
32
34
  context 'multiline comment w/ no indents' do
33
- let(:code) { "/* foo *
34
- * *
35
- * bar */"}
35
+ let(:code) do
36
+ <<-END.gsub(%r{^ {10}}, '')
37
+ /* foo *
38
+ * *
39
+ * bar */
40
+ END
41
+ end
36
42
 
37
- let(:fixed) { "# foo *
38
- # *
39
- # bar"}
43
+ let(:fixed) do
44
+ <<-END.gsub(%r{^ {10}}, '')
45
+ # foo *
46
+ # *
47
+ # bar
48
+ END
49
+ end
40
50
 
41
51
  it 'should only detect a single problem' do
42
52
  expect(problems).to have(1).problem
@@ -50,23 +60,27 @@ describe 'star_comments' do
50
60
  expect(manifest).to eq(fixed)
51
61
  end
52
62
  end
53
-
63
+
54
64
  context 'multiline comment w/ one line of content' do
55
- let(:code) { "
56
- /* foo
57
- */
58
- "}
65
+ let(:code) do
66
+ <<-END
67
+ /* foo
68
+ */
69
+ END
70
+ end
59
71
 
60
- let(:fixed) { "
61
- # foo
62
- "}
72
+ let(:fixed) do
73
+ <<-END
74
+ # foo
75
+ END
76
+ end
63
77
 
64
78
  it 'should only detect a single problem' do
65
79
  expect(problems).to have(1).problem
66
80
  end
67
81
 
68
82
  it 'should create a warning' do
69
- expect(problems).to contain_fixed(msg).on_line(2).in_column(9)
83
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(11)
70
84
  end
71
85
 
72
86
  it 'should convert the multiline comment' do
@@ -75,27 +89,31 @@ describe 'star_comments' do
75
89
  end
76
90
 
77
91
  context 'multiline comment w/ multiple line of content' do
78
- let(:code) { "
79
- /* foo
80
- * bar
81
- * baz
82
- */
83
- notify { 'foo': }
84
- "}
85
-
86
- let(:fixed) { "
87
- # foo
88
- # bar
89
- # baz
90
- notify { 'foo': }
91
- "}
92
+ let(:code) do
93
+ <<-END
94
+ /* foo
95
+ * bar
96
+ * baz
97
+ */
98
+ notify { 'foo': }
99
+ END
100
+ end
101
+
102
+ let(:fixed) do
103
+ <<-END
104
+ # foo
105
+ # bar
106
+ # baz
107
+ notify { 'foo': }
108
+ END
109
+ end
92
110
 
93
111
  it 'should only detect a single problem' do
94
112
  expect(problems).to have(1).problem
95
113
  end
96
114
 
97
115
  it 'should create a warning' do
98
- expect(problems).to contain_fixed(msg).on_line(2).in_column(9)
116
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(11)
99
117
  end
100
118
 
101
119
  it 'should convert the multiline comment' do
@@ -4,12 +4,14 @@ describe 'case_without_default' do
4
4
  let(:msg) { 'case statement without a default case' }
5
5
 
6
6
  context 'case statement with a default case' do
7
- let(:code) { "
8
- case $foo {
9
- bar: { }
10
- default: { }
11
- }"
12
- }
7
+ let(:code) do
8
+ <<-END
9
+ case $foo {
10
+ bar: { }
11
+ default: { }
12
+ }
13
+ END
14
+ end
13
15
 
14
16
  it 'should not detect any problems' do
15
17
  expect(problems).to have(0).problems
@@ -17,31 +19,35 @@ describe 'case_without_default' do
17
19
  end
18
20
 
19
21
  context 'case statement without a default case' do
20
- let(:code) { "
21
- case $foo {
22
- bar: { }
23
- baz: { }
24
- }"
25
- }
22
+ let(:code) do
23
+ <<-END
24
+ case $foo {
25
+ bar: { }
26
+ baz: { }
27
+ }
28
+ END
29
+ end
26
30
 
27
31
  it 'should only detect a single problem' do
28
32
  expect(problems).to have(1).problem
29
33
  end
30
34
 
31
35
  it 'should create a warning' do
32
- expect(problems).to contain_warning(msg).on_line(2).in_column(7)
36
+ expect(problems).to contain_warning(msg).on_line(1).in_column(9)
33
37
  end
34
38
  end
35
-
39
+
36
40
  context 'nested case statements without a default case on the outermost' do
37
- let(:code) { "
38
- case $foo {
39
- case $foop {
40
- bar: {}
41
- default: {}
42
- }
43
- }"
44
- }
41
+ let(:code) do
42
+ <<-END
43
+ case $foo {
44
+ case $foop {
45
+ bar: {}
46
+ default: {}
47
+ }
48
+ }
49
+ END
50
+ end
45
51
 
46
52
  it 'should only detect a single problem' do
47
53
  expect(problems).to have(1).problem
@@ -53,43 +59,47 @@ describe 'case_without_default' do
53
59
  end
54
60
 
55
61
  context 'three nested case statements with two missing default cases' do
56
- let(:code) { "
57
- case $foo {
58
- case $foop {
59
- bar: {}
60
- case $woop {
61
- baz: {}
62
- }
63
- default: {}
64
- }
65
- }"
66
- }
62
+ let(:code) do
63
+ <<-END
64
+ case $foo {
65
+ case $foop {
66
+ bar: {}
67
+ case $woop {
68
+ baz: {}
69
+ }
70
+ default: {}
71
+ }
72
+ }
73
+ END
74
+ end
67
75
 
68
76
  it 'should detect two problems' do
69
77
  expect(problems).to have(2).problems
70
78
  end
71
79
 
72
80
  it 'should create two warnings' do
73
- expect(problems).to contain_warning(msg).on_line(2).in_column(7)
74
- expect(problems).to contain_warning(msg).on_line(5).in_column(4)
81
+ expect(problems).to contain_warning(msg).on_line(1).in_column(9)
82
+ expect(problems).to contain_warning(msg).on_line(4).in_column(13)
75
83
  end
76
84
  end
77
85
 
78
86
  context 'issue-117' do
79
- let(:code) { "
80
- $mem = inline_template('<%
81
- mem,unit = scope.lookupvar(\'::memorysize\').split
82
- mem = mem.to_f
83
- # Normalize mem to bytes
84
- case unit
85
- when nil: mem *= (1<<0)
86
- when \'kB\': mem *= (1<<10)
87
- when \'MB\': mem *= (1<<20)
88
- when \'GB\': mem *= (1<<30)
89
- when \'TB\': mem *= (1<<40)
90
- end
91
- %><%= mem.to_i %>')
92
- "}
87
+ let(:code) do
88
+ <<-END
89
+ $mem = inline_template('<%
90
+ mem,unit = scope.lookupvar(\'::memorysize\').split
91
+ mem = mem.to_f
92
+ # Normalize mem to bytes
93
+ case unit
94
+ when nil: mem *= (1<<0)
95
+ when \'kB\': mem *= (1<<10)
96
+ when \'MB\': mem *= (1<<20)
97
+ when \'GB\': mem *= (1<<30)
98
+ when \'TB\': mem *= (1<<40)
99
+ end
100
+ %><%= mem.to_i %>')
101
+ END
102
+ end
93
103
 
94
104
  it 'should not detect any problems' do
95
105
  expect(problems).to have(0).problems
@@ -4,30 +4,34 @@ describe 'selector_inside_resource' do
4
4
  let(:msg) { 'selector inside resource block' }
5
5
 
6
6
  context 'resource with a selector' do
7
- let(:code) { "
8
- file { 'foo':
9
- ensure => $bar ? {
10
- true => present,
11
- default => absent,
12
- },
13
- }"
14
- }
7
+ let(:code) do
8
+ <<-END
9
+ file { 'foo':
10
+ ensure => $bar ? {
11
+ true => present,
12
+ default => absent,
13
+ },
14
+ }
15
+ END
16
+ end
15
17
 
16
18
  it 'should only detect a single problem' do
17
19
  expect(problems).to have(1).problem
18
20
  end
19
21
 
20
22
  it 'should create a warning' do
21
- expect(problems).to contain_warning(msg).on_line(3).in_column(16)
23
+ expect(problems).to contain_warning(msg).on_line(2).in_column(18)
22
24
  end
23
25
  end
24
26
 
25
27
  context 'resource with a variable as a attr value' do
26
- let(:code) { "
27
- file { 'foo',
28
- ensure => $bar,
29
- }"
30
- }
28
+ let(:code) do
29
+ <<-END
30
+ file { 'foo',
31
+ ensure => $bar,
32
+ }
33
+ END
34
+ end
31
35
 
32
36
  it 'should not detect any problems' do
33
37
  expect(problems).to have(0).problems
@@ -5,7 +5,7 @@ describe 'documentation' do
5
5
  let(:define_msg) { 'defined type not documented' }
6
6
 
7
7
  describe 'undocumented class' do
8
- let(:code) { "class test {}" }
8
+ let(:code) { 'class test {}' }
9
9
 
10
10
  it 'should only detect a single problem' do
11
11
  expect(problems).to have(1).problem
@@ -17,10 +17,12 @@ describe 'documentation' do
17
17
  end
18
18
 
19
19
  describe 'documented class' do
20
- let(:code) { "
21
- # foo
22
- class test {}
23
- "}
20
+ let(:code) do
21
+ <<-END
22
+ # foo
23
+ class test {}
24
+ END
25
+ end
24
26
 
25
27
  it 'should not detect any problems' do
26
28
  expect(problems).to have(0).problems
@@ -28,7 +30,7 @@ describe 'documentation' do
28
30
  end
29
31
 
30
32
  describe 'undocumented defined type' do
31
- let(:code) { "define test {}" }
33
+ let(:code) { 'define test {}' }
32
34
 
33
35
  it 'should only detect a single problem' do
34
36
  expect(problems).to have(1).problem
@@ -40,10 +42,12 @@ describe 'documentation' do
40
42
  end
41
43
 
42
44
  describe 'documented defined type' do
43
- let(:code) { "
44
- # foo
45
- define test {}
46
- "}
45
+ let(:code) do
46
+ <<-END
47
+ # foo
48
+ define test {}
49
+ END
50
+ end
47
51
 
48
52
  it 'should not detect any problems' do
49
53
  expect(problems).to have(0).problems
@@ -5,7 +5,7 @@ describe 'unquoted_node_name' do
5
5
 
6
6
  context 'with fix disabled' do
7
7
  context 'unquoted node name' do
8
- let(:code) { "node foo { }" }
8
+ let(:code) { 'node foo { }' }
9
9
 
10
10
  it 'should only detect a single problem' do
11
11
  expect(problems).to have(1).problem
@@ -17,7 +17,7 @@ describe 'unquoted_node_name' do
17
17
  end
18
18
 
19
19
  context 'default node' do
20
- let(:code) { "node default { }" }
20
+ let(:code) { 'node default { }' }
21
21
 
22
22
  it 'should not detect any problems' do
23
23
  expect(problems).to have(0).problems
@@ -33,7 +33,7 @@ describe 'unquoted_node_name' do
33
33
  end
34
34
 
35
35
  context 'regex node name' do
36
- let(:code) { "node /foo/ { }" }
36
+ let(:code) { 'node /foo/ { }' }
37
37
 
38
38
  it 'should not detect any problems' do
39
39
  expect(problems).to have(0).problems
@@ -41,7 +41,7 @@ describe 'unquoted_node_name' do
41
41
  end
42
42
 
43
43
  context 'multiple bare node names' do
44
- let(:code) { "node foo, bar, baz { }" }
44
+ let(:code) { 'node foo, bar, baz { }' }
45
45
 
46
46
  it 'should detect 3 problems' do
47
47
  expect(problems).to have(3).problems
@@ -68,7 +68,7 @@ describe 'unquoted_node_name' do
68
68
  end
69
69
 
70
70
  context 'multiple node blocks' do
71
- let(:code) { "node foo { } node bar { }" }
71
+ let(:code) { 'node foo { } node bar { }' }
72
72
 
73
73
  it 'should detect 2 problems' do
74
74
  expect(problems).to have(2).problems
@@ -103,7 +103,7 @@ describe 'unquoted_node_name' do
103
103
  end
104
104
 
105
105
  context 'unquoted node name' do
106
- let(:code) { "node foo { }" }
106
+ let(:code) { 'node foo { }' }
107
107
 
108
108
  it 'should only detect a single problem' do
109
109
  expect(problems).to have(1).problem
@@ -119,7 +119,7 @@ describe 'unquoted_node_name' do
119
119
  end
120
120
 
121
121
  context 'multiple bare node names' do
122
- let(:code) { "node foo, bar, baz { }" }
122
+ let(:code) { 'node foo, bar, baz { }' }
123
123
  let(:fixed) { "node 'foo', 'bar', 'baz' { }" }
124
124
 
125
125
  it 'should detect 3 problems' do