halyard-puppet-lint 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +10 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +20 -0
  6. data/README.md +210 -0
  7. data/Rakefile +7 -0
  8. data/bin/puppet-lint +7 -0
  9. data/lib/puppet-lint.rb +214 -0
  10. data/lib/puppet-lint/bin.rb +79 -0
  11. data/lib/puppet-lint/checkplugin.rb +176 -0
  12. data/lib/puppet-lint/checks.rb +91 -0
  13. data/lib/puppet-lint/configuration.rb +153 -0
  14. data/lib/puppet-lint/data.rb +521 -0
  15. data/lib/puppet-lint/lexer.rb +373 -0
  16. data/lib/puppet-lint/lexer/token.rb +101 -0
  17. data/lib/puppet-lint/monkeypatches.rb +2 -0
  18. data/lib/puppet-lint/monkeypatches/string_percent.rb +52 -0
  19. data/lib/puppet-lint/monkeypatches/string_prepend.rb +13 -0
  20. data/lib/puppet-lint/optparser.rb +118 -0
  21. data/lib/puppet-lint/plugins.rb +74 -0
  22. data/lib/puppet-lint/plugins/check_classes.rb +285 -0
  23. data/lib/puppet-lint/plugins/check_comments.rb +55 -0
  24. data/lib/puppet-lint/plugins/check_conditionals.rb +65 -0
  25. data/lib/puppet-lint/plugins/check_documentation.rb +31 -0
  26. data/lib/puppet-lint/plugins/check_nodes.rb +29 -0
  27. data/lib/puppet-lint/plugins/check_resources.rb +194 -0
  28. data/lib/puppet-lint/plugins/check_strings.rb +174 -0
  29. data/lib/puppet-lint/plugins/check_variables.rb +19 -0
  30. data/lib/puppet-lint/plugins/check_whitespace.rb +170 -0
  31. data/lib/puppet-lint/tasks/puppet-lint.rb +91 -0
  32. data/lib/puppet-lint/version.rb +3 -0
  33. data/puppet-lint.gemspec +24 -0
  34. data/spec/fixtures/test/manifests/fail.pp +2 -0
  35. data/spec/fixtures/test/manifests/ignore.pp +1 -0
  36. data/spec/fixtures/test/manifests/ignore_multiple_block.pp +6 -0
  37. data/spec/fixtures/test/manifests/ignore_multiple_line.pp +2 -0
  38. data/spec/fixtures/test/manifests/ignore_reason.pp +1 -0
  39. data/spec/fixtures/test/manifests/init.pp +3 -0
  40. data/spec/fixtures/test/manifests/malformed.pp +1 -0
  41. data/spec/fixtures/test/manifests/url_interpolation.pp +12 -0
  42. data/spec/fixtures/test/manifests/warning.pp +2 -0
  43. data/spec/puppet-lint/bin_spec.rb +326 -0
  44. data/spec/puppet-lint/configuration_spec.rb +56 -0
  45. data/spec/puppet-lint/ignore_overrides_spec.rb +109 -0
  46. data/spec/puppet-lint/lexer/token_spec.rb +18 -0
  47. data/spec/puppet-lint/lexer_spec.rb +783 -0
  48. data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +105 -0
  49. data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +35 -0
  50. data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +33 -0
  51. data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +45 -0
  52. data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +76 -0
  53. data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +73 -0
  54. data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +25 -0
  55. data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +196 -0
  56. data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +45 -0
  57. data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +84 -0
  58. data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +98 -0
  59. data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +36 -0
  60. data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +52 -0
  61. data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +146 -0
  62. data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +100 -0
  63. data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +55 -0
  64. data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +89 -0
  65. data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +113 -0
  66. data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +45 -0
  67. data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +216 -0
  68. data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +199 -0
  69. data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +114 -0
  70. data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +62 -0
  71. data/spec/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +129 -0
  72. data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +17 -0
  73. data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +73 -0
  74. data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +37 -0
  75. data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +21 -0
  76. data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +54 -0
  77. data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +524 -0
  78. data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +45 -0
  79. data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +101 -0
  80. data/spec/puppet-lint_spec.rb +20 -0
  81. data/spec/spec_helper.rb +129 -0
  82. metadata +229 -0
@@ -0,0 +1,199 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'double_quoted_strings' do
4
+ let(:msg) { 'double quoted string containing no variables' }
5
+
6
+ context 'with fix disabled' do
7
+ context 'double quoted string containing a variable inside single quotes' do
8
+ let(:code) { "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }" }
9
+
10
+ it 'should not detect any problems' do
11
+ expect(problems).to have(0).problems
12
+ end
13
+ end
14
+
15
+ context 'multiple strings in a line' do
16
+ let(:code) { "\"aoeu\" '${foo}'" }
17
+
18
+ it 'should only detect a single problem' do
19
+ expect(problems).to have(1).problem
20
+ end
21
+
22
+ it 'should create a warning' do
23
+ expect(problems).to contain_warning(msg).on_line(1).in_column(1)
24
+ end
25
+ end
26
+
27
+ context 'double quoted string nested in a single quoted string' do
28
+ let(:code) { "'grep \"status=sent\" /var/log/mail.log'" }
29
+
30
+ it 'should not detect any problems' do
31
+ expect(problems).to have(0).problems
32
+ end
33
+ end
34
+
35
+ context 'double quoted string after a comment' do
36
+ let(:code) { "service { 'foo': } # \"bar\"" }
37
+
38
+ it 'should not detect any problems' do
39
+ expect(problems).to have(0).problems
40
+ end
41
+ end
42
+
43
+ context 'double quoted string containing newline but no variables' do
44
+ let(:code) { %{"foo\n"} }
45
+
46
+ it 'should not detect any problems' do
47
+ expect(problems).to have(0).problems
48
+ end
49
+ end
50
+
51
+ context 'double quoted string with backslash for continuation' do
52
+ let(:code) { %{
53
+ class puppet::master::maintenance (
54
+ ) {
55
+ cron { 'puppet_master_reports_cleanup':
56
+ command => "/usr/bin/find /var/lib/puppet/reports -type f -mtime +15 \
57
+ -delete && /usr/bin/find /var/lib/puppet/reports -mindepth 1 \
58
+ -empty -type d -delete",
59
+ minute => '15',
60
+ hour => '5',
61
+ }
62
+ }
63
+ } }
64
+
65
+ it 'should not detect any problems' do
66
+ expect(problems).to have(0).problems
67
+ end
68
+ end
69
+
70
+ context 'double quoted true' do
71
+ let(:code) { "class { 'foo': boolFlag => \"true\" }" }
72
+
73
+ it 'should only detect a single problem' do
74
+ expect(problems).to have(1).problem
75
+ end
76
+
77
+ it 'should create a warning' do
78
+ expect(problems).to contain_warning(msg).on_line(1).in_column(28)
79
+ end
80
+ end
81
+
82
+ context 'double quoted false' do
83
+ let(:code) { "class { 'foo': boolFlag => \"false\" }" }
84
+
85
+ it 'should only detect a single problem' do
86
+ expect(problems).to have(1).problem
87
+ end
88
+
89
+ it 'should create a warning' do
90
+ expect(problems).to contain_warning(msg).on_line(1).in_column(28)
91
+ end
92
+ end
93
+
94
+ context 'double quoted stings containing supported escape patterns' do
95
+ let(:code) {%{
96
+ $string1 = "this string contins \n newline"
97
+ $string2 = "this string contains \ttab"
98
+ $string3 = "this string contains \${escaped} var"
99
+ $string4 = "this string contains \\"escaped \\" double quotes"
100
+ $string5 = "this string contains \\'escaped \\' single quotes"
101
+ $string6 = "this string contains \r line return"
102
+ }}
103
+
104
+ it 'should not detect any problems' do
105
+ expect(problems).to have(0).problems
106
+ end
107
+ end
108
+
109
+ context 'double quoted string with random escape should be rejected' do
110
+ let(:code) {%{ $ztring = "this string contains \l random esape" } }
111
+
112
+ it 'should only detect a single problem' do
113
+ expect(problems).to have(1).problem
114
+ end
115
+
116
+ it 'should create a warning' do
117
+ expect(problems).to contain_warning(msg).on_line(1).in_column(12)
118
+ end
119
+ end
120
+
121
+ context 'single quotes in a double quoted string' do
122
+ let(:code) { "\"this 'string' 'has' lots of 'quotes'\"" }
123
+
124
+ it 'should not detect any problems' do
125
+ expect(problems).to have(0).problems
126
+ end
127
+ end
128
+
129
+ context 'double quoted string containing single quoted string' do
130
+ let(:code) { %[notify { "'foo'": }] }
131
+
132
+ it 'should not detect any problems' do
133
+ expect(problems).to have(0).problems
134
+ end
135
+ end
136
+ end
137
+
138
+ context 'with fix enabled' do
139
+ before do
140
+ PuppetLint.configuration.fix = true
141
+ end
142
+
143
+ after do
144
+ PuppetLint.configuration.fix = false
145
+ end
146
+
147
+ context 'double quoted string containing a variable inside single quotes' do
148
+ let(:code) { "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }" }
149
+
150
+ it 'should not detect any problems' do
151
+ expect(problems).to have(0).problems
152
+ end
153
+
154
+ it 'should not modify the manifest' do
155
+ expect(manifest).to eq(code)
156
+ end
157
+ end
158
+
159
+ context 'double quoted string containing a lone dollar' do
160
+ let(:code) {"\"sed -i 's/^;*[[:space:]]*${name}[[:space:]]*=.*$/${name} = ${value}/g' file\"" }
161
+
162
+ it 'should not detect any problems' do
163
+ expect(problems).to have(0).problems
164
+ end
165
+
166
+ it 'should not modify the manifest' do
167
+ expect(manifest).to eq(code)
168
+ end
169
+ end
170
+
171
+ context 'multiple strings in a line' do
172
+ let(:code) { "\"aoeu\" '${foo}'" }
173
+
174
+ it 'should only detect a single problem' do
175
+ expect(problems).to have(1).problem
176
+ end
177
+
178
+ it 'should fix the manifest' do
179
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
180
+ end
181
+
182
+ it 'should convert the double quoted string into single quotes' do
183
+ expect(manifest).to eq("'aoeu' '${foo}'")
184
+ end
185
+ end
186
+
187
+ context 'single quotes in a double quoted string' do
188
+ let(:code) { "\"this 'string' 'has' lots of 'quotes'\"" }
189
+
190
+ it 'should not detect any problems' do
191
+ expect(problems).to have(0).problems
192
+ end
193
+
194
+ it 'should not modify the manifest' do
195
+ expect(manifest).to eq(code)
196
+ end
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,114 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'only_variable_string' do
4
+ let(:msg) { 'string containing only a variable' }
5
+
6
+ context 'with fix disabled' do
7
+ context 'string containing only a variable' do
8
+ let(:code) { '"${foo}"' }
9
+
10
+ it 'should only detect a single problem' do
11
+ expect(problems).to have(1).problem
12
+ end
13
+
14
+ it 'should create a warning' do
15
+ expect(problems).to contain_warning(msg).on_line(1).in_column(3)
16
+ end
17
+ end
18
+
19
+ context 'string containing only a variable w/ ref' do
20
+ let(:code) { '"${foo[0]}"' }
21
+
22
+ it 'should only detect a single problem' do
23
+ expect(problems).to have(1).problem
24
+ end
25
+
26
+ it 'should create a warning' do
27
+ expect(problems).to contain_warning(msg).on_line(1).in_column(3)
28
+ end
29
+ end
30
+
31
+ context 'string containing only a variable w/ lots of refs' do
32
+ let(:code) { '"${foo[0][aoeuaoeu][bar][999]}"' }
33
+
34
+ it 'should only detect a single problem' do
35
+ expect(problems).to have(1).problem
36
+ end
37
+
38
+ it 'should create a warning' do
39
+ expect(problems).to contain_warning(msg).on_line(1).in_column(3)
40
+ end
41
+ end
42
+
43
+ context 'string containing only a variable as a hash key' do
44
+ let(:code) { "
45
+ $bar = 'key'
46
+ $foo = {
47
+ \"$bar\" => 1,
48
+ }"
49
+ }
50
+
51
+ it 'should not detect any problems' do
52
+ expect(problems).to be_empty
53
+ end
54
+ end
55
+ end
56
+
57
+ context 'with fix enabled' do
58
+ before do
59
+ PuppetLint.configuration.fix = true
60
+ end
61
+
62
+ after do
63
+ PuppetLint.configuration.fix = false
64
+ end
65
+
66
+ context 'string containing only a variable' do
67
+ let(:code) { '"${foo}"' }
68
+
69
+ it 'should only detect a single problem' do
70
+ expect(problems).to have(1).problem
71
+ end
72
+
73
+ it 'should fix the manifest' do
74
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(3)
75
+ end
76
+
77
+ it 'should unquote the variable' do
78
+ expect(manifest).to eq("$foo")
79
+ end
80
+ end
81
+
82
+ context 'string contaiting only a variable w/ ref' do
83
+ let(:code) { '"${foo[0]}"' }
84
+
85
+ it 'should only detect a single problem' do
86
+ expect(problems).to have(1).problem
87
+ end
88
+
89
+ it 'should fix the manifest' do
90
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(3)
91
+ end
92
+
93
+ it 'should unquoted the variable' do
94
+ expect(manifest).to eq("$foo[0]")
95
+ end
96
+ end
97
+
98
+ context 'string containing only a variable w/ lots of refs' do
99
+ let(:code) { '"${foo[0][aoeuaoeu][bar][999]}"' }
100
+
101
+ it 'should only detect a single problem' do
102
+ expect(problems).to have(1).problem
103
+ end
104
+
105
+ it 'should fix the manifest' do
106
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(3)
107
+ end
108
+
109
+ it 'should unquote the variable' do
110
+ expect(manifest).to eq("$foo[0][aoeuaoeu][bar][999]")
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'puppet_url_without_modules' do
4
+ let(:msg) { 'puppet:// URL without modules/ found' }
5
+
6
+ context 'puppet:// url with modules' do
7
+ let(:code) { "'puppet:///modules/foo'" }
8
+
9
+ it 'should not detect any problems' do
10
+ expect(problems).to have(0).problems
11
+ end
12
+ end
13
+
14
+ context 'with fix disabled' do
15
+ context 'puppet:// url without modules' do
16
+ let(:code) { "'puppet:///foo'" }
17
+
18
+ it 'should only detect a single problem' do
19
+ expect(problems).to have(1).problem
20
+ end
21
+
22
+ it 'should create a warning' do
23
+ expect(problems).to contain_warning(msg).on_line(1).in_column(1)
24
+ end
25
+ end
26
+ end
27
+
28
+ context 'with fix enabled' do
29
+ before do
30
+ PuppetLint.configuration.fix = true
31
+ end
32
+
33
+ after do
34
+ PuppetLint.configuration.fix = false
35
+ end
36
+
37
+ context 'puppet:// url without modules' do
38
+ let(:code) { "'puppet:///foo'" }
39
+
40
+ it 'should only detect a single problem' do
41
+ expect(problems).to have(1).problem
42
+ end
43
+
44
+ it 'should fix the manifest' do
45
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
46
+ end
47
+
48
+ it 'should insert modules into the path' do
49
+ expect(manifest).to eq("'puppet:///modules/foo'")
50
+ end
51
+ end
52
+ end
53
+
54
+ context 'double string wrapped puppet:// urls' do
55
+ let(:code) { File.read('spec/fixtures/test/manifests/url_interpolation.pp') }
56
+
57
+ it 'should detect several problems' do
58
+ expect(problems).to have(4).problem
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'quoted_booleans' do
4
+ let(:msg) { 'quoted boolean value found' }
5
+
6
+ context 'with fix disabled' do
7
+ context 'quoted false' do
8
+ let(:code) { "class { 'foo': boolFlag => 'false' }" }
9
+
10
+ it 'should only detect a single problem' do
11
+ expect(problems).to have(1).problem
12
+ end
13
+
14
+ it 'should create a warning' do
15
+ expect(problems).to contain_warning(msg).on_line(1).in_column(28)
16
+ end
17
+ end
18
+
19
+ context 'quoted true' do
20
+ let(:code) { "class { 'foo': boolFlag => 'true' }" }
21
+
22
+ it 'should only detect a single problem' do
23
+ expect(problems).to have(1).problem
24
+ end
25
+
26
+ it 'should create a warning' do
27
+ expect(problems).to contain_warning(msg).on_line(1).in_column(28)
28
+ end
29
+ end
30
+
31
+ context 'double quoted true' do
32
+ let(:code) { "class { 'foo': boolFlag => \"true\" }" }
33
+
34
+ it 'should only detect a single problem' do
35
+ expect(problems).to have(1).problem
36
+ end
37
+
38
+ it 'should create a warning' do
39
+ expect(problems).to contain_warning(msg).on_line(1).in_column(28)
40
+ end
41
+ end
42
+
43
+ context 'double quoted false' do
44
+ let(:code) { "class { 'foo': boolFlag => \"false\" }" }
45
+
46
+ it 'should only detect a single problem' do
47
+ expect(problems).to have(1).problem
48
+ end
49
+
50
+ it 'should create a warning' do
51
+ expect(problems).to contain_warning(msg).on_line(1).in_column(28)
52
+ end
53
+ end
54
+ end
55
+
56
+ context 'with fix enabled' do
57
+ before do
58
+ PuppetLint.configuration.fix = true
59
+ end
60
+
61
+ after do
62
+ PuppetLint.configuration.fix = false
63
+ end
64
+
65
+ context 'quoted false' do
66
+ let(:code) { "class { 'foo': boolFlag => 'false' }" }
67
+
68
+ it 'should only detect a single problem' do
69
+ expect(problems).to have(1).problem
70
+ end
71
+
72
+ it 'should fix the manifest' do
73
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(28)
74
+ end
75
+
76
+ it 'should unquote the boolean' do
77
+ expect(manifest).to eq("class { 'foo': boolFlag => false }")
78
+ end
79
+ end
80
+
81
+ context 'quoted true' do
82
+ let(:code) { "class { 'foo': boolFlag => 'true' }" }
83
+
84
+ it 'should only detect a single problem' do
85
+ expect(problems).to have(1).problem
86
+ end
87
+
88
+ it 'should fix the manifest' do
89
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(28)
90
+ end
91
+
92
+ it 'should unquote the boolean' do
93
+ expect(manifest).to eq("class { 'foo': boolFlag => true }")
94
+ end
95
+ end
96
+
97
+ context 'double quoted true' do
98
+ let(:code) { "class { 'foo': boolFlag => \"true\" }" }
99
+
100
+ it 'should only detect a single problem' do
101
+ expect(problems).to have(1).problem
102
+ end
103
+
104
+ it 'should fix the manifest' do
105
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(28)
106
+ end
107
+
108
+ it 'should unquote the boolean' do
109
+ expect(manifest).to eq("class { 'foo': boolFlag => true }")
110
+ end
111
+ end
112
+
113
+ context 'double quoted false' do
114
+ let(:code) { "class { 'foo': boolFlag => \"false\" }" }
115
+
116
+ it 'should only detect a single problem' do
117
+ expect(problems).to have(1).problem
118
+ end
119
+
120
+ it 'should fix the manifest' do
121
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(28)
122
+ end
123
+
124
+ it 'should unquote the boolean' do
125
+ expect(manifest).to eq("class { 'foo': boolFlag => false }")
126
+ end
127
+ end
128
+ end
129
+ end