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,23 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'right_to_left_relationship' do
4
- describe 'chain 2 resources left to right' do
4
+ let(:msg) { 'right-to-left (<-) relationship' }
5
+
6
+ context 'chain 2 resources left to right' do
5
7
  let(:code) { "Class[foo] -> Class[bar]" }
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 'chain 2 resources right to left' do
14
+ context 'chain 2 resources right to left' do
11
15
  let(:code) { "Class[foo] <- Class[bar]" }
12
16
 
13
- its(:problems) {
14
- should have_problem({
15
- :kind => :warning,
16
- :message => "right-to-left (<-) relationship",
17
- :linenumber => 1,
18
- :column => 12,
19
- })
20
- should_not have_problem :kind => :error
21
- }
17
+ it 'should only detect a single problem' do
18
+ expect(problems).to have(1).problem
19
+ end
20
+
21
+ it 'should create a warning' do
22
+ expect(problems).to contain_warning(msg).on_line(1).in_column(12)
23
+ end
22
24
  end
23
25
  end
@@ -1,35 +1,37 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'variable_scope' do
4
- describe 'class with no variables declared accessing top scope' do
4
+ let(:msg) { 'top-scope variable being used without an explicit namespace' }
5
+
6
+ context 'class with no variables declared accessing top scope' do
5
7
  let(:code) { "
6
8
  class foo {
7
9
  $bar = $baz
8
10
  }"
9
11
  }
10
12
 
11
- its(:problems) {
12
- should have_problem({
13
- :kind => :warning,
14
- :message => "top-scope variable being used without an explicit namespace",
15
- :linenumber => 3,
16
- :column => 16,
17
- })
18
- should_not have_problem :kind => :error
19
- }
13
+ it 'should only detect a single problem' do
14
+ expect(problems).to have(1).problem
15
+ end
16
+
17
+ it 'should create a warning' do
18
+ expect(problems).to contain_warning(msg).on_line(3).in_column(16)
19
+ end
20
20
  end
21
21
 
22
- describe 'class with no variables declared accessing top scope explicitly' do
22
+ context 'class with no variables declared accessing top scope explicitly' do
23
23
  let(:code) { "
24
24
  class foo {
25
25
  $bar = $::baz
26
26
  }"
27
27
  }
28
28
 
29
- its(:problems) { should be_empty }
29
+ it 'should not detect any problems' do
30
+ expect(problems).to have(0).problems
31
+ end
30
32
  end
31
33
 
32
- describe 'class with variables declared accessing local scope' do
34
+ context 'class with variables declared accessing local scope' do
33
35
  let(:code) { "
34
36
  class foo {
35
37
  $bar = 1
@@ -37,48 +39,52 @@ describe 'variable_scope' do
37
39
  }"
38
40
  }
39
41
 
40
- its(:problems) { should be_empty }
42
+ it 'should not detect any problems' do
43
+ expect(problems).to have(0).problems
44
+ end
41
45
  end
42
46
 
43
- describe 'class with parameters accessing local scope' do
47
+ context 'class with parameters accessing local scope' do
44
48
  let(:code) { "
45
49
  class foo($bar='UNSET') {
46
50
  $baz = $bar
47
51
  }"
48
52
  }
49
53
 
50
- its(:problems) { should be_empty }
54
+ it 'should not detect any problems' do
55
+ expect(problems).to have(0).problems
56
+ end
51
57
  end
52
58
 
53
- describe 'defined type with no variables declared accessing top scope' do
59
+ context 'defined type with no variables declared accessing top scope' do
54
60
  let(:code) { "
55
61
  define foo() {
56
62
  $bar = $fqdn
57
63
  }"
58
64
  }
59
65
 
60
- its(:problems) {
61
- should have_problem({
62
- :kind => :warning,
63
- :message => "top-scope variable being used without an explicit namespace",
64
- :linenumber => 3,
65
- :column => 16,
66
- })
67
- should_not have_problem :kind => :error
68
- }
66
+ it 'should only detect a single problem' do
67
+ expect(problems).to have(1).problem
68
+ end
69
+
70
+ it 'should create a warning' do
71
+ expect(problems).to contain_warning(msg).on_line(3).in_column(16)
72
+ end
69
73
  end
70
74
 
71
- describe 'defined type with no variables declared accessing top scope explicitly' do
75
+ context 'defined type with no variables declared accessing top scope explicitly' do
72
76
  let(:code) { "
73
77
  define foo() {
74
78
  $bar = $::fqdn
75
79
  }"
76
80
  }
77
81
 
78
- its(:problems) { should be_empty }
82
+ it 'should not detect any problems' do
83
+ expect(problems).to have(0).problems
84
+ end
79
85
  end
80
86
 
81
- describe '$name should be auto defined' do
87
+ context '$name should be auto defined' do
82
88
  let(:code) { "
83
89
  define foo() {
84
90
  $bar = $name
@@ -88,6 +94,44 @@ describe 'variable_scope' do
88
94
  }"
89
95
  }
90
96
 
91
- its(:problems) { should be_empty }
97
+ it 'should not detect any problems' do
98
+ expect(problems).to have(0).problems
99
+ end
100
+ end
101
+
102
+ context 'define with required parameter' do
103
+ let(:code) { "
104
+ define tomcat::base (
105
+ $max_perm_gen,
106
+ $owner = hiera('app_user'),
107
+ $system_properties = {},
108
+ ) { }"
109
+ }
110
+
111
+ it 'should not detect any problems' do
112
+ expect(problems).to have(0).problems
113
+ end
114
+ end
115
+
116
+ context 'future parser blocks' do
117
+ let(:code) { "
118
+ class foo() {
119
+ $foo = [1,2]
120
+ $foo.each |$a, $b| {
121
+ $a
122
+ $c
123
+ }
124
+ $b
125
+ }
126
+ " }
127
+
128
+ it 'should only detect a single problem' do
129
+ expect(problems).to have(2).problem
130
+ end
131
+
132
+ it 'should create two warnings' do
133
+ expect(problems).to contain_warning(msg).on_line(8).in_column(9)
134
+ expect(problems).to contain_warning(msg).on_line(6).in_column(11)
135
+ end
92
136
  end
93
137
  end
@@ -1,20 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'slash_comments' do
4
- describe 'slash comments' do
5
- let(:code) { "// foo" }
6
-
7
- its(:problems) do
8
- should only_have_problem({
9
- :kind => :warning,
10
- :message => '// comment found',
11
- :linenumber => 1,
12
- :column => 1,
13
- })
4
+ let(:msg) { '// comment found' }
5
+
6
+ context 'with fix disabled' do
7
+ context 'slash comments' 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(1)
16
+ end
14
17
  end
15
18
  end
16
19
 
17
- describe 'slash comments w/fix' do
20
+ context 'with fix enabled' do
18
21
  before do
19
22
  PuppetLint.configuration.fix = true
20
23
  end
@@ -23,16 +26,20 @@ describe 'slash_comments' do
23
26
  PuppetLint.configuration.fix = false
24
27
  end
25
28
 
26
- let(:code) { '// foo' }
29
+ context 'slash comments' do
30
+ let(:code) { '// foo' }
31
+
32
+ it 'should only detect a single problem' do
33
+ expect(problems).to have(1).problem
34
+ end
35
+
36
+ it 'should fix the manifest' do
37
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
38
+ end
27
39
 
28
- its(:problems) do
29
- should only_have_problem({
30
- :kind => :fixed,
31
- :message => '// comment found',
32
- :linenumber => 1,
33
- :column => 1,
34
- })
40
+ it 'should replace the double slash with a hash' do
41
+ expect(manifest).to eq("# foo")
42
+ end
35
43
  end
36
- its(:manifest) { should == '# foo' }
37
44
  end
38
45
  end
@@ -1,19 +1,84 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'star_comments' do
4
- describe 'slash asterisk comment' do
5
- let(:code) { "
6
- /* foo
7
- */
8
- "}
9
-
10
- its(:problems) do
11
- should only_have_problem({
12
- :kind => :warning,
13
- :message => '/* */ comment found',
14
- :linenumber => 2,
15
- :column => 7,
16
- })
4
+ let(:msg) { '/* */ comment found' }
5
+
6
+ context 'with fix disabled' do
7
+ context 'multiline comment w/ one line of content' do
8
+ let(:code) { "
9
+ /* foo
10
+ */
11
+ "}
12
+
13
+ it 'should only detect a single problem' do
14
+ expect(problems).to have(1).problem
15
+ end
16
+
17
+ it 'should create a warning' do
18
+ expect(problems).to contain_warning(msg).on_line(2).in_column(9)
19
+ end
20
+ end
21
+ end
22
+
23
+ context 'with fix enabled' do
24
+ before do
25
+ PuppetLint.configuration.fix = true
26
+ end
27
+
28
+ after do
29
+ PuppetLint.configuration.fix = false
30
+ end
31
+
32
+ context 'multiline comment w/ one line of content' do
33
+ let(:code) { "
34
+ /* foo
35
+ */
36
+ "}
37
+
38
+ let(:fixed) { "
39
+ # foo
40
+ "}
41
+
42
+ it 'should only detect a single problem' do
43
+ expect(problems).to have(1).problem
44
+ end
45
+
46
+ it 'should create a warning' do
47
+ expect(problems).to contain_fixed(msg).on_line(2).in_column(9)
48
+ end
49
+
50
+ it 'should convert the multiline comment' do
51
+ expect(manifest).to eq(fixed)
52
+ end
53
+ end
54
+
55
+ context 'multiline comment w/ multiple line of content' do
56
+ let(:code) { "
57
+ /* foo
58
+ * bar
59
+ * baz
60
+ */
61
+ notify { 'foo': }
62
+ "}
63
+
64
+ let(:fixed) { "
65
+ # foo
66
+ # bar
67
+ # baz
68
+ notify { 'foo': }
69
+ "}
70
+
71
+ it 'should only detect a single problem' do
72
+ expect(problems).to have(1).problem
73
+ end
74
+
75
+ it 'should create a warning' do
76
+ expect(problems).to contain_fixed(msg).on_line(2).in_column(9)
77
+ end
78
+
79
+ it 'should convert the multiline comment' do
80
+ expect(manifest).to eq(fixed)
81
+ end
17
82
  end
18
83
  end
19
84
  end
@@ -1,7 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'case_without_default' do
4
- describe 'case statement with a default case' do
4
+ let(:msg) { 'case statement without a default case' }
5
+
6
+ context 'case statement with a default case' do
5
7
  let(:code) { "
6
8
  case $foo {
7
9
  bar: { }
@@ -9,10 +11,12 @@ describe 'case_without_default' do
9
11
  }"
10
12
  }
11
13
 
12
- its(:problems) { should be_empty }
14
+ it 'should not detect any problems' do
15
+ expect(problems).to have(0).problems
16
+ end
13
17
  end
14
18
 
15
- describe 'case statement without a default case' do
19
+ context 'case statement without a default case' do
16
20
  let(:code) { "
17
21
  case $foo {
18
22
  bar: { }
@@ -20,17 +24,16 @@ describe 'case_without_default' do
20
24
  }"
21
25
  }
22
26
 
23
- its(:problems) do
24
- should only_have_problem({
25
- :kind => :warning,
26
- :message => 'case statement without a default case',
27
- :linenumber => 2,
28
- :column => 7,
29
- })
27
+ it 'should only detect a single problem' do
28
+ expect(problems).to have(1).problem
29
+ end
30
+
31
+ it 'should create a warning' do
32
+ expect(problems).to contain_warning(msg).on_line(2).in_column(7)
30
33
  end
31
34
  end
32
35
 
33
- describe 'issue-117' do
36
+ context 'issue-117' do
34
37
  let(:code) { "
35
38
  $mem = inline_template('<%
36
39
  mem,unit = scope.lookupvar(\'::memorysize\').split
@@ -46,6 +49,8 @@ describe 'case_without_default' do
46
49
  %><%= mem.to_i %>')
47
50
  "}
48
51
 
49
- its(:problems) { should == [] }
52
+ it 'should not detect any problems' do
53
+ expect(problems).to have(0).problems
54
+ end
50
55
  end
51
56
  end
@@ -1,7 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'selector_inside_resource' do
4
- describe 'resource with a selector' do
4
+ let(:msg) { 'selector inside resource block' }
5
+
6
+ context 'resource with a selector' do
5
7
  let(:code) { "
6
8
  file { 'foo':
7
9
  ensure => $bar ? {
@@ -11,23 +13,24 @@ describe 'selector_inside_resource' do
11
13
  }"
12
14
  }
13
15
 
14
- its(:problems) do
15
- should only_have_problem({
16
- :kind => :warning,
17
- :message => 'selector inside resource block',
18
- :linenumber => 3,
19
- :column => 16,
20
- })
16
+ it 'should only detect a single problem' do
17
+ expect(problems).to have(1).problem
18
+ end
19
+
20
+ it 'should create a warning' do
21
+ expect(problems).to contain_warning(msg).on_line(3).in_column(16)
21
22
  end
22
23
  end
23
24
 
24
- describe 'resource with a variable as a attr value' do
25
+ context 'resource with a variable as a attr value' do
25
26
  let(:code) { "
26
27
  file { 'foo',
27
28
  ensure => $bar,
28
29
  }"
29
30
  }
30
31
 
31
- its(:problems) { should be_empty }
32
+ it 'should not detect any problems' do
33
+ expect(problems).to have(0).problems
34
+ end
32
35
  end
33
36
  end