puppet-lint 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +74 -0
  3. data/.rubocop_todo.yml +89 -0
  4. data/.travis.yml +11 -9
  5. data/CHANGELOG.md +54 -0
  6. data/Gemfile +3 -0
  7. data/Rakefile +14 -3
  8. data/appveyor.yml +1 -4
  9. data/bin/puppet-lint +1 -1
  10. data/lib/puppet-lint.rb +25 -21
  11. data/lib/puppet-lint/bin.rb +15 -19
  12. data/lib/puppet-lint/checkplugin.rb +24 -17
  13. data/lib/puppet-lint/checks.rb +42 -31
  14. data/lib/puppet-lint/configuration.rb +11 -8
  15. data/lib/puppet-lint/data.rb +236 -164
  16. data/lib/puppet-lint/lexer.rb +225 -203
  17. data/lib/puppet-lint/lexer/token.rb +34 -18
  18. data/lib/puppet-lint/optparser.rb +33 -30
  19. data/lib/puppet-lint/plugins.rb +42 -38
  20. data/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +26 -28
  21. data/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +21 -20
  22. data/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +8 -9
  23. data/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb +9 -8
  24. data/lib/puppet-lint/plugins/check_classes/inherits_across_namespaces.rb +12 -11
  25. data/lib/puppet-lint/plugins/check_classes/names_containing_dash.rb +13 -12
  26. data/lib/puppet-lint/plugins/check_classes/names_containing_uppercase.rb +14 -13
  27. data/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +9 -10
  28. data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +40 -31
  29. data/lib/puppet-lint/plugins/check_classes/right_to_left_relationship.rb +3 -2
  30. data/lib/puppet-lint/plugins/check_classes/variable_scope.rb +21 -24
  31. data/lib/puppet-lint/plugins/check_comments/slash_comments.rb +3 -2
  32. data/lib/puppet-lint/plugins/check_comments/star_comments.rb +6 -5
  33. data/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb +21 -20
  34. data/lib/puppet-lint/plugins/check_conditionals/selector_inside_resource.rb +10 -13
  35. data/lib/puppet-lint/plugins/check_documentation/documentation.rb +26 -17
  36. data/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb +11 -11
  37. data/lib/puppet-lint/plugins/check_resources/duplicate_params.rb +4 -3
  38. data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +17 -18
  39. data/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +17 -16
  40. data/lib/puppet-lint/plugins/check_resources/file_mode.rb +22 -23
  41. data/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +14 -13
  42. data/lib/puppet-lint/plugins/check_resources/unquoted_resource_title.rb +9 -8
  43. data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +8 -8
  44. data/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +29 -42
  45. data/lib/puppet-lint/plugins/check_strings/puppet_url_without_modules.rb +5 -4
  46. data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +3 -2
  47. data/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +4 -3
  48. data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +3 -2
  49. data/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +9 -8
  50. data/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb +9 -8
  51. data/lib/puppet-lint/plugins/check_whitespace/140chars.rb +9 -9
  52. data/lib/puppet-lint/plugins/check_whitespace/2sp_soft_tabs.rb +4 -3
  53. data/lib/puppet-lint/plugins/check_whitespace/80chars.rb +10 -10
  54. data/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +23 -22
  55. data/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +3 -2
  56. data/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb +3 -2
  57. data/lib/puppet-lint/tasks/puppet-lint.rb +3 -3
  58. data/lib/puppet-lint/version.rb +1 -1
  59. data/puppet-lint.gemspec +4 -4
  60. data/spec/puppet-lint/bin_spec.rb +268 -140
  61. data/spec/puppet-lint/checks_spec.rb +229 -0
  62. data/spec/puppet-lint/configuration_spec.rb +10 -9
  63. data/spec/puppet-lint/data_spec.rb +84 -0
  64. data/spec/puppet-lint/ignore_overrides_spec.rb +71 -40
  65. data/spec/puppet-lint/lexer/token_spec.rb +1 -1
  66. data/spec/puppet-lint/lexer_spec.rb +306 -73
  67. data/spec/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb +12 -6
  68. data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +10 -10
  69. data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +15 -11
  70. data/spec/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb +26 -21
  71. data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +3 -3
  72. data/spec/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb +4 -5
  73. data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +13 -0
  74. data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +33 -25
  75. data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +80 -55
  76. data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +2 -2
  77. data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +165 -130
  78. data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +2 -2
  79. data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +53 -35
  80. data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +59 -49
  81. data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +18 -14
  82. data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +14 -10
  83. data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +7 -7
  84. data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +54 -44
  85. data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +114 -89
  86. data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +41 -30
  87. data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +46 -40
  88. data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +46 -40
  89. data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +95 -71
  90. data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +28 -24
  91. data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +11 -9
  92. data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +1 -2
  93. data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +18 -14
  94. data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +1 -1
  95. data/spec/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb +1 -1
  96. data/spec/puppet-lint/plugins/check_whitespace/140chars_spec.rb +22 -15
  97. data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +8 -6
  98. data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +23 -29
  99. data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +588 -494
  100. data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +1 -1
  101. data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +27 -19
  102. data/spec/puppet-lint_spec.rb +2 -12
  103. data/spec/spec_helper.rb +35 -30
  104. metadata +6 -5
  105. data/lib/puppet-lint/monkeypatches.rb +0 -2
  106. data/lib/puppet-lint/monkeypatches/string_percent.rb +0 -52
  107. data/lib/puppet-lint/monkeypatches/string_prepend.rb +0 -13
@@ -41,7 +41,7 @@ describe 'double_quoted_strings' do
41
41
  end
42
42
 
43
43
  context 'double quoted string containing newline but no variables' do
44
- let(:code) { %{"foo\n"} }
44
+ let(:code) { %("foo\n") }
45
45
 
46
46
  it 'should not detect any problems' do
47
47
  expect(problems).to have(0).problems
@@ -49,18 +49,20 @@ describe 'double_quoted_strings' do
49
49
  end
50
50
 
51
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',
52
+ let(:code) do
53
+ <<-END
54
+ class puppet::master::maintenance (
55
+ ) {
56
+ cron { 'puppet_master_reports_cleanup':
57
+ command => "/usr/bin/find /var/lib/puppet/reports -type f -mtime +15 \
58
+ -delete && /usr/bin/find /var/lib/puppet/reports -mindepth 1 \
59
+ -empty -type d -delete",
60
+ minute => '15',
61
+ hour => '5',
62
+ }
61
63
  }
62
- }
63
- } }
64
+ END
65
+ end
64
66
 
65
67
  it 'should not detect any problems' do
66
68
  expect(problems).to have(0).problems
@@ -92,15 +94,17 @@ describe 'double_quoted_strings' do
92
94
  end
93
95
 
94
96
  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
- $string7 = "this string contains \\\\ an escaped backslash"
103
- }}
97
+ let(:code) do
98
+ <<-END
99
+ $string1 = "this string contins \n newline"
100
+ $string2 = "this string contains \ttab"
101
+ $string3 = "this string contains \${escaped} var"
102
+ $string4 = "this string contains \\"escaped \\" double quotes"
103
+ $string5 = "this string contains \\'escaped \\' single quotes"
104
+ $string6 = "this string contains \r line return"
105
+ $string7 = "this string contains \\\\ an escaped backslash"
106
+ END
107
+ end
104
108
 
105
109
  it 'should not detect any problems' do
106
110
  expect(problems).to have(0).problems
@@ -108,7 +112,7 @@ describe 'double_quoted_strings' do
108
112
  end
109
113
 
110
114
  context 'double quoted string with random escape should be rejected' do
111
- let(:code) {%{ $ztring = "this string contains \l random esape" } }
115
+ let(:code) { %( $ztring = "this string contains \l random esape" ) }
112
116
 
113
117
  it 'should only detect a single problem' do
114
118
  expect(problems).to have(1).problem
@@ -128,7 +132,7 @@ describe 'double_quoted_strings' do
128
132
  end
129
133
 
130
134
  context 'double quoted string containing single quoted string' do
131
- let(:code) { %[notify { "'foo'": }] }
135
+ let(:code) { %(notify { "'foo'": }) }
132
136
 
133
137
  it 'should not detect any problems' do
134
138
  expect(problems).to have(0).problems
@@ -158,7 +162,7 @@ describe 'double_quoted_strings' do
158
162
  end
159
163
 
160
164
  context 'double quoted string containing a lone dollar' do
161
- let(:code) {"\"sed -i 's/^;*[[:space:]]*${name}[[:space:]]*=.*$/${name} = ${value}/g' file\"" }
165
+ let(:code) { "\"sed -i 's/^;*[[:space:]]*${name}[[:space:]]*=.*$/${name} = ${value}/g' file\"" }
162
166
 
163
167
  it 'should not detect any problems' do
164
168
  expect(problems).to have(0).problems
@@ -41,12 +41,14 @@ describe 'only_variable_string' do
41
41
  end
42
42
 
43
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
- }
44
+ let(:code) do
45
+ <<-END
46
+ $bar = 'key'
47
+ $foo = {
48
+ \"$bar\" => 1,
49
+ }
50
+ END
51
+ end
50
52
 
51
53
  it 'should not detect any problems' do
52
54
  expect(problems).to be_empty
@@ -75,7 +77,7 @@ describe 'only_variable_string' do
75
77
  end
76
78
 
77
79
  it 'should unquote the variable' do
78
- expect(manifest).to eq("$foo")
80
+ expect(manifest).to eq('$foo')
79
81
  end
80
82
  end
81
83
 
@@ -91,7 +93,7 @@ describe 'only_variable_string' do
91
93
  end
92
94
 
93
95
  it 'should unquoted the variable' do
94
- expect(manifest).to eq("$foo[0]")
96
+ expect(manifest).to eq('$foo[0]')
95
97
  end
96
98
  end
97
99
 
@@ -107,7 +109,7 @@ describe 'only_variable_string' do
107
109
  end
108
110
 
109
111
  it 'should unquote the variable' do
110
- expect(manifest).to eq("$foo[0][aoeuaoeu][bar][999]")
112
+ expect(manifest).to eq('$foo[0][aoeuaoeu][bar][999]')
111
113
  end
112
114
  end
113
115
  end
@@ -50,13 +50,12 @@ describe 'puppet_url_without_modules' do
50
50
  end
51
51
  end
52
52
  end
53
-
53
+
54
54
  context 'double string wrapped puppet:// urls' do
55
55
  let(:code) { File.read('spec/fixtures/test/manifests/url_interpolation.pp') }
56
56
 
57
57
  it 'should detect several problems' do
58
58
  expect(problems).to have(4).problem
59
59
  end
60
-
61
60
  end
62
61
  end
@@ -16,25 +16,29 @@ describe 'single_quote_string_with_variables' do
16
16
  end
17
17
 
18
18
  context 'single quoted inline template with dollar signs has no problems' do
19
- let (:code) {"
20
- $list = ['one', 'two', 'three']
21
- file { '/tmp/text.txt':
22
- ensure => file,
23
- content => inline_template('<% $list.each |$item| { %><%= \"${item}\n\" %><% } %>'),
24
- }
25
- "}
19
+ let(:code) do
20
+ <<-END
21
+ $list = ['one', 'two', 'three']
22
+ file { '/tmp/text.txt':
23
+ ensure => file,
24
+ content => inline_template('<% $list.each |$item| { %><%= "${item}\n" %><% } %>'),
25
+ }
26
+ END
27
+ end
26
28
 
27
29
  it { expect(problems).to have(0).problem }
28
30
  end
29
31
 
30
32
  context 'single quoted inline epp with dollar signs has no problems' do
31
- let (:code) {"
32
- $list = ['one', 'two', 'three']
33
- file { '/tmp/text.txt':
34
- ensure => file,
35
- content => inline_template('<% @list.each do |item| %><%= @item %>\n<% end %>'),
36
- }
37
- "}
33
+ let(:code) do
34
+ <<-END
35
+ $list = ['one', 'two', 'three']
36
+ file { '/tmp/text.txt':
37
+ ensure => file,
38
+ content => inline_template('<% @list.each do |item| %><%= @item %>\n<% end %>'),
39
+ }
40
+ END
41
+ end
38
42
 
39
43
  it { expect(problems).to have(0).problem }
40
44
  end
@@ -28,7 +28,7 @@ describe 'variable_contains_dash' do
28
28
  end
29
29
 
30
30
  context 'variable with an array reference containing a dash' do
31
- let(:code) { "$foo[bar-baz]" }
31
+ let(:code) { '$foo[bar-baz]' }
32
32
 
33
33
  it 'should not detect any problems' do
34
34
  expect(problems).to be_empty
@@ -9,7 +9,7 @@ describe 'variable_is_lowercase' do
9
9
  it 'should only detect a single problem' do
10
10
  expect(problems).to have(1).problem
11
11
  end
12
-
12
+
13
13
  it 'should create a warning' do
14
14
  expect(problems).to contain_warning(msg).on_line(1).in_column(1)
15
15
  end
@@ -1,15 +1,18 @@
1
1
  # encoding: utf-8
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  describe '140chars' do
5
6
  let(:msg) { 'line has more than 140 characters' }
6
7
 
7
8
  context 'file resource with a source line > 140c' do
8
- let(:code) { "
9
- file {
10
- source => 'puppet:///modules/certificates/etc/ssl/private/wildcard.example.com.crt',
11
- }"
12
- }
9
+ let(:code) do
10
+ <<-END
11
+ file {
12
+ source => 'puppet:///modules/certificates/etc/ssl/private/wildcard.example.com.crt',
13
+ }
14
+ END
15
+ end
13
16
 
14
17
  it 'should not detect any problems' do
15
18
  expect(problems).to have(0).problems
@@ -17,11 +20,13 @@ describe '140chars' do
17
20
  end
18
21
 
19
22
  context 'file resource with a template line > 140c' do
20
- let(:code) { "
21
- file {
22
- content => template('mymodule/this/is/a/truely/absurdly/long/path/that/should/make/you/feel/bad'),
23
- }"
24
- }
23
+ let(:code) do
24
+ <<-END
25
+ file {
26
+ content => template('mymodule/this/is/a/truely/absurdly/long/path/that/should/make/you/feel/bad'),
27
+ }
28
+ END
29
+ end
25
30
 
26
31
  it 'should not detect any problems' do
27
32
  expect(problems).to have(0).problems
@@ -29,11 +34,13 @@ describe '140chars' do
29
34
  end
30
35
 
31
36
  context 'length of lines with UTF-8 characters' do
32
- let(:code) { "
33
- # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
34
- # ┃ Configuration ┃
35
- # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
36
- }
37
+ let(:code) do
38
+ <<-END
39
+ # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
40
+ # ┃ Configuration ┃
41
+ # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
42
+ END
43
+ end
37
44
 
38
45
  it 'should not detect any problems' do
39
46
  expect(problems).to have(0).problems
@@ -4,18 +4,20 @@ describe '2sp_soft_tabs' do
4
4
  let(:msg) { 'two-space soft tabs not used' }
5
5
 
6
6
  context 'when a line is indented by 3 spaces' do
7
- let(:code) { "
8
- file { 'foo':
9
- foo => bar,
10
- }"
11
- }
7
+ let(:code) do
8
+ <<-END
9
+ file { 'foo':
10
+ foo => bar,
11
+ }
12
+ END
13
+ end
12
14
 
13
15
  it 'should only detect a single problem' do
14
16
  expect(problems).to have(1).problem
15
17
  end
16
18
 
17
19
  it 'should create an error' do
18
- expect(problems).to contain_error(msg).on_line(3).in_column(1)
20
+ expect(problems).to contain_error(msg).on_line(2).in_column(1)
19
21
  end
20
22
  end
21
23
  end
@@ -1,19 +1,22 @@
1
1
  # encoding: utf-8
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  describe '80chars' do
5
6
  before do
6
- PuppetLint.configuration.send("enable_80chars")
7
+ PuppetLint.configuration.send('enable_80chars')
7
8
  end
8
9
 
9
10
  let(:msg) { 'line has more than 80 characters' }
10
11
 
11
12
  context 'file resource with a source line > 80c' do
12
- let(:code) { "
13
- file {
14
- source => 'puppet:///modules/certificates/etc/ssl/private/wildcard.example.com.crt',
15
- }"
16
- }
13
+ let(:code) do
14
+ <<-END
15
+ file {
16
+ source => 'puppet:///modules/certificates/etc/ssl/private/wildcard.example.com.crt',
17
+ }
18
+ END
19
+ end
17
20
 
18
21
  it 'should not detect any problems' do
19
22
  expect(problems).to have(0).problems
@@ -21,11 +24,13 @@ describe '80chars' do
21
24
  end
22
25
 
23
26
  context 'file resource with a template line > 80c' do
24
- let(:code) { "
25
- file {
26
- content => template('mymodule/this/is/a/truely/absurdly/long/path/that/should/make/you/feel/bad'),
27
- }"
28
- }
27
+ let(:code) do
28
+ <<-END
29
+ file {
30
+ content => template('mymodule/this/is/a/truely/absurdly/long/path/that/should/make/you/feel/bad'),
31
+ }
32
+ END
33
+ end
29
34
 
30
35
  it 'should not detect any problems' do
31
36
  expect(problems).to have(0).problems
@@ -33,11 +38,13 @@ describe '80chars' do
33
38
  end
34
39
 
35
40
  context 'length of lines with UTF-8 characters' do
36
- let(:code) { "
37
- # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
38
- # ┃ Configuration ┃
39
- # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
40
- }
41
+ let(:code) do
42
+ <<-END
43
+ # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
44
+ # ┃ Configuration ┃
45
+ # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
46
+ END
47
+ end
41
48
 
42
49
  it 'should not detect any problems' do
43
50
  expect(problems).to have(0).problems
@@ -55,17 +62,4 @@ describe '80chars' do
55
62
  expect(problems).to contain_warning(msg).on_line(1).in_column(80)
56
63
  end
57
64
  end
58
-
59
- # TODO: figure out why rspec keeps enabling this check!
60
- #
61
- # context '81 character line with disabled check' do
62
- # let(:code) { 'a' * 81 }
63
- #
64
- # PuppetLint.configuration.send("disable_80chars")
65
- #
66
- # it 'should not detect any problems' do
67
- # expect(problems).to have(0).problem
68
- # end
69
- # end
70
-
71
65
  end
@@ -5,16 +5,18 @@ describe 'arrow_alignment' do
5
5
 
6
6
  context 'with fix disabled' do
7
7
  context 'selectors inside a resource' do
8
- let(:code) { "
9
- file { 'foo':
10
- ensure => $ensure,
11
- require => $ensure ? {
12
- present => Class['tomcat::install'],
13
- absent => undef;
14
- },
15
- foo => bar,
16
- }"
17
- }
8
+ let(:code) do
9
+ <<-END
10
+ file { 'foo':
11
+ ensure => $ensure,
12
+ require => $ensure ? {
13
+ present => Class['tomcat::install'],
14
+ absent => undef;
15
+ },
16
+ foo => bar,
17
+ }
18
+ END
19
+ end
18
20
 
19
21
  it 'should not detect any problems' do
20
22
  expect(problems).to have(0).problems
@@ -22,15 +24,17 @@ describe 'arrow_alignment' do
22
24
  end
23
25
 
24
26
  context 'selectors in the middle of a resource' do
25
- let(:code) { "
26
- file { 'foo':
27
- ensure => $ensure ? {
28
- present => directory,
29
- absent => undef,
30
- },
31
- owner => 'tomcat6',
32
- }"
33
- }
27
+ let(:code) do
28
+ <<-END
29
+ file { 'foo':
30
+ ensure => $ensure ? {
31
+ present => directory,
32
+ absent => undef,
33
+ },
34
+ owner => 'tomcat6',
35
+ }
36
+ END
37
+ end
34
38
 
35
39
  it 'should not detect any problems' do
36
40
  expect(problems).to have(0).problems
@@ -38,14 +42,17 @@ describe 'arrow_alignment' do
38
42
  end
39
43
 
40
44
  context 'selector inside a resource' do
41
- let(:code) { "
42
- ensure => $ensure ? {
43
- present => directory,
44
- absent => undef,
45
- },
46
- owner => 'foo4',
47
- group => 'foo4',
48
- mode => '0755'," }
45
+ let(:code) do
46
+ <<-END
47
+ ensure => $ensure ? {
48
+ present => directory,
49
+ absent => undef,
50
+ },
51
+ owner => 'foo4',
52
+ group => 'foo4',
53
+ mode => '0755',
54
+ END
55
+ end
49
56
 
50
57
  it 'should not detect any problems' do
51
58
  expect(problems).to have(0).problems
@@ -53,17 +60,20 @@ describe 'arrow_alignment' do
53
60
  end
54
61
 
55
62
  context 'selector inside a hash inside a resource' do
56
- let(:code) { "
57
- server => {
58
- ensure => ensure => $ensure ? {
59
- present => directory,
60
- absent => undef,
61
- },
62
- ip => '192.168.1.1'
63
- },
64
- owner => 'foo4',
65
- group => 'foo4',
66
- mode => '0755'," }
63
+ let(:code) do
64
+ <<-END
65
+ server => {
66
+ ensure => ensure => $ensure ? {
67
+ present => directory,
68
+ absent => undef,
69
+ },
70
+ ip => '192.168.1.1'
71
+ },
72
+ owner => 'foo4',
73
+ group => 'foo4',
74
+ mode => '0755',
75
+ END
76
+ end
67
77
 
68
78
  it 'should not detect any problems' do
69
79
  expect(problems).to have(0).problems
@@ -71,32 +81,34 @@ describe 'arrow_alignment' do
71
81
  end
72
82
 
73
83
  context 'nested hashes with correct indentation' do
74
- let(:code) { "
75
- class { 'lvs::base':
76
- virtualeservers => {
77
- '192.168.2.13' => {
78
- vport => '11025',
79
- service => 'smtp',
80
- scheduler => 'wlc',
81
- protocol => 'tcp',
82
- checktype => 'external',
83
- checkcommand => '/path/to/checkscript',
84
- real_servers => {
85
- 'server01' => {
86
- real_server => '192.168.2.14',
87
- real_port => '25',
88
- forwarding => 'masq',
89
- },
90
- 'server02' => {
91
- real_server => '192.168.2.15',
92
- real_port => '25',
93
- forwarding => 'masq',
84
+ let(:code) do
85
+ <<-END
86
+ class { 'lvs::base':
87
+ virtualeservers => {
88
+ '192.168.2.13' => {
89
+ vport => '11025',
90
+ service => 'smtp',
91
+ scheduler => 'wlc',
92
+ protocol => 'tcp',
93
+ checktype => 'external',
94
+ checkcommand => '/path/to/checkscript',
95
+ real_servers => {
96
+ 'server01' => {
97
+ real_server => '192.168.2.14',
98
+ real_port => '25',
99
+ forwarding => 'masq',
100
+ },
101
+ 'server02' => {
102
+ real_server => '192.168.2.15',
103
+ real_port => '25',
104
+ forwarding => 'masq',
105
+ }
94
106
  }
95
107
  }
96
108
  }
97
109
  }
98
- }"
99
- }
110
+ END
111
+ end
100
112
 
101
113
  it 'should not detect any problems' do
102
114
  expect(problems).to have(0).problems
@@ -104,128 +116,141 @@ describe 'arrow_alignment' do
104
116
  end
105
117
 
106
118
  context 'single resource with a misaligned =>' do
107
- let(:code) { "
108
- file { '/tmp/foo':
109
- foo => 1,
110
- bar => 2,
111
- gronk => 3,
112
- baz => 4,
113
- meh => 5,
114
- }"
115
- }
119
+ let(:code) do
120
+ <<-END
121
+ file { '/tmp/foo':
122
+ foo => 1,
123
+ bar => 2,
124
+ gronk => 3,
125
+ baz => 4,
126
+ meh => 5,
127
+ }
128
+ END
129
+ end
116
130
 
117
131
  it 'should detect four problems' do
118
132
  expect(problems).to have(4).problems
119
133
  end
120
134
 
121
135
  it 'should create four warnings' do
122
- expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(3).in_column(15)
123
- expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(4).in_column(15)
124
- expect(problems).to contain_warning(sprintf(msg,17,16)).on_line(6).in_column(16)
125
- expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(7).in_column(15)
136
+ expect(problems).to contain_warning(format(msg, 19, 17)).on_line(2).in_column(17)
137
+ expect(problems).to contain_warning(format(msg, 19, 17)).on_line(3).in_column(17)
138
+ expect(problems).to contain_warning(format(msg, 19, 18)).on_line(5).in_column(18)
139
+ expect(problems).to contain_warning(format(msg, 19, 17)).on_line(6).in_column(17)
126
140
  end
127
141
  end
128
142
 
129
143
  context 'single resource with a misaligned => and semicolon at the end' do
130
- let(:code) { "
131
- file { '/tmp/bar':
132
- foo => 1,
133
- bar => 2,
134
- gronk => 3,
135
- baz => 4,
136
- meh => 5;
137
- }"
138
- }
144
+ let(:code) do
145
+ <<-END
146
+ file { '/tmp/bar':
147
+ foo => 1,
148
+ bar => 2,
149
+ gronk => 3,
150
+ baz => 4,
151
+ meh => 5;
152
+ }
153
+ END
154
+ end
139
155
 
140
156
  it 'should detect four problems' do
141
157
  expect(problems).to have(4).problems
142
158
  end
143
159
 
144
160
  it 'should create four warnings' do
145
- expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(3).in_column(15)
146
- expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(4).in_column(15)
147
- expect(problems).to contain_warning(sprintf(msg,17,16)).on_line(6).in_column(16)
148
- expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(7).in_column(15)
161
+ expect(problems).to contain_warning(format(msg, 19, 17)).on_line(2).in_column(17)
162
+ expect(problems).to contain_warning(format(msg, 19, 17)).on_line(3).in_column(17)
163
+ expect(problems).to contain_warning(format(msg, 19, 18)).on_line(5).in_column(18)
164
+ expect(problems).to contain_warning(format(msg, 19, 17)).on_line(6).in_column(17)
149
165
  end
150
166
  end
167
+
151
168
  context 'complex resource with a misaligned =>' do
152
- let(:code) { "
153
- file { '/tmp/foo':
154
- foo => 1,
155
- bar => $baz ? {
156
- gronk => 2,
157
- meh => 3,
158
- },
159
- meep => 4,
160
- bah => 5,
161
- }"
162
- }
169
+ let(:code) do
170
+ <<-END
171
+ file { '/tmp/foo':
172
+ foo => 1,
173
+ bar => $baz ? {
174
+ gronk => 2,
175
+ meh => 3,
176
+ },
177
+ meep => 4,
178
+ bah => 5,
179
+ }
180
+ END
181
+ end
163
182
 
164
183
  it 'should detect three problems' do
165
184
  expect(problems).to have(3).problems
166
185
  end
167
186
 
168
187
  it 'should create three warnings' do
169
- expect(problems).to contain_warning(sprintf(msg,16,15)).on_line(3).in_column(15)
170
- expect(problems).to contain_warning(sprintf(msg,19,17)).on_line(6).in_column(17)
171
- expect(problems).to contain_warning(sprintf(msg,16,15)).on_line(9).in_column(15)
188
+ expect(problems).to contain_warning(format(msg, 18, 17)).on_line(2).in_column(17)
189
+ expect(problems).to contain_warning(format(msg, 21, 19)).on_line(5).in_column(19)
190
+ expect(problems).to contain_warning(format(msg, 18, 17)).on_line(8).in_column(17)
172
191
  end
173
192
  end
174
193
 
175
194
  context 'multi-resource with a misaligned =>' do
176
- let(:code) { "
177
- file {
178
- '/tmp/foo': ;
179
- '/tmp/bar':
180
- foo => 'bar';
181
- '/tmp/baz':
182
- gronk => 'bah',
183
- meh => 'no'
184
- }"
185
- }
195
+ let(:code) do
196
+ <<-END
197
+ file {
198
+ '/tmp/foo': ;
199
+ '/tmp/bar':
200
+ foo => 'bar';
201
+ '/tmp/baz':
202
+ gronk => 'bah',
203
+ meh => 'no'
204
+ }
205
+ END
206
+ end
186
207
 
187
208
  it 'should only detect a single problem' do
188
209
  expect(problems).to have(1).problem
189
210
  end
190
211
 
191
212
  it 'should create a warning' do
192
- expect(problems).to contain_warning(sprintf(msg,19,17)).on_line(8).in_column(17)
213
+ expect(problems).to contain_warning(format(msg, 21, 19)).on_line(7).in_column(19)
193
214
  end
194
215
  end
195
216
 
196
217
  context 'multi-resource with a misaligned => and semicolons' do
197
- let(:code) { "
198
- file {
199
- '/tmp/foo':
200
- ensure => 'directory',
201
- owner => 'root',
202
- mode => '0755';
203
- '/tmp/bar':
204
- ensure => 'directory';
205
- '/tmp/baz':
206
- ensure => 'directory',
207
- owner => 'root',
208
- mode => '0755';
209
- }"
210
- }
218
+ let(:code) do
219
+ <<-END
220
+ file {
221
+ '/tmp/foo':
222
+ ensure => 'directory',
223
+ owner => 'root',
224
+ mode => '0755';
225
+ '/tmp/bar':
226
+ ensure => 'directory';
227
+ '/tmp/baz':
228
+ ensure => 'directory',
229
+ owner => 'root',
230
+ mode => '0755';
231
+ }
232
+ END
233
+ end
211
234
 
212
235
  it 'should only detect a single problem' do
213
236
  expect(problems).to have(4).problem
214
237
  end
215
238
 
216
239
  it 'should create a warning' do
217
- expect(problems).to contain_warning(sprintf(msg,20,19)).on_line(5).in_column(19)
218
- expect(problems).to contain_warning(sprintf(msg,20,18)).on_line(6).in_column(18)
219
- expect(problems).to contain_warning(sprintf(msg,20,19)).on_line(11).in_column(19)
220
- expect(problems).to contain_warning(sprintf(msg,20,18)).on_line(12).in_column(18)
240
+ expect(problems).to contain_warning(format(msg, 22, 21)).on_line(4).in_column(21)
241
+ expect(problems).to contain_warning(format(msg, 22, 20)).on_line(5).in_column(20)
242
+ expect(problems).to contain_warning(format(msg, 22, 21)).on_line(10).in_column(21)
243
+ expect(problems).to contain_warning(format(msg, 22, 20)).on_line(11).in_column(20)
221
244
  end
222
245
  end
223
246
 
224
247
  context 'multiple single line resources' do
225
- let(:code) { "
226
- file { 'foo': ensure => file }
227
- package { 'bar': ensure => present }"
228
- }
248
+ let(:code) do
249
+ <<-END
250
+ file { 'foo': ensure => file }
251
+ package { 'bar': ensure => present }
252
+ END
253
+ end
229
254
 
230
255
  it 'should not detect any problems' do
231
256
  expect(problems).to have(0).problems
@@ -233,12 +258,14 @@ describe 'arrow_alignment' do
233
258
  end
234
259
 
235
260
  context 'resource with unaligned => in commented line' do
236
- let(:code) { "
237
- file { 'foo':
238
- ensure => directory,
239
- # purge => true,
240
- }"
241
- }
261
+ let(:code) do
262
+ <<-END
263
+ file { 'foo':
264
+ ensure => directory,
265
+ # purge => true,
266
+ }
267
+ END
268
+ end
242
269
 
243
270
  it 'should not detect any problems' do
244
271
  expect(problems).to have(0).problems
@@ -246,11 +273,13 @@ describe 'arrow_alignment' do
246
273
  end
247
274
 
248
275
  context 'single line resource spread out on multiple lines' do
249
- let(:code) {"
250
- file {
251
- 'foo': ensure => present,
252
- }"
253
- }
276
+ let(:code) do
277
+ <<-END
278
+ file {
279
+ 'foo': ensure => present,
280
+ }
281
+ END
282
+ end
254
283
 
255
284
  it 'should not detect any problems' do
256
285
  expect(problems).to have(0).problems
@@ -258,11 +287,13 @@ describe 'arrow_alignment' do
258
287
  end
259
288
 
260
289
  context 'multiline resource with a single line of params' do
261
- let(:code) { "
262
- mymodule::do_thing { 'some thing':
263
- whatever => { foo => 'bar', one => 'two' },
264
- }"
265
- }
290
+ let(:code) do
291
+ <<-END
292
+ mymodule::do_thing { 'some thing':
293
+ whatever => { foo => 'bar', one => 'two' },
294
+ }
295
+ END
296
+ end
266
297
 
267
298
  it 'should not detect any problems' do
268
299
  expect(problems).to have(0).problems
@@ -270,31 +301,35 @@ describe 'arrow_alignment' do
270
301
  end
271
302
 
272
303
  context 'resource with aligned => too far out' do
273
- let(:code) { "
274
- file { '/tmp/foo':
275
- ensure => file,
276
- mode => '0444',
277
- }"
278
- }
304
+ let(:code) do
305
+ <<-END
306
+ file { '/tmp/foo':
307
+ ensure => file,
308
+ mode => '0444',
309
+ }
310
+ END
311
+ end
279
312
 
280
313
  it 'should detect 2 problems' do
281
314
  expect(problems).to have(2).problems
282
315
  end
283
316
 
284
317
  it 'should create 2 warnings' do
285
- expect(problems).to contain_warning(sprintf(msg,18,19)).on_line(3).in_column(19)
286
- expect(problems).to contain_warning(sprintf(msg,18,19)).on_line(4).in_column(19)
318
+ expect(problems).to contain_warning(format(msg, 20, 21)).on_line(2).in_column(21)
319
+ expect(problems).to contain_warning(format(msg, 20, 21)).on_line(3).in_column(21)
287
320
  end
288
321
  end
289
322
 
290
323
  context 'resource with multiple params where one is an empty hash' do
291
- let(:code) { "
292
- foo { 'foo':
293
- a => true,
294
- b => {
324
+ let(:code) do
325
+ <<-END
326
+ foo { 'foo':
327
+ a => true,
328
+ b => {
329
+ }
295
330
  }
296
- }
297
- "}
331
+ END
332
+ end
298
333
 
299
334
  it 'should not detect any problems' do
300
335
  expect(problems).to have(0).problems
@@ -302,30 +337,34 @@ describe 'arrow_alignment' do
302
337
  end
303
338
 
304
339
  context 'multiline resource with multiple params on a line' do
305
- let(:code) { "
306
- user { 'test':
307
- a => 'foo', bb => 'bar',
308
- ccc => 'baz',
309
- }
310
- " }
340
+ let(:code) do
341
+ <<-END
342
+ user { 'test':
343
+ a => 'foo', bb => 'bar',
344
+ ccc => 'baz',
345
+ }
346
+ END
347
+ end
311
348
 
312
349
  it 'should detect 2 problems' do
313
350
  expect(problems).to have(2).problems
314
351
  end
315
352
 
316
353
  it 'should create 2 warnings' do
317
- expect(problems).to contain_warning(sprintf(msg,15,13)).on_line(3).in_column(13)
318
- expect(problems).to contain_warning(sprintf(msg,15,26)).on_line(3).in_column(26)
354
+ expect(problems).to contain_warning(format(msg, 17, 15)).on_line(2).in_column(15)
355
+ expect(problems).to contain_warning(format(msg, 17, 28)).on_line(2).in_column(28)
319
356
  end
320
357
  end
321
358
 
322
359
  context 'resource param containing a single-element same-line hash' do
323
- let(:code) { "
324
- foo { 'foo':
325
- a => true,
326
- b => { 'a' => 'b' }
327
- }
328
- "}
360
+ let(:code) do
361
+ <<-END
362
+ foo { 'foo':
363
+ a => true,
364
+ b => { 'a' => 'b' }
365
+ }
366
+ END
367
+ end
329
368
 
330
369
  it 'should not detect any problems' do
331
370
  expect(problems).to have(0).problems
@@ -333,14 +372,16 @@ describe 'arrow_alignment' do
333
372
  end
334
373
 
335
374
  context 'multiline hash with opening brace on same line as first pair' do
336
- let(:code) { "
337
- foo { 'foo':
338
- bar => [
339
- { aa => bb,
340
- c => d},
341
- ],
342
- }
343
- " }
375
+ let(:code) do
376
+ <<-END
377
+ foo { 'foo':
378
+ bar => [
379
+ { aa => bb,
380
+ c => d},
381
+ ],
382
+ }
383
+ END
384
+ end
344
385
 
345
386
  it 'should not detect any problems' do
346
387
  expect(problems).to have(0).problems
@@ -348,34 +389,38 @@ describe 'arrow_alignment' do
348
389
  end
349
390
 
350
391
  context 'unaligned multiline hash with opening brace on the same line as the first pair' do
351
- let(:code) { "
352
- foo { 'foo':
353
- bar => [
354
- { aa => bb,
355
- c => d},
356
- ],
357
- }
358
- " }
392
+ let(:code) do
393
+ <<-END
394
+ foo { 'foo':
395
+ bar => [
396
+ { aa => bb,
397
+ c => d},
398
+ ],
399
+ }
400
+ END
401
+ end
359
402
 
360
403
  it 'should detect one problem' do
361
404
  expect(problems).to have(1).problem
362
405
  end
363
406
 
364
407
  it 'should create one warning' do
365
- expect(problems).to contain_warning(sprintf(msg,18,17)).on_line(5).in_column(17)
408
+ expect(problems).to contain_warning(format(msg, 20, 19)).on_line(4).in_column(19)
366
409
  end
367
410
  end
368
411
 
369
412
  context 'hash with strings containing variables as keys properly aligned' do
370
- let(:code) { '
371
- foo { foo:
372
- param => {
373
- a => 1
374
- "${aoeu}" => 2,
375
- b => 3,
376
- },
377
- }
378
- ' }
413
+ let(:code) do
414
+ <<-END
415
+ foo { foo:
416
+ param => {
417
+ a => 1
418
+ "${aoeu}" => 2,
419
+ b => 3,
420
+ },
421
+ }
422
+ END
423
+ end
379
424
 
380
425
  it 'should not detect any problems' do
381
426
  expect(problems).to have(0).problems
@@ -383,42 +428,46 @@ describe 'arrow_alignment' do
383
428
  end
384
429
 
385
430
  context 'hash with strings containing variables as keys incorrectly aligned' do
386
- let(:code) { '
387
- foo { foo:
388
- param => {
389
- a => 1
390
- "${aoeu}" => 2,
391
- b => 3,
392
- },
393
- }
394
- ' }
431
+ let(:code) do
432
+ <<-END
433
+ foo { foo:
434
+ param => {
435
+ a => 1
436
+ "${aoeu}" => 2,
437
+ b => 3,
438
+ },
439
+ }
440
+ END
441
+ end
395
442
 
396
443
  it 'should detect 2 problems' do
397
444
  expect(problems).to have(2).problems
398
445
  end
399
446
 
400
447
  it 'should create 2 warnings' do
401
- expect(problems).to contain_warning(sprintf(msg,23,15)).on_line(4).in_column(15)
402
- expect(problems).to contain_warning(sprintf(msg,23,19)).on_line(6).in_column(19)
448
+ expect(problems).to contain_warning(format(msg, 25, 17)).on_line(3).in_column(17)
449
+ expect(problems).to contain_warning(format(msg, 25, 21)).on_line(5).in_column(21)
403
450
  end
404
451
  end
405
452
 
406
453
  context 'complex data structure with different indentation levels at the same depth' do
407
- let(:code) { "
408
- class { 'some_class':
409
- config_hash => {
410
- 'a_hash' => {
411
- 'foo' => 'bar',
412
- },
413
- 'an_array' => [
414
- {
415
- foo => 'bar',
416
- bar => 'baz',
454
+ let(:code) do
455
+ <<-END
456
+ class { 'some_class':
457
+ config_hash => {
458
+ 'a_hash' => {
459
+ 'foo' => 'bar',
417
460
  },
418
- ],
419
- },
420
- }
421
- " }
461
+ 'an_array' => [
462
+ {
463
+ foo => 'bar',
464
+ bar => 'baz',
465
+ },
466
+ ],
467
+ },
468
+ }
469
+ END
470
+ end
422
471
 
423
472
  it 'should not detect any problems' do
424
473
  expect(problems).to have(0).problems
@@ -426,16 +475,18 @@ describe 'arrow_alignment' do
426
475
  end
427
476
 
428
477
  context 'where the top level of the block has no parameters' do
429
- let(:code) { "
430
- case $::osfamily {
431
- 'RedHat': {
432
- $datadir = $::operatingsystem ? {
433
- 'Amazon' => pick($datadir, 'value'),
434
- default => pick($datadir, 'value'),
478
+ let(:code) do
479
+ <<-END
480
+ case $::osfamily {
481
+ 'RedHat': {
482
+ $datadir = $::operatingsystem ? {
483
+ 'Amazon' => pick($datadir, 'value'),
484
+ default => pick($datadir, 'value'),
485
+ }
435
486
  }
436
487
  }
437
- }
438
- " }
488
+ END
489
+ end
439
490
 
440
491
  it 'should not detect any problems' do
441
492
  expect(problems).to have(0).problems
@@ -453,34 +504,39 @@ describe 'arrow_alignment' do
453
504
  end
454
505
 
455
506
  context 'single resource with a misaligned =>' do
456
- let(:code) { "
457
- file { '/tmp/foo':
458
- foo => 1,
459
- bar => 2,
460
- gronk => 3,
461
- baz => 4,
462
- meh => 5,
463
- }"
464
- }
465
- let(:fixed) { "
466
- file { '/tmp/foo':
467
- foo => 1,
468
- bar => 2,
469
- gronk => 3,
470
- baz => 4,
471
- meh => 5,
472
- }"
473
- }
507
+ let(:code) do
508
+ <<-END
509
+ file { '/tmp/foo':
510
+ foo => 1,
511
+ bar => 2,
512
+ gronk => 3,
513
+ baz => 4,
514
+ meh => 5,
515
+ }
516
+ END
517
+ end
518
+
519
+ let(:fixed) do
520
+ <<-END
521
+ file { '/tmp/foo':
522
+ foo => 1,
523
+ bar => 2,
524
+ gronk => 3,
525
+ baz => 4,
526
+ meh => 5,
527
+ }
528
+ END
529
+ end
474
530
 
475
531
  it 'should detect four problems' do
476
532
  expect(problems).to have(4).problems
477
533
  end
478
534
 
479
535
  it 'should fix the manifest' do
480
- expect(problems).to contain_fixed(sprintf(msg,17,15)).on_line(3).in_column(15)
481
- expect(problems).to contain_fixed(sprintf(msg,17,15)).on_line(4).in_column(15)
482
- expect(problems).to contain_fixed(sprintf(msg,17,16)).on_line(6).in_column(16)
483
- expect(problems).to contain_fixed(sprintf(msg,17,15)).on_line(7).in_column(15)
536
+ expect(problems).to contain_fixed(format(msg, 19, 17)).on_line(2).in_column(17)
537
+ expect(problems).to contain_fixed(format(msg, 19, 17)).on_line(3).in_column(17)
538
+ expect(problems).to contain_fixed(format(msg, 19, 18)).on_line(5).in_column(18)
539
+ expect(problems).to contain_fixed(format(msg, 19, 17)).on_line(6).in_column(17)
484
540
  end
485
541
 
486
542
  it 'should align the arrows' do
@@ -489,37 +545,42 @@ describe 'arrow_alignment' do
489
545
  end
490
546
 
491
547
  context 'complex resource with a misaligned =>' do
492
- let(:code) { "
493
- file { '/tmp/foo':
494
- foo => 1,
495
- bar => $baz ? {
496
- gronk => 2,
497
- meh => 3,
498
- },
499
- meep => 4,
500
- bah => 5,
501
- }"
502
- }
503
- let(:fixed) { "
504
- file { '/tmp/foo':
505
- foo => 1,
506
- bar => $baz ? {
507
- gronk => 2,
508
- meh => 3,
509
- },
510
- meep => 4,
511
- bah => 5,
512
- }"
513
- }
548
+ let(:code) do
549
+ <<-END
550
+ file { '/tmp/foo':
551
+ foo => 1,
552
+ bar => $baz ? {
553
+ gronk => 2,
554
+ meh => 3,
555
+ },
556
+ meep => 4,
557
+ bah => 5,
558
+ }
559
+ END
560
+ end
561
+
562
+ let(:fixed) do
563
+ <<-END
564
+ file { '/tmp/foo':
565
+ foo => 1,
566
+ bar => $baz ? {
567
+ gronk => 2,
568
+ meh => 3,
569
+ },
570
+ meep => 4,
571
+ bah => 5,
572
+ }
573
+ END
574
+ end
514
575
 
515
576
  it 'should detect three problems' do
516
577
  expect(problems).to have(3).problems
517
578
  end
518
579
 
519
580
  it 'should fix the manifest' do
520
- expect(problems).to contain_fixed(sprintf(msg,16,15)).on_line(3).in_column(15)
521
- expect(problems).to contain_fixed(sprintf(msg,19,17)).on_line(6).in_column(17)
522
- expect(problems).to contain_fixed(sprintf(msg,16,15)).on_line(9).in_column(15)
581
+ expect(problems).to contain_fixed(format(msg, 18, 17)).on_line(2).in_column(17)
582
+ expect(problems).to contain_fixed(format(msg, 21, 19)).on_line(5).in_column(19)
583
+ expect(problems).to contain_fixed(format(msg, 18, 17)).on_line(8).in_column(17)
523
584
  end
524
585
 
525
586
  it 'should align the arrows' do
@@ -528,33 +589,38 @@ describe 'arrow_alignment' do
528
589
  end
529
590
 
530
591
  context 'multi-resource with a misaligned =>' do
531
- let(:code) { "
532
- file {
533
- '/tmp/foo': ;
534
- '/tmp/bar':
535
- foo => 'bar';
536
- '/tmp/baz':
537
- gronk => 'bah',
538
- meh => 'no'
539
- }"
540
- }
541
- let(:fixed) { "
542
- file {
543
- '/tmp/foo': ;
544
- '/tmp/bar':
545
- foo => 'bar';
546
- '/tmp/baz':
547
- gronk => 'bah',
548
- meh => 'no'
549
- }"
550
- }
592
+ let(:code) do
593
+ <<-END
594
+ file {
595
+ '/tmp/foo': ;
596
+ '/tmp/bar':
597
+ foo => 'bar';
598
+ '/tmp/baz':
599
+ gronk => 'bah',
600
+ meh => 'no'
601
+ }
602
+ END
603
+ end
604
+
605
+ let(:fixed) do
606
+ <<-END
607
+ file {
608
+ '/tmp/foo': ;
609
+ '/tmp/bar':
610
+ foo => 'bar';
611
+ '/tmp/baz':
612
+ gronk => 'bah',
613
+ meh => 'no'
614
+ }
615
+ END
616
+ end
551
617
 
552
618
  it 'should only detect a single problem' do
553
619
  expect(problems).to have(1).problem
554
620
  end
555
621
 
556
622
  it 'should fix the manifest' do
557
- expect(problems).to contain_fixed(sprintf(msg,19,17)).on_line(8).in_column(17)
623
+ expect(problems).to contain_fixed(format(msg, 21, 19)).on_line(7).in_column(19)
558
624
  end
559
625
 
560
626
  it 'should align the arrows' do
@@ -563,27 +629,31 @@ describe 'arrow_alignment' do
563
629
  end
564
630
 
565
631
  context 'resource with aligned => too far out' do
566
- let(:code) { "
567
- file { '/tmp/foo':
568
- ensure => file,
569
- mode => '0444',
570
- }"
571
- }
572
-
573
- let(:fixed) { "
574
- file { '/tmp/foo':
575
- ensure => file,
576
- mode => '0444',
577
- }"
578
- }
632
+ let(:code) do
633
+ <<-END
634
+ file { '/tmp/foo':
635
+ ensure => file,
636
+ mode => '0444',
637
+ }
638
+ END
639
+ end
640
+
641
+ let(:fixed) do
642
+ <<-END
643
+ file { '/tmp/foo':
644
+ ensure => file,
645
+ mode => '0444',
646
+ }
647
+ END
648
+ end
579
649
 
580
650
  it 'should detect 2 problems' do
581
651
  expect(problems).to have(2).problems
582
652
  end
583
653
 
584
654
  it 'should create 2 warnings' do
585
- expect(problems).to contain_fixed(sprintf(msg,18,19)).on_line(3).in_column(19)
586
- expect(problems).to contain_fixed(sprintf(msg,18,19)).on_line(4).in_column(19)
655
+ expect(problems).to contain_fixed(format(msg, 20, 21)).on_line(2).in_column(21)
656
+ expect(problems).to contain_fixed(format(msg, 20, 21)).on_line(3).in_column(21)
587
657
  end
588
658
 
589
659
  it 'should realign the arrows with the minimum whitespace' do
@@ -592,26 +662,30 @@ describe 'arrow_alignment' do
592
662
  end
593
663
 
594
664
  context 'resource with unaligned => and no whitespace between param and =>' do
595
- let(:code) { "
596
- user { 'test':
597
- param1 => 'foo',
598
- param2=> 'bar',
599
- }
600
- " }
601
-
602
- let(:fixed) { "
603
- user { 'test':
604
- param1 => 'foo',
605
- param2 => 'bar',
606
- }
607
- " }
665
+ let(:code) do
666
+ <<-END
667
+ user { 'test':
668
+ param1 => 'foo',
669
+ param2=> 'bar',
670
+ }
671
+ END
672
+ end
673
+
674
+ let(:fixed) do
675
+ <<-END
676
+ user { 'test':
677
+ param1 => 'foo',
678
+ param2 => 'bar',
679
+ }
680
+ END
681
+ end
608
682
 
609
683
  it 'should detect 1 problem' do
610
684
  expect(problems).to have(1).problem
611
685
  end
612
686
 
613
687
  it 'should fix the problem' do
614
- expect(problems).to contain_fixed(sprintf(msg,18,17)).on_line(4).in_column(17)
688
+ expect(problems).to contain_fixed(format(msg, 20, 19)).on_line(3).in_column(19)
615
689
  end
616
690
 
617
691
  it 'should add whitespace between the param and the arrow' do
@@ -620,28 +694,32 @@ describe 'arrow_alignment' do
620
694
  end
621
695
 
622
696
  context 'multiline resource with multiple params on a line' do
623
- let(:code) { "
624
- user { 'test':
625
- a => 'foo', bb => 'bar',
626
- ccc => 'baz',
627
- }
628
- " }
629
-
630
- let(:fixed) { "
631
- user { 'test':
632
- a => 'foo',
633
- bb => 'bar',
634
- ccc => 'baz',
635
- }
636
- " }
697
+ let(:code) do
698
+ <<-END
699
+ user { 'test':
700
+ a => 'foo', bb => 'bar',
701
+ ccc => 'baz',
702
+ }
703
+ END
704
+ end
705
+
706
+ let(:fixed) do
707
+ <<-END
708
+ user { 'test':
709
+ a => 'foo',
710
+ bb => 'bar',
711
+ ccc => 'baz',
712
+ }
713
+ END
714
+ end
637
715
 
638
716
  it 'should detect 2 problems' do
639
717
  expect(problems).to have(2).problems
640
718
  end
641
719
 
642
720
  it 'should fix 2 problems' do
643
- expect(problems).to contain_fixed(sprintf(msg,15,13)).on_line(3).in_column(13)
644
- expect(problems).to contain_fixed(sprintf(msg,15,26)).on_line(3).in_column(26)
721
+ expect(problems).to contain_fixed(format(msg, 17, 15)).on_line(2).in_column(15)
722
+ expect(problems).to contain_fixed(format(msg, 17, 28)).on_line(2).in_column(28)
645
723
  end
646
724
 
647
725
  it 'should move the extra param onto its own line and realign' do
@@ -650,64 +728,72 @@ describe 'arrow_alignment' do
650
728
  end
651
729
 
652
730
  context 'multiline resource with multiple params on a line, extra one longer' do
653
- let(:code) { "
654
- user { 'test':
655
- a => 'foo', bbccc => 'bar',
656
- ccc => 'baz',
657
- }
658
- " }
659
-
660
- let(:fixed) { "
661
- user { 'test':
662
- a => 'foo',
663
- bbccc => 'bar',
664
- ccc => 'baz',
665
- }
666
- " }
731
+ let(:code) do
732
+ <<-END
733
+ user { 'test':
734
+ a => 'foo', bbccc => 'bar',
735
+ ccc => 'baz',
736
+ }
737
+ END
738
+ end
739
+
740
+ let(:fixed) do
741
+ <<-END
742
+ user { 'test':
743
+ a => 'foo',
744
+ bbccc => 'bar',
745
+ ccc => 'baz',
746
+ }
747
+ END
748
+ end
667
749
 
668
750
  it 'should detect 2 problems' do
669
751
  expect(problems).to have(3).problems
670
752
  end
671
753
 
672
754
  it 'should fix 2 problems' do
673
- expect(problems).to contain_fixed(sprintf(msg,17,13)).on_line(3).in_column(13)
674
- expect(problems).to contain_fixed(sprintf(msg,17,29)).on_line(3).in_column(29)
675
- expect(problems).to contain_fixed(sprintf(msg,17,15)).on_line(4).in_column(15)
755
+ expect(problems).to contain_fixed(format(msg, 19, 15)).on_line(2).in_column(15)
756
+ expect(problems).to contain_fixed(format(msg, 19, 31)).on_line(2).in_column(31)
757
+ expect(problems).to contain_fixed(format(msg, 19, 17)).on_line(3).in_column(17)
676
758
  end
677
759
 
678
760
  it 'should move the extra param onto its own line and realign' do
679
761
  expect(manifest).to eq(fixed)
680
762
  end
681
763
  end
682
-
764
+
683
765
  context 'hash with strings containing variables as keys incorrectly aligned' do
684
- let(:code) { '
685
- foo { foo:
686
- param => {
687
- a => 1
688
- "${aoeu}" => 2,
689
- b => 3,
690
- },
691
- }
692
- ' }
693
- let(:fixed) { '
694
- foo { foo:
695
- param => {
696
- a => 1
697
- "${aoeu}" => 2,
698
- b => 3,
699
- },
700
- }
701
- ' }
766
+ let(:code) do
767
+ <<-END
768
+ foo { foo:
769
+ param => {
770
+ a => 1
771
+ "${aoeu}" => 2,
772
+ b => 3,
773
+ },
774
+ }
775
+ END
776
+ end
702
777
 
778
+ let(:fixed) do
779
+ <<-END
780
+ foo { foo:
781
+ param => {
782
+ a => 1
783
+ "${aoeu}" => 2,
784
+ b => 3,
785
+ },
786
+ }
787
+ END
788
+ end
703
789
 
704
790
  it 'should detect 2 problems' do
705
791
  expect(problems).to have(2).problems
706
792
  end
707
793
 
708
794
  it 'should fix 2 problems' do
709
- expect(problems).to contain_fixed(sprintf(msg,23,15)).on_line(4).in_column(15)
710
- expect(problems).to contain_fixed(sprintf(msg,23,19)).on_line(6).in_column(19)
795
+ expect(problems).to contain_fixed(format(msg, 25, 17)).on_line(3).in_column(17)
796
+ expect(problems).to contain_fixed(format(msg, 25, 21)).on_line(5).in_column(21)
711
797
  end
712
798
 
713
799
  it 'should align the hash rockets' do
@@ -716,44 +802,48 @@ describe 'arrow_alignment' do
716
802
  end
717
803
 
718
804
  context 'complex data structure with different indentation levels at the same depth' do
719
- let(:code) { "
720
- class { 'some_class':
721
- config_hash => {
722
- 'a_hash' => {
723
- 'foo' => 'bar',
724
- },
725
- 'an_array' => [
726
- {
727
- foo => 'bar',
728
- bar => 'baz',
805
+ let(:code) do
806
+ <<-END
807
+ class { 'some_class':
808
+ config_hash => {
809
+ 'a_hash' => {
810
+ 'foo' => 'bar',
729
811
  },
730
- ],
731
- },
732
- }
733
- " }
734
-
735
- let(:fixed) { "
736
- class { 'some_class':
737
- config_hash => {
738
- 'a_hash' => {
739
- 'foo' => 'bar',
812
+ 'an_array' => [
813
+ {
814
+ foo => 'bar',
815
+ bar => 'baz',
816
+ },
817
+ ],
740
818
  },
741
- 'an_array' => [
742
- {
743
- foo => 'bar',
744
- bar => 'baz',
819
+ }
820
+ END
821
+ end
822
+
823
+ let(:fixed) do
824
+ <<-END
825
+ class { 'some_class':
826
+ config_hash => {
827
+ 'a_hash' => {
828
+ 'foo' => 'bar',
745
829
  },
746
- ],
747
- },
748
- }
749
- " }
830
+ 'an_array' => [
831
+ {
832
+ foo => 'bar',
833
+ bar => 'baz',
834
+ },
835
+ ],
836
+ },
837
+ }
838
+ END
839
+ end
750
840
 
751
841
  it 'should detect 1 problem' do
752
842
  expect(problems).to have(1).problems
753
843
  end
754
844
 
755
845
  it 'should fix 1 problem' do
756
- expect(problems).to contain_fixed(sprintf(msg, 21, 22)).on_line(10).in_column(22)
846
+ expect(problems).to contain_fixed(format(msg, 23, 24)).on_line(9).in_column(24)
757
847
  end
758
848
 
759
849
  it 'should align the hash rockets' do
@@ -762,58 +852,60 @@ describe 'arrow_alignment' do
762
852
  end
763
853
 
764
854
  context 'complex data structure with multiple token keys' do
765
- let(:code) { <<-END.gsub(/^ {8}/, '')
766
- class example (
767
- $external_ip_base,
768
- ) {
769
-
770
- bar { 'xxxxxxxxx':
771
- inputs => {
772
- 'ny' => {
773
- "${external_ip_base}.16:443 ${a} ${b} ${c}" => 'foo',
774
- 'veryveryverylongstring8:443'=> 'foo',
775
- 'simple'=> 'foo',
776
- '3'=> :foo,
777
- :baz=> :qux,
778
- 3=> 3,
855
+ let(:code) do
856
+ <<-END.gsub(%r{^ {10}}, '')
857
+ class example (
858
+ $external_ip_base,
859
+ ) {
860
+
861
+ bar { 'xxxxxxxxx':
862
+ inputs => {
863
+ 'ny' => {
864
+ "${external_ip_base}.16:443 ${a} ${b} ${c}" => 'foo',
865
+ 'veryveryverylongstring8:443'=> 'foo',
866
+ 'simple'=> 'foo',
867
+ '3'=> :foo,
868
+ :baz=> :qux,
869
+ 3=> 3,
870
+ },
779
871
  },
780
- },
872
+ }
781
873
  }
782
- }
783
874
  END
784
- }
785
-
786
- let(:fixed) { <<-END.gsub(/^ {8}/, '')
787
- class example (
788
- $external_ip_base,
789
- ) {
875
+ end
790
876
 
791
- bar { 'xxxxxxxxx':
792
- inputs => {
793
- 'ny' => {
794
- "${external_ip_base}.16:443 ${a} ${b} ${c}" => 'foo',
795
- 'veryveryverylongstring8:443' => 'foo',
796
- 'simple' => 'foo',
797
- '3' => :foo,
798
- :baz => :qux,
799
- 3 => 3,
877
+ let(:fixed) do
878
+ <<-END.gsub(%r{^ {10}}, '')
879
+ class example (
880
+ $external_ip_base,
881
+ ) {
882
+
883
+ bar { 'xxxxxxxxx':
884
+ inputs => {
885
+ 'ny' => {
886
+ "${external_ip_base}.16:443 ${a} ${b} ${c}" => 'foo',
887
+ 'veryveryverylongstring8:443' => 'foo',
888
+ 'simple' => 'foo',
889
+ '3' => :foo,
890
+ :baz => :qux,
891
+ 3 => 3,
892
+ },
800
893
  },
801
- },
894
+ }
802
895
  }
803
- }
804
896
  END
805
- }
897
+ end
806
898
 
807
899
  it 'should detect 5 problems' do
808
900
  expect(problems).to have(5).problems
809
901
  end
810
902
 
811
903
  it 'should fix 5 problems' do
812
- expect(problems).to contain_fixed(sprintf(msg, 53, 38)).on_line(9).in_column(38)
813
- expect(problems).to contain_fixed(sprintf(msg, 53, 17)).on_line(10).in_column(17)
814
- expect(problems).to contain_fixed(sprintf(msg, 53, 12)).on_line(11).in_column(12)
815
- expect(problems).to contain_fixed(sprintf(msg, 53, 13)).on_line(12).in_column(13)
816
- expect(problems).to contain_fixed(sprintf(msg, 53, 10)).on_line(13).in_column(10)
904
+ expect(problems).to contain_fixed(format(msg, 53, 38)).on_line(9).in_column(38)
905
+ expect(problems).to contain_fixed(format(msg, 53, 17)).on_line(10).in_column(17)
906
+ expect(problems).to contain_fixed(format(msg, 53, 12)).on_line(11).in_column(12)
907
+ expect(problems).to contain_fixed(format(msg, 53, 13)).on_line(12).in_column(13)
908
+ expect(problems).to contain_fixed(format(msg, 53, 10)).on_line(13).in_column(10)
817
909
  end
818
910
 
819
911
  it 'should realign the arrows' do
@@ -822,51 +914,53 @@ describe 'arrow_alignment' do
822
914
  end
823
915
 
824
916
  context 'realignment of resource with an inline single line hash' do
825
- let(:code) { <<-END.gsub(/^ {8}/, '')
826
- class { 'puppetdb':
827
- database => 'embedded',
828
- #database => 'postgres',
829
- #postgres_version => '9.3',
830
- java_args => { '-Xmx' => '512m', '-Xms' => '256m' },
831
- listen_address => $::ipaddress_eth0,
832
- listen_port => 4998,
833
- ssl_listen_address => $::ipaddress_eth0,
834
- ssl_listen_port => 4999,
835
- open_listen_port => false,
836
- open_ssl_listen_port => false;
837
- }
838
- END
839
- }
840
-
841
- let(:fixed) { <<-END.gsub(/^ {8}/, '')
842
- class { 'puppetdb':
843
- database => 'embedded',
844
- #database => 'postgres',
845
- #postgres_version => '9.3',
846
- java_args => { '-Xmx' => '512m', '-Xms' => '256m' },
847
- listen_address => $::ipaddress_eth0,
848
- listen_port => 4998,
849
- ssl_listen_address => $::ipaddress_eth0,
850
- ssl_listen_port => 4999,
851
- open_listen_port => false,
852
- open_ssl_listen_port => false;
853
- }
854
- END
855
- }
917
+ let(:code) do
918
+ <<-END.gsub(%r{^ {10}}, '')
919
+ class { 'puppetdb':
920
+ database => 'embedded',
921
+ #database => 'postgres',
922
+ #postgres_version => '9.3',
923
+ java_args => { '-Xmx' => '512m', '-Xms' => '256m' },
924
+ listen_address => $::ipaddress_eth0,
925
+ listen_port => 4998,
926
+ ssl_listen_address => $::ipaddress_eth0,
927
+ ssl_listen_port => 4999,
928
+ open_listen_port => false,
929
+ open_ssl_listen_port => false;
930
+ }
931
+ END
932
+ end
933
+
934
+ let(:fixed) do
935
+ <<-END.gsub(%r{^ {10}}, '')
936
+ class { 'puppetdb':
937
+ database => 'embedded',
938
+ #database => 'postgres',
939
+ #postgres_version => '9.3',
940
+ java_args => { '-Xmx' => '512m', '-Xms' => '256m' },
941
+ listen_address => $::ipaddress_eth0,
942
+ listen_port => 4998,
943
+ ssl_listen_address => $::ipaddress_eth0,
944
+ ssl_listen_port => 4999,
945
+ open_listen_port => false,
946
+ open_ssl_listen_port => false;
947
+ }
948
+ END
949
+ end
856
950
 
857
951
  it 'should detect 8 problems' do
858
952
  expect(problems).to have(8).problems
859
953
  end
860
954
 
861
955
  it 'should fix 8 problems' do
862
- expect(problems).to contain_fixed(sprintf(msg, 24, 27)).on_line(2).in_column(27)
863
- expect(problems).to contain_fixed(sprintf(msg, 24, 27)).on_line(5).in_column(27)
864
- expect(problems).to contain_fixed(sprintf(msg, 24, 27)).on_line(6).in_column(27)
865
- expect(problems).to contain_fixed(sprintf(msg, 24, 27)).on_line(7).in_column(27)
866
- expect(problems).to contain_fixed(sprintf(msg, 24, 27)).on_line(8).in_column(27)
867
- expect(problems).to contain_fixed(sprintf(msg, 24, 27)).on_line(9).in_column(27)
868
- expect(problems).to contain_fixed(sprintf(msg, 24, 27)).on_line(10).in_column(27)
869
- expect(problems).to contain_fixed(sprintf(msg, 24, 27)).on_line(11).in_column(27)
956
+ expect(problems).to contain_fixed(format(msg, 24, 27)).on_line(2).in_column(27)
957
+ expect(problems).to contain_fixed(format(msg, 24, 27)).on_line(5).in_column(27)
958
+ expect(problems).to contain_fixed(format(msg, 24, 27)).on_line(6).in_column(27)
959
+ expect(problems).to contain_fixed(format(msg, 24, 27)).on_line(7).in_column(27)
960
+ expect(problems).to contain_fixed(format(msg, 24, 27)).on_line(8).in_column(27)
961
+ expect(problems).to contain_fixed(format(msg, 24, 27)).on_line(9).in_column(27)
962
+ expect(problems).to contain_fixed(format(msg, 24, 27)).on_line(10).in_column(27)
963
+ expect(problems).to contain_fixed(format(msg, 24, 27)).on_line(11).in_column(27)
870
964
  end
871
965
 
872
966
  it 'should realign the arrows' do