puppet-lint 0.4.0.pre1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/.travis.yml +3 -4
  2. data/Gemfile +2 -5
  3. data/README.md +2 -149
  4. data/Rakefile +0 -5
  5. data/lib/puppet-lint.rb +74 -20
  6. data/lib/puppet-lint/bin.rb +20 -85
  7. data/lib/puppet-lint/checkplugin.rb +158 -12
  8. data/lib/puppet-lint/checks.rb +39 -222
  9. data/lib/puppet-lint/configuration.rb +12 -31
  10. data/lib/puppet-lint/data.rb +329 -0
  11. data/lib/puppet-lint/lexer.rb +37 -30
  12. data/lib/puppet-lint/lexer/token.rb +14 -16
  13. data/lib/puppet-lint/monkeypatches/string_prepend.rb +6 -0
  14. data/lib/puppet-lint/optparser.rb +105 -0
  15. data/lib/puppet-lint/plugins.rb +28 -9
  16. data/lib/puppet-lint/plugins/check_classes.rb +162 -238
  17. data/lib/puppet-lint/plugins/check_comments.rb +40 -25
  18. data/lib/puppet-lint/plugins/check_conditionals.rb +16 -20
  19. data/lib/puppet-lint/plugins/check_documentation.rb +14 -20
  20. data/lib/puppet-lint/plugins/check_nodes.rb +23 -0
  21. data/lib/puppet-lint/plugins/check_resources.rb +127 -141
  22. data/lib/puppet-lint/plugins/check_strings.rb +133 -107
  23. data/lib/puppet-lint/plugins/check_variables.rb +11 -11
  24. data/lib/puppet-lint/plugins/check_whitespace.rb +86 -92
  25. data/lib/puppet-lint/tasks/puppet-lint.rb +17 -1
  26. data/lib/puppet-lint/version.rb +1 -1
  27. data/puppet-lint.gemspec +4 -2
  28. data/spec/fixtures/test/manifests/ignore.pp +1 -0
  29. data/spec/fixtures/test/manifests/ignore_reason.pp +1 -0
  30. data/spec/puppet-lint/bin_spec.rb +104 -84
  31. data/spec/puppet-lint/configuration_spec.rb +19 -19
  32. data/spec/puppet-lint/ignore_overrides_spec.rb +97 -0
  33. data/spec/puppet-lint/lexer/token_spec.rb +9 -9
  34. data/spec/puppet-lint/lexer_spec.rb +352 -325
  35. data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +77 -23
  36. data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +14 -12
  37. data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +18 -14
  38. data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +30 -30
  39. data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +31 -26
  40. data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +34 -28
  41. data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +14 -12
  42. data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +74 -30
  43. data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +27 -20
  44. data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +78 -13
  45. data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +17 -12
  46. data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +13 -10
  47. data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +21 -16
  48. data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +69 -0
  49. data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +42 -38
  50. data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +22 -10
  51. data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +81 -18
  52. data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +69 -112
  53. data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +27 -20
  54. data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +177 -171
  55. data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +165 -88
  56. data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +97 -22
  57. data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +25 -0
  58. data/spec/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +97 -111
  59. data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +10 -9
  60. data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +53 -53
  61. data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +26 -14
  62. data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +10 -9
  63. data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +31 -15
  64. data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +340 -322
  65. data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +30 -23
  66. data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +42 -41
  67. data/spec/puppet-lint_spec.rb +3 -3
  68. data/spec/spec_helper.rb +109 -116
  69. metadata +109 -50
  70. data/spec/puppet-lint/plugins/check_classes/class_parameter_defaults_spec.rb +0 -60
@@ -1,42 +1,48 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'autoloader_layout' do
4
- describe 'foo::bar in foo/manifests/bar.pp' do
4
+ context 'foo::bar in foo/manifests/bar.pp' do
5
5
  let(:code) { "class foo::bar { }" }
6
- let(:fullpath) { '/etc/puppet/modules/foo/manifests/bar.pp' }
6
+ let(:path) { 'foo/manifests/bar.pp' }
7
7
 
8
- its(:problems) { should be_empty }
8
+ it 'should not detect any problems' do
9
+ expect(problems).to have(0).problems
10
+ end
9
11
  end
10
12
 
11
- describe 'foo::bar::baz in foo/manifests/bar/baz.pp' do
13
+ context 'foo::bar::baz in foo/manifests/bar/baz.pp' do
12
14
  let(:code) { 'define foo::bar::baz() { }' }
13
- let(:fullpath) { '/etc/puppet/modules/foo/manifests/bar/baz.pp' }
15
+ let(:path) { 'foo/manifests/bar/baz.pp' }
14
16
 
15
- its(:problems) { should be_empty }
17
+ it 'should not detect any problems' do
18
+ expect(problems).to have(0).problems
19
+ end
16
20
  end
17
21
 
18
- describe 'foo in foo/manifests/init.pp' do
22
+ context 'foo in foo/manifests/init.pp' do
19
23
  let(:code) { 'class foo { }' }
20
- let(:fullpath) { '/etc/puppet/modules/foo/manifests/init.pp' }
24
+ let(:path) { 'foo/manifests/init.pp' }
21
25
 
22
- its(:problems) { should be_empty }
26
+ it 'should not detect any problems' do
27
+ expect(problems).to have(0).problems
28
+ end
23
29
  end
24
30
 
25
- describe 'foo::bar in foo/manifests/init.pp' do
31
+ context 'foo::bar in foo/manifests/init.pp' do
26
32
  let(:code) { 'class foo::bar { }' }
27
- let(:fullpath) { '/etc/puppet/modules/foo/manifests/init.pp' }
28
-
29
- its(:problems) {
30
- should only_have_problem({
31
- :kind => :error,
32
- :message => "foo::bar not in autoload module layout",
33
- :linenumber => 1,
34
- :column => 7,
35
- })
36
- }
33
+ let(:path) { 'foo/manifests/init.pp' }
34
+ let(:msg) { 'foo::bar not in autoload module layout' }
35
+
36
+ it 'should only detect a single problem' do
37
+ expect(problems).to have(1).problem
38
+ end
39
+
40
+ it 'should create an error' do
41
+ expect(problems).to contain_error(msg).on_line(1).in_column(7)
42
+ end
37
43
  end
38
44
 
39
- describe 'foo included in bar/manifests/init.pp' do
45
+ context 'foo included in bar/manifests/init.pp' do
40
46
  let(:code) { "
41
47
  class bar {
42
48
  class {'foo':
@@ -45,7 +51,55 @@ describe 'autoloader_layout' do
45
51
  }
46
52
  "
47
53
  }
48
- let(:fullpath) { '/etc/puppet/modules/bar/manifests/init.pp' }
49
- its(:problems) { should be_empty }
54
+ let(:path) { 'bar/manifests/init.pp' }
55
+
56
+ it 'should not detect any problems' do
57
+ expect(problems).to have(0).problems
58
+ end
59
+ end
60
+
61
+ context 'foo in puppet-foo/manifests/init.pp' do
62
+ let(:code) { 'class foo { }' }
63
+ let(:path) { 'puppet-foo/manifests/init.pp' }
64
+
65
+ it 'should detect a single problem' do
66
+ expect(problems).to have(1).problems
67
+ end
68
+ end
69
+
70
+ context 'foo in puppet-foo/manifests/bar.pp with relative option' do
71
+ before do
72
+ PuppetLint.configuration.relative = true
73
+ end
74
+
75
+ after do
76
+ PuppetLint.configuration.relative = false
77
+ end
78
+
79
+ let(:code) { 'class foo { }' }
80
+ let(:path) { 'puppet-foo/manifests/bar.pp' }
81
+
82
+ it 'should detect a single problem' do
83
+ expect(problems).to have(1).problems
84
+ end
50
85
  end
86
+
87
+ context 'foo in puppet-foo/manifests/init.pp with relative option' do
88
+ before do
89
+ PuppetLint.configuration.relative = true
90
+ end
91
+
92
+ after do
93
+ PuppetLint.configuration.relative = false
94
+ end
95
+
96
+ let(:code) { 'class foo { }' }
97
+ let(:path) { 'puppet-foo/manifests/init.pp' }
98
+
99
+ it 'should not detect any problems' do
100
+ expect(problems).to have(0).problems
101
+ end
102
+ end
103
+
104
+
51
105
  end
@@ -1,24 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'class_inherits_from_params_class' do
4
- describe 'parameterised class that inherits from a params class' do
4
+ let(:msg) { 'class inheriting from params class' }
5
+
6
+ context 'parameterised class that inherits from a params class' do
5
7
  let(:code) { "
6
8
  # commented
7
9
  class foo($bar = $name) inherits foo::params { }"
8
10
  }
9
11
 
10
- its(:problems) {
11
- should have_problem({
12
- :kind => :warning,
13
- :message => "class inheriting from params class",
14
- :linenumber => 3,
15
- :column => 40,
16
- })
17
- should_not have_problem :kind => :error
18
- }
12
+ it 'should only detect a single problem' do
13
+ expect(problems).to have(1).problem
14
+ end
15
+
16
+ it 'should create a warning' do
17
+ expect(problems).to contain_warning(msg).on_line(3).in_column(40)
18
+ end
19
19
  end
20
20
 
21
- describe 'class without parameters' do
21
+ context 'class without parameters' do
22
22
  let(:code) {"
23
23
  class myclass {
24
24
 
@@ -28,6 +28,8 @@ describe 'class_inherits_from_params_class' do
28
28
  }
29
29
  "}
30
30
 
31
- its(:problems) { should == [] }
31
+ it 'should not detect any problems' do
32
+ expect(problems).to have(0).problems
33
+ end
32
34
  end
33
35
  end
@@ -1,29 +1,33 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'inherits_across_namespaces' do
4
- describe 'class inheriting from parent in same module namespace' do
4
+ let(:msg) { 'class inherits across module namespaces' }
5
+
6
+ context 'class inheriting from parent in same module namespace' do
5
7
  let(:code) { "class foo::bar inherits foo { }" }
6
8
 
7
- its(:problems) { should be_empty }
9
+ it 'should not detect any problems' do
10
+ expect(problems).to have(0).problems
11
+ end
8
12
  end
9
13
 
10
- describe 'class inheriting from sister in same module namespace' do
14
+ context 'class inheriting from sister in same module namespace' do
11
15
  let(:code) { "class foo::bar inherits foo::baz { }" }
12
16
 
13
- its(:problems) { should be_empty }
17
+ it 'should not detect any problems' do
18
+ expect(problems).to have(0).problems
19
+ end
14
20
  end
15
21
 
16
- describe 'class inheriting from another module namespace' do
22
+ context 'class inheriting from another module namespace' do
17
23
  let(:code) { "class foo::bar inherits baz { }" }
18
24
 
19
- its(:problems) {
20
- should have_problem({
21
- :kind => :warning,
22
- :message => "class inherits across module namespaces",
23
- :linenumber => 1,
24
- :column => 25,
25
- })
26
- should_not have_problem :kind => :error
27
- }
25
+ it 'should only detect a single problem' do
26
+ expect(problems).to have(1).problem
27
+ end
28
+
29
+ it 'should create a warning' do
30
+ expect(problems).to contain_warning(msg).on_line(1).in_column(25)
31
+ end
28
32
  end
29
33
  end
@@ -1,45 +1,45 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'names_containing_dash' do
4
- describe 'module named foo-bar' do
4
+ let(:class_msg) { 'class name containing a dash' }
5
+ let(:define_msg) { 'defined type name containing a dash' }
6
+
7
+ context 'module named foo-bar' do
5
8
  let(:code) { 'class foo-bar { }' }
6
- let(:fullpath) { '/etc/puppet/modules/foo-bar/manifests/init.pp' }
7
-
8
- its(:problems) do
9
- should only_have_problem({
10
- :kind => :warning,
11
- :message => 'class name containing a dash',
12
- :linenumber => 1,
13
- :column => 7,
14
- })
9
+ let(:path) { 'foo-bar/manifests/init.pp' }
10
+
11
+ it 'should only detect a single problem' do
12
+ expect(problems).to have(1).problem
13
+ end
14
+
15
+ it 'should create a warning' do
16
+ expect(problems).to contain_warning(class_msg).on_line(1).in_column(7)
15
17
  end
16
18
  end
17
19
 
18
- describe 'define named foo-bar' do
20
+ context 'define named foo-bar' do
19
21
  let(:code) { 'define foo::foo-bar { }' }
20
- let(:fullpath) { '/etc/puppet/modules/foo/manifests/foo-bar.pp' }
21
-
22
- its(:problems) do
23
- should only_have_problem({
24
- :kind => :warning,
25
- :message => 'defined type name containing a dash',
26
- :linenumber => 1,
27
- :column => 8,
28
- })
22
+ let(:path) { 'foo/manifests/foo-bar.pp' }
23
+
24
+ it 'should only detect a single problem' do
25
+ expect(problems).to have(1).problem
26
+ end
27
+
28
+ it 'should create a warning' do
29
+ expect(problems).to contain_warning(define_msg).on_line(1).in_column(8)
29
30
  end
30
31
  end
31
32
 
32
- describe 'class named bar-foo' do
33
+ context 'class named bar-foo' do
33
34
  let(:code) { 'class foo::bar-foo { }' }
34
- let(:fullpath) { '/etc/puppet/modules/foo/manifests/bar-foo.pp' }
35
-
36
- its(:problems) do
37
- should only_have_problem({
38
- :kind => :warning,
39
- :message => 'class name containing a dash',
40
- :linenumber => 1,
41
- :column => 7,
42
- })
35
+ let(:path) { 'foo/manifests/bar-foo.pp' }
36
+
37
+ it 'should only detect a single problem' do
38
+ expect(problems).to have(1).problem
39
+ end
40
+
41
+ it 'should create a warning' do
42
+ expect(problems).to contain_warning(class_msg).on_line(1).in_column(7)
43
43
  end
44
44
  end
45
45
  end
@@ -1,13 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'nested_classes_or_defines' do
4
- describe 'class on its own' do
4
+ let(:class_msg) { 'class defined inside a class' }
5
+ let(:define_msg) { 'defined type defined inside a class' }
6
+
7
+ context 'class on its own' do
5
8
  let(:code) { "class foo { }" }
6
9
 
7
- its(:problems) { should be_empty }
10
+ it 'should not detect any problems' do
11
+ expect(problems).to have(0).problems
12
+ end
8
13
  end
9
14
 
10
- describe 'class inside a class' do
15
+ context 'class inside a class' do
11
16
  let(:code) { "
12
17
  class foo {
13
18
  class bar {
@@ -15,18 +20,16 @@ describe 'nested_classes_or_defines' do
15
20
  }"
16
21
  }
17
22
 
18
- its(:problems) {
19
- should have_problem({
20
- :kind => :warning,
21
- :message => "class defined inside a class",
22
- :linenumber => 3,
23
- :column => 9,
24
- })
25
- should_not have_problem :kind => :error
26
- }
23
+ it 'should only detect a single problem' do
24
+ expect(problems).to have(1).problem
25
+ end
26
+
27
+ it 'should create a warning' do
28
+ expect(problems).to contain_warning(class_msg).on_line(3).in_column(9)
29
+ end
27
30
  end
28
31
 
29
- describe 'instantiating a parametised class inside a class' do
32
+ context 'instantiating a parametised class inside a class' do
30
33
  let(:code) { "
31
34
  class bar {
32
35
  class { 'foo':
@@ -35,10 +38,12 @@ describe 'nested_classes_or_defines' do
35
38
  }"
36
39
  }
37
40
 
38
- its(:problems) { should be_empty }
41
+ it 'should not detect any problems' do
42
+ expect(problems).to have(0).problems
43
+ end
39
44
  end
40
45
 
41
- describe 'instantiating a parametised class inside a define' do
46
+ context 'instantiating a parametised class inside a define' do
42
47
  let(:code) { "
43
48
  define bar() {
44
49
  class { 'foo':
@@ -47,10 +52,12 @@ describe 'nested_classes_or_defines' do
47
52
  }"
48
53
  }
49
54
 
50
- its(:problems) { should be_empty }
55
+ it 'should not detect any problems' do
56
+ expect(problems).to have(0).problems
57
+ end
51
58
  end
52
59
 
53
- describe 'define inside a class' do
60
+ context 'define inside a class' do
54
61
  let(:code) { "
55
62
  class foo {
56
63
  define bar() {
@@ -58,14 +65,12 @@ describe 'nested_classes_or_defines' do
58
65
  }"
59
66
  }
60
67
 
61
- its(:problems) {
62
- should have_problem({
63
- :kind => :warning,
64
- :message => "define defined inside a class",
65
- :linenumber => 3,
66
- :column => 9,
67
- })
68
- should_not have_problem :kind => :error
69
- }
68
+ it 'should only detect a single problem' do
69
+ expect(problems).to have(1).problems
70
+ end
71
+
72
+ it 'should create a warning' do
73
+ expect(problems).to contain_warning(define_msg).on_line(3).in_column(9)
74
+ end
70
75
  end
71
76
  end
@@ -1,59 +1,63 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'parameter_order' do
4
- describe 'define with attrs in order' do
4
+ let(:msg) { 'optional parameter listed before required parameter' }
5
+
6
+ context 'define with attrs in order' do
5
7
  let(:code) { "define foo($bar, $baz='gronk') { }" }
6
8
 
7
- its(:problems) { should be_empty }
9
+ it 'should not detect any problems' do
10
+ expect(problems).to have(0).problems
11
+ end
8
12
  end
9
13
 
10
- describe 'define with parameter that calls a function' do
14
+ context 'define with parameter that calls a function' do
11
15
  let(:code) { "define foo($bar=extlookup($name)) {}" }
12
16
 
13
- its(:problems) { should == [] }
17
+ it 'should not detect any problems' do
18
+ expect(problems).to have(0).problems
19
+ end
14
20
  end
15
21
 
16
- describe 'define with attrs out of order' do
22
+ context 'define with attrs out of order' do
17
23
  let(:code) { "define foo($bar='baz', $gronk) { }" }
18
24
 
19
- its(:problems) {
20
- should have_problem({
21
- :kind => :warning,
22
- :message => "optional parameter listed before required parameter",
23
- :linenumber => 1,
24
- :column => 24,
25
- })
26
- should_not have_problem :kind => :error
27
- }
25
+ it 'should only detect a single problem' do
26
+ expect(problems).to have(1).problem
27
+ end
28
+
29
+ it 'should create a warning' do
30
+ expect(problems).to contain_warning(msg).on_line(1).in_column(24)
31
+ end
28
32
  end
29
33
 
30
- describe 'class/define parameter set to another variable' do
34
+ context 'class/define parameter set to another variable' do
31
35
  let(:code) { "
32
36
  define foo($bar, $baz = $name, $gronk=$::fqdn) {
33
37
  }"
34
38
  }
35
39
 
36
- its(:problems) { should be_empty }
40
+ it 'should not detect any problems' do
41
+ expect(problems).to have(0).problems
42
+ end
37
43
  end
38
44
 
39
- describe 'class/define parameter set to another variable with incorrect order' do
45
+ context 'class/define parameter set to another variable with incorrect order' do
40
46
  let(:code) { "
41
47
  define foo($baz = $name, $bar, $gronk=$::fqdn) {
42
48
  }"
43
49
  }
44
50
 
45
- its(:problems) {
46
- should have_problem({
47
- :kind => :warning,
48
- :message => "optional parameter listed before required parameter",
49
- :linenumber => 2,
50
- :column => 32,
51
- })
52
- should_not have_problem :kind => :error
53
- }
51
+ it 'should only detect a single problem' do
52
+ expect(problems).to have(1).problem
53
+ end
54
+
55
+ it 'should create a warning' do
56
+ expect(problems).to contain_warning(msg).on_line(2).in_column(32)
57
+ end
54
58
  end
55
59
 
56
- describe 'issue-101' do
60
+ context 'issue-101' do
57
61
  let(:code) { "
58
62
  define b (
59
63
  $foo,
@@ -62,6 +66,8 @@ describe 'parameter_order' do
62
66
  ) { }
63
67
  " }
64
68
 
65
- its(:problems) { should == [] }
69
+ it 'should not detect any problems' do
70
+ expect(problems).to have(0).problems
71
+ end
66
72
  end
67
73
  end