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,20 +1,60 @@
1
1
  require 'spec_helper'
2
2
 
3
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
- }
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
15
55
  end
16
56
 
17
- describe 'string containing only a variable w/fix' do
57
+ context 'with fix enabled' do
18
58
  before do
19
59
  PuppetLint.configuration.fix = true
20
60
  end
@@ -23,17 +63,52 @@ describe 'only_variable_string' do
23
63
  PuppetLint.configuration.fix = false
24
64
  end
25
65
 
26
- let(:code) { '"${foo}"' }
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
27
88
 
28
- its(:problems) {
29
- should only_have_problem({
30
- :kind => :fixed,
31
- :message => 'string containing only a variable',
32
- :linenumber => 1,
33
- :column => 3,
34
- })
35
- }
89
+ it 'should fix the manifest' do
90
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(3)
91
+ end
36
92
 
37
- its(:manifest) { should == "$foo" }
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
38
113
  end
39
114
  end
@@ -0,0 +1,25 @@
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 'puppet:// url without modules' do
15
+ let(:code) { "'puppet:///foo'" }
16
+
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(1)
23
+ end
24
+ end
25
+ end
@@ -1,81 +1,59 @@
1
1
  require 'spec_helper'
2
2
 
3
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
4
+ let(:msg) { 'quoted boolean value found' }
16
5
 
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
6
+ context 'with fix disabled' do
7
+ context 'quoted false' do
8
+ let(:code) { "class { 'foo': boolFlag => 'false' }" }
29
9
 
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
10
+ it 'should only detect a single problem' do
11
+ expect(problems).to have(1).problem
12
+ end
42
13
 
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
14
+ it 'should create a warning' do
15
+ expect(problems).to contain_warning(msg).on_line(1).in_column(28)
16
+ end
17
+ end
55
18
 
56
- describe 'quoted false w/fix' do
57
- before do
58
- PuppetLint.configuration.fix = true
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
59
29
  end
60
30
 
61
- after do
62
- PuppetLint.configuration.fix = false
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
63
41
  end
64
42
 
65
- let(:code) { "class { 'foo': boolFlag => 'false' }" }
66
-
67
- its(:problems) {
68
- should only_have_problem({
69
- :kind => :fixed,
70
- :message => 'quoted boolean value found',
71
- :linenumber => 1,
72
- :column => 28,
73
- })
74
- }
75
- its(:manifest) { should == "class { 'foo': boolFlag => false }" }
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
76
54
  end
77
55
 
78
- describe 'quoted true w/fix' do
56
+ context 'with fix enabled' do
79
57
  before do
80
58
  PuppetLint.configuration.fix = true
81
59
  end
@@ -84,60 +62,68 @@ describe 'quoted_booleans' do
84
62
  PuppetLint.configuration.fix = false
85
63
  end
86
64
 
87
- let(:code) { "class { 'foo': boolFlag => 'true' }" }
88
-
89
- its(:problems) {
90
- should only_have_problem({
91
- :kind => :fixed,
92
- :message => 'quoted boolean value found',
93
- :linenumber => 1,
94
- :column => 28,
95
- })
96
- }
97
- its(:manifest) { should == "class { 'foo': boolFlag => true }" }
98
- end
65
+ context 'quoted false' do
66
+ let(:code) { "class { 'foo': boolFlag => 'false' }" }
99
67
 
100
- describe 'double quoted true w/fix' do
101
- before do
102
- PuppetLint.configuration.fix = true
103
- end
68
+ it 'should only detect a single problem' do
69
+ expect(problems).to have(1).problem
70
+ end
104
71
 
105
- after do
106
- PuppetLint.configuration.fix = false
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
107
79
  end
108
80
 
109
- let(:code) { "class { 'foo': boolFlag => \"true\" }" }
110
-
111
- its(:problems) {
112
- should have_problem({
113
- :kind => :fixed,
114
- :message => 'quoted boolean value found',
115
- :linenumber => 1,
116
- :column => 28,
117
- })
118
- }
119
- its(:manifest) { should == "class { 'foo': boolFlag => true }" }
120
- end
81
+ context 'quoted true' do
82
+ let(:code) { "class { 'foo': boolFlag => 'true' }" }
121
83
 
122
- describe 'double quoted false w/fix' do
123
- before do
124
- PuppetLint.configuration.fix = true
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
125
95
  end
126
96
 
127
- after do
128
- PuppetLint.configuration.fix = false
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
129
111
  end
130
112
 
131
- let(:code) { "class { 'foo': boolFlag => \"false\" }" }
132
-
133
- its(:problems) {
134
- should have_problem({
135
- :kind => :fixed,
136
- :message => 'quoted boolean value found',
137
- :linenumber => 1,
138
- :column => 28,
139
- })
140
- }
141
- its(:manifest) { should == "class { 'foo': boolFlag => false }" }
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
142
128
  end
143
129
  end
@@ -1,16 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'single_quote_string_with_variables' do
4
- describe 'multiple strings in a line' do
4
+ let(:msg) { 'single quoted string containing a variable found' }
5
+
6
+ context 'multiple strings in a line' do
5
7
  let(:code) { "\"aoeu\" '${foo}'" }
6
8
 
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
- }
9
+ it 'should only detect a single problem' do
10
+ expect(problems).to have(1).problem
11
+ end
12
+
13
+ it 'should create an error' do
14
+ expect(problems).to contain_error(msg).on_line(1).in_column(8)
15
+ end
15
16
  end
16
17
  end
@@ -1,55 +1,35 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'variables_not_enclosed' do
4
- describe 'variable not enclosed in {}' do
5
- let(:code) { '" $gronk"' }
6
-
7
- its(:problems) {
8
- should only_have_problem({
9
- :kind => :warning,
10
- :message => 'variable not enclosed in {}',
11
- :linenumber => 1,
12
- :column => 3,
13
- })
14
- }
15
- end
4
+ let(:msg) { 'variable not enclosed in {}' }
16
5
 
17
- describe 'variable not enclosed in {} w/fix' do
18
- before do
19
- PuppetLint.configuration.fix = true
20
- end
6
+ context 'with fix disabled' do
7
+ context 'variable not enclosed in {}' do
8
+ let(:code) { '" $gronk"' }
21
9
 
22
- after do
23
- PuppetLint.configuration.fix = false
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
24
17
  end
25
18
 
26
- let(:code) { '" $gronk"' }
27
-
28
- its(:problems) {
29
- should only_have_problem({
30
- :kind => :fixed,
31
- :message => 'variable not enclosed in {}',
32
- :linenumber => 1,
33
- :column => 3,
34
- })
35
- }
36
- its(:manifest) { should == '" ${gronk}"' }
37
- end
19
+ context 'variable not enclosed in {} after many tokens' do
20
+ let(:code) { ("'groovy'\n" * 20) + '" $gronk"' }
38
21
 
39
- describe 'variable not enclosed in {} after many tokens' do
40
- let(:code) { ("'groovy'\n" * 20) + '" $gronk"' }
41
-
42
- its(:problems) {
43
- should only_have_problem({
44
- :kind => :warning,
45
- :message => 'variable not enclosed in {}',
46
- :linenumber => 21,
47
- :column => 3,
48
- })
49
- }
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(21).in_column(3)
28
+ end
29
+ end
50
30
  end
51
31
 
52
- describe 'variable not enclosed in {} after many tokens w/fix' do
32
+ context 'with fix enabled' do
53
33
  before do
54
34
  PuppetLint.configuration.fix = true
55
35
  end
@@ -58,16 +38,36 @@ describe 'variables_not_enclosed' do
58
38
  PuppetLint.configuration.fix = false
59
39
  end
60
40
 
61
- let(:code) { ("'groovy'\n" * 20) + '" $gronk"' }
62
-
63
- its(:problems) {
64
- should only_have_problem({
65
- :kind => :fixed,
66
- :message => 'variable not enclosed in {}',
67
- :linenumber => 21,
68
- :column => 3,
69
- })
70
- }
71
- its(:manifest) { should == ("'groovy'\n" * 20) + '" ${gronk}"' }
41
+ context 'variable not enclosed in {}' do
42
+ let(:code) { '" $gronk"' }
43
+
44
+ it 'should only detect a single problem' do
45
+ expect(problems).to have(1).problem
46
+ end
47
+
48
+ it 'should fix the manifest' do
49
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(3)
50
+ end
51
+
52
+ it 'should enclose the variable in braces' do
53
+ expect(manifest).to eq('" ${gronk}"')
54
+ end
55
+ end
56
+
57
+ context 'variable not enclosed in {} after many tokens' do
58
+ let(:code) { ("'groovy'\n" * 20) + '" $gronk"' }
59
+
60
+ it 'should only detect a single problem' do
61
+ expect(problems).to have(1).problem
62
+ end
63
+
64
+ it 'should fix the manifest' do
65
+ expect(problems).to contain_fixed(msg).on_line(21).in_column(3)
66
+ end
67
+
68
+ it 'should enclose the variable in braces' do
69
+ expect(manifest).to eq(("'groovy'\n" * 20) + '" ${gronk}"')
70
+ end
71
+ end
72
72
  end
73
73
  end