puppet-lint 0.2.0 → 0.2.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 (44) hide show
  1. data/lib/puppet-lint.rb +1 -3
  2. data/lib/puppet-lint/configuration.rb +7 -6
  3. data/lib/puppet-lint/plugin.rb +14 -24
  4. data/lib/puppet-lint/plugins/check_classes.rb +14 -10
  5. data/lib/puppet-lint/plugins/check_documentation.rb +10 -14
  6. data/lib/puppet-lint/plugins/check_resources.rb +56 -73
  7. data/lib/puppet-lint/version.rb +1 -1
  8. data/spec/puppet-lint/configuration_spec.rb +4 -1
  9. data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +51 -0
  10. data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +23 -0
  11. data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +45 -0
  12. data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +71 -0
  13. data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +67 -0
  14. data/spec/puppet-lint/plugins/check_classes/parameterised_classes_spec.rb +43 -0
  15. data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +23 -0
  16. data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +93 -0
  17. data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +16 -0
  18. data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +19 -0
  19. data/spec/puppet-lint/plugins/{check_conditionals_spec.rb → check_conditionals/case_without_default_spec.rb} +1 -39
  20. data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +33 -0
  21. data/spec/puppet-lint/plugins/{check_documentation_spec.rb → check_documentation/documentation_spec.rb} +1 -9
  22. data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +23 -0
  23. data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +43 -0
  24. data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +26 -0
  25. data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +43 -0
  26. data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +11 -0
  27. data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +110 -0
  28. data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +83 -0
  29. data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +16 -0
  30. data/spec/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +55 -0
  31. data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +16 -0
  32. data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +29 -0
  33. data/spec/puppet-lint/plugins/{check_variables_spec.rb → check_variables/variable_contains_dash_spec.rb} +1 -9
  34. data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +20 -0
  35. data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +38 -0
  36. data/spec/puppet-lint/plugins/{check_whitespace_spec.rb → check_whitespace/arrow_alignment_spec.rb} +1 -86
  37. data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +16 -0
  38. data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +16 -0
  39. data/spec/spec_helper.rb +17 -0
  40. metadata +122 -92
  41. data/spec/puppet-lint/plugins/check_classes_spec.rb +0 -390
  42. data/spec/puppet-lint/plugins/check_comments_spec.rb +0 -40
  43. data/spec/puppet-lint/plugins/check_resources_spec.rb +0 -249
  44. data/spec/puppet-lint/plugins/check_strings_spec.rb +0 -175
@@ -1,14 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe PuppetLint::Plugins::CheckDocumentation do
4
- subject do
5
- klass = described_class.new
6
- fileinfo = {}
7
- fileinfo[:fullpath] = defined?(fullpath).nil? ? '' : fullpath
8
- klass.run(fileinfo, code)
9
- klass
10
- end
11
-
3
+ describe 'documentation' do
12
4
  describe 'undocumented class' do
13
5
  let(:code) { "class test {}" }
14
6
 
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'duplicate_params' do
4
+ describe 'resource with duplicate parameters' do
5
+ let(:code) { "
6
+ file { '/tmp/foo':
7
+ ensure => present,
8
+ foo => bar,
9
+ baz => gronk,
10
+ foo => meh,
11
+ }"
12
+ }
13
+
14
+ its(:problems) {
15
+ should only_have_problem({
16
+ :kind => :error,
17
+ :message => 'duplicate parameter found in resource',
18
+ :linenumber => 6,
19
+ :column => 9,
20
+ })
21
+ }
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ensure_first_param' do
4
+ describe 'ensure as only attr in a single line resource' do
5
+ let(:code) { "file { 'foo': ensure => present }" }
6
+
7
+ its(:problems) { should be_empty }
8
+ end
9
+
10
+ describe 'ensure as only attr in a multi line resource' do
11
+ let(:code) { "
12
+ file { 'foo':
13
+ ensure => present,
14
+ }"
15
+ }
16
+
17
+ its(:problems) { should be_empty }
18
+ end
19
+
20
+ describe 'ensure as second attr in a multi line resource' do
21
+ let(:code) { "
22
+ file { 'foo':
23
+ mode => '0000',
24
+ ensure => present,
25
+ }"
26
+ }
27
+
28
+ its(:problems) {
29
+ should only_have_problem :kind => :warning, :message => "ensure found on line but it's not the first attribute", :linenumber => 4
30
+ }
31
+ end
32
+
33
+ describe 'ensure as first attr in a multi line resource' do
34
+ let(:code) { "
35
+ file { 'foo':
36
+ ensure => present,
37
+ mode => '0000',
38
+ }"
39
+ }
40
+
41
+ its(:problems) { should be_empty }
42
+ end
43
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ensure_not_symlink_target' do
4
+ describe 'file resource creating a symlink with seperate target attr' do
5
+ let(:code) { "
6
+ file { 'foo':
7
+ ensure => link,
8
+ target => '/foo/bar',
9
+ }"
10
+ }
11
+
12
+ its(:problems) { should be_empty }
13
+ end
14
+
15
+ describe 'file resource creating a symlink with target specified in ensure' do
16
+ let(:code) { "
17
+ file { 'foo':
18
+ ensure => '/foo/bar',
19
+ }"
20
+ }
21
+
22
+ its(:problems) {
23
+ should only_have_problem :kind => :warning, :message => "symlink target specified in ensure attr", :linenumber => 3
24
+ }
25
+ end
26
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'file_mode' do
4
+ describe '3 digit file mode' do
5
+ let(:code) { "file { 'foo': mode => '777' }" }
6
+
7
+ its(:problems) {
8
+ should only_have_problem :kind => :warning, :message => "mode should be represented as a 4 digit octal value or symbolic mode", :linenumber => 1
9
+ }
10
+ end
11
+
12
+ describe '4 digit file mode' do
13
+ let(:code) { "file { 'foo': mode => '0777' }" }
14
+
15
+ its(:problems) { should be_empty }
16
+ end
17
+
18
+ describe 'file mode as a variable' do
19
+ let(:code) { "file { 'foo': mode => $file_mode }" }
20
+
21
+ its(:problems) { should be_empty }
22
+ end
23
+
24
+ describe 'symbolic file mode' do
25
+ let(:code) { "file { 'foo': mode => 'u=rw,og=r' }" }
26
+
27
+ its(:problems) { should be_empty }
28
+ end
29
+
30
+ describe 'file mode undef unquoted' do
31
+ let(:code) { "file { 'foo': mode => undef }" }
32
+
33
+ its(:problems) { should be_empty }
34
+ end
35
+
36
+ describe 'file mode undef quoted' do
37
+ let(:code) { "file { 'foo': mode => 'undef' }" }
38
+
39
+ its(:problems) {
40
+ should only_have_problem :kind => :warning, :message => "mode should be represented as a 4 digit octal value or symbolic mode", :linenumber => 1
41
+ }
42
+ end
43
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'unquoted_file_mode' do
4
+ describe '4 digit unquoted file mode' do
5
+ let(:code) { "file { 'foo': mode => 0777 }" }
6
+
7
+ its(:problems) {
8
+ should only_have_problem :kind => :warning, :message => "unquoted file mode"
9
+ }
10
+ end
11
+ end
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'unquoted_resource_title' do
4
+ describe 'quoted resource title on single line resource' do
5
+ let(:code) { "file { 'foo': }" }
6
+
7
+ its(:problems) { should be_empty }
8
+ end
9
+
10
+ describe 'unquoted resource title on single line resource' do
11
+ let(:code) { "file { foo: }" }
12
+
13
+ its(:problems) {
14
+ should only_have_problem :kind => :warning, :message => "unquoted resource title", :linenumber => 1
15
+ }
16
+ end
17
+
18
+ describe 'quoted resource title on multi line resource' do
19
+ let(:code) { "
20
+ file { 'foo':
21
+ }"
22
+ }
23
+
24
+ its(:problems) { should be_empty }
25
+ end
26
+
27
+ describe 'unquoted resource title on multi line resource' do
28
+ let(:code) { "
29
+ file { foo:
30
+ }"
31
+ }
32
+
33
+ its(:problems) {
34
+ should only_have_problem :kind => :warning, :message => "unquoted resource title", :linenumber => 2
35
+ }
36
+ end
37
+
38
+ describe 'condensed resources with quoted titles' do
39
+ let(:code) { "
40
+ file {
41
+ 'foo': ;
42
+ 'bar': ;
43
+ }"
44
+ }
45
+
46
+ its(:problems) { should be_empty }
47
+ end
48
+
49
+ describe 'condensed resources with an unquoted title' do
50
+ let(:code) { "
51
+ file {
52
+ 'foo': ;
53
+ bar: ;
54
+ }"
55
+ }
56
+
57
+ its(:problems) {
58
+ should only_have_problem :kind => :warning, :message => "unquoted resource title", :linenumber => 4
59
+ }
60
+ end
61
+
62
+ describe 'single line resource with an array of titles (all quoted)' do
63
+ let(:code) { "file { ['foo', 'bar']: }" }
64
+
65
+ its(:problems) { should be_empty }
66
+ end
67
+
68
+ describe 'resource inside a case statement' do
69
+ let(:code) { "
70
+ case $ensure {
71
+ 'absent': {
72
+ file { \"some_file_${name}\":
73
+ ensure => absent,
74
+ }
75
+ }
76
+ }"
77
+ }
78
+
79
+ its(:problems) { should == [] }
80
+ end
81
+
82
+ describe 'issue #116' do
83
+ let(:code) { "
84
+ $config_file_init = $::operatingsystem ? {
85
+ /(?i:Debian|Ubuntu|Mint)/ => '/etc/default/foo',
86
+ default => '/etc/sysconfig/foo',
87
+ }"
88
+ }
89
+
90
+ its(:problems) { should == [] }
91
+ end
92
+
93
+ describe 'case statement' do
94
+ let(:code) { %{
95
+ case $operatingsystem {
96
+ centos: {
97
+ $version = '1.2.3'
98
+ }
99
+ solaris: {
100
+ $version = '3.2.1'
101
+ }
102
+ default: {
103
+ fail("Module ${module_name} is not supported on ${operatingsystem}")
104
+ }
105
+ }}
106
+ }
107
+
108
+ its(:problems) { should == [] }
109
+ end
110
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'double_quoted_strings' do
4
+ describe 'double quoted string containing a variable inside single quotes' do
5
+ let(:code) { "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }" }
6
+
7
+ its(:problems) { should be_empty }
8
+ end
9
+
10
+ describe 'multiple strings in a line' do
11
+ let(:code) { "\"aoeu\" '${foo}'" }
12
+
13
+ its(:problems) {
14
+ should have_problem({
15
+ :kind => :warning,
16
+ :message => 'double quoted string containing no variables',
17
+ :linenumber => 1,
18
+ :column => 1,
19
+ })
20
+ }
21
+ end
22
+
23
+ describe 'double quoted string nested in a single quoted string' do
24
+ let(:code) { "'grep \"status=sent\" /var/log/mail.log'" }
25
+
26
+ its(:problems) { should be_empty }
27
+ end
28
+
29
+ describe 'double quoted string after a comment' do
30
+ let(:code) { "service { 'foo': } # \"bar\"" }
31
+
32
+ its(:problems) { should be_empty }
33
+ end
34
+
35
+ describe 'double quoted string containing newline but no variables' do
36
+ let(:code) { %{"foo\n"} }
37
+
38
+ its(:problems) { should be_empty }
39
+ end
40
+
41
+ describe 'double quoted string with backslash for continuation' do
42
+ let(:code) { %{
43
+ class puppet::master::maintenance (
44
+ ) {
45
+ cron { 'puppet_master_reports_cleanup':
46
+ command => "/usr/bin/find /var/lib/puppet/reports -type f -mtime +15 \
47
+ -delete && /usr/bin/find /var/lib/puppet/reports -mindepth 1 \
48
+ -empty -type d -delete",
49
+ minute => '15',
50
+ hour => '5',
51
+ }
52
+ }
53
+ } }
54
+
55
+ its(:problems) { should == [] }
56
+ end
57
+
58
+ describe 'double quoted true' do
59
+ let(:code) { "class { 'foo': boolFlag => \"true\" }" }
60
+
61
+ its(:problems) {
62
+ should have_problem({
63
+ :kind => :warning,
64
+ :message => 'double quoted string containing no variables',
65
+ :linenumber => 1,
66
+ :column => 28,
67
+ })
68
+ }
69
+ end
70
+
71
+ describe 'double quoted false' do
72
+ let(:code) { "class { 'foo': boolFlag => \"false\" }" }
73
+
74
+ its(:problems) {
75
+ should have_problem({
76
+ :kind => :warning,
77
+ :message => 'double quoted string containing no variables',
78
+ :linenumber => 1,
79
+ :column => 28,
80
+ })
81
+ }
82
+ end
83
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'only_variable_string' do
4
+ describe 'string containing only a variable' do
5
+ let(:code) { '"${foo}"' }
6
+
7
+ its(:problems) {
8
+ should only_have_problem({
9
+ :kind => :warning,
10
+ :message => 'string containing only a variable',
11
+ :linenumber => 1,
12
+ :column => 3,
13
+ })
14
+ }
15
+ end
16
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'quoted_booleans' do
4
+ describe 'quoted false' do
5
+ let(:code) { "class { 'foo': boolFlag => 'false' }" }
6
+
7
+ its(:problems) {
8
+ should only_have_problem({
9
+ :kind => :warning,
10
+ :message => 'quoted boolean value found',
11
+ :linenumber => 1,
12
+ :column => 28,
13
+ })
14
+ }
15
+ end
16
+
17
+ describe 'quoted true' do
18
+ let(:code) { "class { 'foo': boolFlag => 'true' }" }
19
+
20
+ its(:problems) {
21
+ should only_have_problem({
22
+ :kind => :warning,
23
+ :message => 'quoted boolean value found',
24
+ :linenumber => 1,
25
+ :column => 28,
26
+ })
27
+ }
28
+ end
29
+
30
+ describe 'double quoted true' do
31
+ let(:code) { "class { 'foo': boolFlag => \"true\" }" }
32
+
33
+ its(:problems) {
34
+ should have_problem({
35
+ :kind => :warning,
36
+ :message => 'quoted boolean value found',
37
+ :linenumber => 1,
38
+ :column => 28,
39
+ })
40
+ }
41
+ end
42
+
43
+ describe 'double quoted false' do
44
+ let(:code) { "class { 'foo': boolFlag => \"false\" }" }
45
+
46
+ its(:problems) {
47
+ should have_problem({
48
+ :kind => :warning,
49
+ :message => 'quoted boolean value found',
50
+ :linenumber => 1,
51
+ :column => 28,
52
+ })
53
+ }
54
+ end
55
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'single_quote_string_with_variables' do
4
+ describe 'multiple strings in a line' do
5
+ let(:code) { "\"aoeu\" '${foo}'" }
6
+
7
+ its(:problems) {
8
+ should have_problem({
9
+ :kind => :error,
10
+ :message => 'single quoted string containing a variable found',
11
+ :linenumber => 1,
12
+ :column => 8,
13
+ })
14
+ }
15
+ end
16
+ end