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.
- checksums.yaml +4 -4
- data/.rubocop.yml +74 -0
- data/.rubocop_todo.yml +89 -0
- data/.travis.yml +11 -9
- data/CHANGELOG.md +54 -0
- data/Gemfile +3 -0
- data/Rakefile +14 -3
- data/appveyor.yml +1 -4
- data/bin/puppet-lint +1 -1
- data/lib/puppet-lint.rb +25 -21
- data/lib/puppet-lint/bin.rb +15 -19
- data/lib/puppet-lint/checkplugin.rb +24 -17
- data/lib/puppet-lint/checks.rb +42 -31
- data/lib/puppet-lint/configuration.rb +11 -8
- data/lib/puppet-lint/data.rb +236 -164
- data/lib/puppet-lint/lexer.rb +225 -203
- data/lib/puppet-lint/lexer/token.rb +34 -18
- data/lib/puppet-lint/optparser.rb +33 -30
- data/lib/puppet-lint/plugins.rb +42 -38
- data/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +26 -28
- data/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +21 -20
- data/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +8 -9
- data/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb +9 -8
- data/lib/puppet-lint/plugins/check_classes/inherits_across_namespaces.rb +12 -11
- data/lib/puppet-lint/plugins/check_classes/names_containing_dash.rb +13 -12
- data/lib/puppet-lint/plugins/check_classes/names_containing_uppercase.rb +14 -13
- data/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +9 -10
- data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +40 -31
- data/lib/puppet-lint/plugins/check_classes/right_to_left_relationship.rb +3 -2
- data/lib/puppet-lint/plugins/check_classes/variable_scope.rb +21 -24
- data/lib/puppet-lint/plugins/check_comments/slash_comments.rb +3 -2
- data/lib/puppet-lint/plugins/check_comments/star_comments.rb +6 -5
- data/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb +21 -20
- data/lib/puppet-lint/plugins/check_conditionals/selector_inside_resource.rb +10 -13
- data/lib/puppet-lint/plugins/check_documentation/documentation.rb +26 -17
- data/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb +11 -11
- data/lib/puppet-lint/plugins/check_resources/duplicate_params.rb +4 -3
- data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +17 -18
- data/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +17 -16
- data/lib/puppet-lint/plugins/check_resources/file_mode.rb +22 -23
- data/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +14 -13
- data/lib/puppet-lint/plugins/check_resources/unquoted_resource_title.rb +9 -8
- data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +8 -8
- data/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +29 -42
- data/lib/puppet-lint/plugins/check_strings/puppet_url_without_modules.rb +5 -4
- data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +3 -2
- data/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +4 -3
- data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +3 -2
- data/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +9 -8
- data/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb +9 -8
- data/lib/puppet-lint/plugins/check_whitespace/140chars.rb +9 -9
- data/lib/puppet-lint/plugins/check_whitespace/2sp_soft_tabs.rb +4 -3
- data/lib/puppet-lint/plugins/check_whitespace/80chars.rb +10 -10
- data/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +23 -22
- data/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +3 -2
- data/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb +3 -2
- data/lib/puppet-lint/tasks/puppet-lint.rb +3 -3
- data/lib/puppet-lint/version.rb +1 -1
- data/puppet-lint.gemspec +4 -4
- data/spec/puppet-lint/bin_spec.rb +268 -140
- data/spec/puppet-lint/checks_spec.rb +229 -0
- data/spec/puppet-lint/configuration_spec.rb +10 -9
- data/spec/puppet-lint/data_spec.rb +84 -0
- data/spec/puppet-lint/ignore_overrides_spec.rb +71 -40
- data/spec/puppet-lint/lexer/token_spec.rb +1 -1
- data/spec/puppet-lint/lexer_spec.rb +306 -73
- data/spec/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb +12 -6
- data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +10 -10
- data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +15 -11
- data/spec/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb +26 -21
- data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +3 -3
- data/spec/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb +4 -5
- data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +13 -0
- data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +33 -25
- data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +80 -55
- data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +2 -2
- data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +165 -130
- data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +2 -2
- data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +53 -35
- data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +59 -49
- data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +18 -14
- data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +14 -10
- data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +7 -7
- data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +54 -44
- data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +114 -89
- data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +41 -30
- data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +46 -40
- data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +46 -40
- data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +95 -71
- data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +28 -24
- data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +11 -9
- data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +1 -2
- data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +18 -14
- data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +1 -1
- data/spec/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb +1 -1
- data/spec/puppet-lint/plugins/check_whitespace/140chars_spec.rb +22 -15
- data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +8 -6
- data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +23 -29
- data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +588 -494
- data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +1 -1
- data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +27 -19
- data/spec/puppet-lint_spec.rb +2 -12
- data/spec/spec_helper.rb +35 -30
- metadata +6 -5
- data/lib/puppet-lint/monkeypatches.rb +0 -2
- data/lib/puppet-lint/monkeypatches/string_percent.rb +0 -52
- data/lib/puppet-lint/monkeypatches/string_prepend.rb +0 -13
@@ -0,0 +1,229 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PuppetLint::Checks do
|
4
|
+
subject(:instance) { described_class.new }
|
5
|
+
|
6
|
+
let(:path) { File.join('path', 'to', 'test.pp') }
|
7
|
+
let(:content) { "notify { 'test': }" }
|
8
|
+
|
9
|
+
describe '#initialize' do
|
10
|
+
it { is_expected.to have_attributes(:problems => []) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#load_data' do
|
14
|
+
let(:lexer) { PuppetLint::Lexer.new }
|
15
|
+
|
16
|
+
before do
|
17
|
+
allow(PuppetLint::Lexer).to receive(:new).and_return(lexer)
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when the tokeniser encounters an error' do
|
21
|
+
before do
|
22
|
+
allow(lexer).to receive(:tokenise).with(content).and_raise(lexer_error)
|
23
|
+
instance.load_data(path, content)
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'and the reason for the error is unknown' do
|
27
|
+
let(:lexer_error) { PuppetLint::LexerError.new(1, 2) }
|
28
|
+
|
29
|
+
it 'stores an empty tokens array' do
|
30
|
+
expect(PuppetLint::Data.tokens).to be_empty
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'creates a syntax error problem for the file' do
|
34
|
+
expect(instance.problems).to have(1).problem
|
35
|
+
expect(instance.problems.first).to include(
|
36
|
+
:kind => :error,
|
37
|
+
:check => :syntax,
|
38
|
+
:message => 'Syntax error',
|
39
|
+
:line => 1,
|
40
|
+
:column => 2,
|
41
|
+
:path => anything,
|
42
|
+
:fullpath => anything,
|
43
|
+
:filename => anything,
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'and the reason for the error is known' do
|
49
|
+
let(:lexer_error) { PuppetLint::LexerError.new(1, 2, 'some reason') }
|
50
|
+
|
51
|
+
it 'stores an empty tokens array' do
|
52
|
+
expect(PuppetLint::Data.tokens).to be_empty
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'creates a syntax error problem for the file' do
|
56
|
+
expect(instance.problems).to have(1).problem
|
57
|
+
expect(instance.problems.first).to include(
|
58
|
+
:kind => :error,
|
59
|
+
:check => :syntax,
|
60
|
+
:message => 'Syntax error (some reason)',
|
61
|
+
:line => 1,
|
62
|
+
:column => 2,
|
63
|
+
:path => anything,
|
64
|
+
:fullpath => anything,
|
65
|
+
:filename => anything,
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#run' do
|
73
|
+
let(:fileinfo) { File.join('path', 'to', 'test.pp') }
|
74
|
+
let(:data) { "notify { 'test': }" }
|
75
|
+
let(:enabled_checks) { [] }
|
76
|
+
|
77
|
+
before do
|
78
|
+
allow(instance).to receive(:enabled_checks).and_return(enabled_checks)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'loads the manifest data' do
|
82
|
+
expect(instance).to receive(:load_data).with(fileinfo, data).and_call_original
|
83
|
+
instance.run(fileinfo, data)
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'when there are checks enabled' do
|
87
|
+
let(:enabled_checks) { [:arrow_alignment, :hard_tabs] }
|
88
|
+
let(:enabled_check_classes) { enabled_checks.map { |r| PuppetLint.configuration.check_object[r] } }
|
89
|
+
let(:disabled_checks) { PuppetLint.configuration.checks - enabled_checks }
|
90
|
+
let(:disabled_check_classes) { disabled_checks.map { |r| PuppetLint.configuration.check_object[r] } }
|
91
|
+
|
92
|
+
it 'runs the enabled checks' do
|
93
|
+
expect(enabled_check_classes).to all(receive(:new).and_call_original)
|
94
|
+
|
95
|
+
instance.run(fileinfo, data)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'does not run the disabled checks' do
|
99
|
+
# expect().to_not all(matcher) is not supported
|
100
|
+
disabled_check_classes.each do |check_class|
|
101
|
+
expect(check_class).to_not receive(:new)
|
102
|
+
end
|
103
|
+
|
104
|
+
instance.run(fileinfo, data)
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'when a check finds a problem in the manifest' do
|
108
|
+
let(:arrow_alignment_check) { PuppetLint.configuration.check_object[:arrow_alignment] }
|
109
|
+
let(:hard_tabs_check) { PuppetLint.configuration.check_object[:hard_tabs] }
|
110
|
+
let(:mock_arrow_alignment) do
|
111
|
+
instance_double(
|
112
|
+
PuppetLint::CheckPlugin,
|
113
|
+
:run => [{ :kind => :error, :check => :arrow_alignment }],
|
114
|
+
:fix_problems => [{ :kind => :fixed, :check => :arrow_alignment }],
|
115
|
+
)
|
116
|
+
end
|
117
|
+
let(:mock_hard_tabs) do
|
118
|
+
instance_double(PuppetLint::CheckPlugin, :run => [], :fix_problems => [])
|
119
|
+
end
|
120
|
+
let(:fix_state) { false }
|
121
|
+
|
122
|
+
before(:each) do
|
123
|
+
allow(arrow_alignment_check).to receive(:new).and_return(mock_arrow_alignment)
|
124
|
+
allow(hard_tabs_check).to receive(:new).and_return(mock_hard_tabs)
|
125
|
+
allow(PuppetLint.configuration).to receive(:fix).and_return(fix_state)
|
126
|
+
instance.run(fileinfo, data)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'adds the found problems to the problems array' do
|
130
|
+
expect(instance).to have_attributes(:problems => [{ :kind => :error, :check => :arrow_alignment }])
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'and fix is enabled' do
|
134
|
+
let(:fix_state) { true }
|
135
|
+
|
136
|
+
it 'calls #fix_problems on the check and adds the results to the problems array' do
|
137
|
+
expect(instance).to have_attributes(:problems => [{ :kind => :fixed, :check => :arrow_alignment }])
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'when an unhandled exception is raised' do
|
144
|
+
before do
|
145
|
+
allow(instance).to receive(:load_data).with(fileinfo, data).and_raise(StandardError.new('test message'))
|
146
|
+
allow($stdout).to receive(:puts).with(anything)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'prints out information about the puppet-lint version and ruby environment' do
|
150
|
+
expected_info = [
|
151
|
+
"puppet-lint version: #{PuppetLint::VERSION}",
|
152
|
+
"ruby version: #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
|
153
|
+
"platform: #{RUBY_PLATFORM}",
|
154
|
+
]
|
155
|
+
pattern = expected_info.map { |r| Regexp.escape(r) }.join('\s+')
|
156
|
+
expect($stdout).to receive(:puts).with(a_string_matching(%r{#{pattern}}m))
|
157
|
+
|
158
|
+
expect {
|
159
|
+
instance.run(fileinfo, data)
|
160
|
+
}.to raise_error(SystemExit) { |error|
|
161
|
+
expect(error.status).to eq(1)
|
162
|
+
}
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'prints out the details of the exception raised' do
|
166
|
+
expect($stdout).to receive(:puts).with(a_string_matching(%r{error:\s+```\s+StandardError: test message.+```}m))
|
167
|
+
|
168
|
+
expect {
|
169
|
+
instance.run(fileinfo, data)
|
170
|
+
}.to raise_error(SystemExit) { |error|
|
171
|
+
expect(error.status).to eq(1)
|
172
|
+
}
|
173
|
+
end
|
174
|
+
|
175
|
+
context 'and the file being linted is readable' do
|
176
|
+
before do
|
177
|
+
allow(File).to receive(:readable?).with(fileinfo).and_return(true)
|
178
|
+
allow(File).to receive(:read).with(fileinfo).and_return(data)
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'adds the contents of the file to the bug report' do
|
182
|
+
expect($stdout).to receive(:puts).with("file contents:\n```\n#{data}\n```")
|
183
|
+
|
184
|
+
expect {
|
185
|
+
instance.run(fileinfo, data)
|
186
|
+
}.to raise_error(SystemExit) { |error|
|
187
|
+
expect(error.status).to eq(1)
|
188
|
+
}
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe '#enabled_checks' do
|
195
|
+
subject(:enabled_checks) { instance.enabled_checks }
|
196
|
+
|
197
|
+
let(:expected_enabled_checks) { [:arrow_alignment, :trailing_whitespace] }
|
198
|
+
|
199
|
+
before do
|
200
|
+
PuppetLint.configuration.checks.each do |check|
|
201
|
+
allow(PuppetLint.configuration).to receive("#{check}_enabled?").and_return(expected_enabled_checks.include?(check))
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'checks the configuration for each check to see if it is enabled' do
|
206
|
+
expect(enabled_checks.sort).to eq(expected_enabled_checks.sort)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe '#manifest' do
|
211
|
+
subject(:manifest) { instance.manifest }
|
212
|
+
|
213
|
+
let(:tokens) do
|
214
|
+
[
|
215
|
+
instance_double(PuppetLint::Lexer::Token, :to_manifest => '1'),
|
216
|
+
instance_double(PuppetLint::Lexer::Token, :to_manifest => '2'),
|
217
|
+
instance_double(PuppetLint::Lexer::Token, :to_manifest => '3'),
|
218
|
+
]
|
219
|
+
end
|
220
|
+
|
221
|
+
before do
|
222
|
+
allow(PuppetLint::Data).to receive(:tokens).and_return(tokens)
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'reassembles the manifest from the tokens array' do
|
226
|
+
expect(manifest).to eq('123')
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
@@ -43,15 +43,16 @@ describe PuppetLint::Configuration do
|
|
43
43
|
it 'should be able to set sane defaults' do
|
44
44
|
subject.defaults
|
45
45
|
|
46
|
-
expect(subject.settings).to eq(
|
47
|
-
'with_filename'
|
46
|
+
expect(subject.settings).to eq(
|
47
|
+
'with_filename' => false,
|
48
48
|
'fail_on_warnings' => false,
|
49
|
-
'error_level'
|
50
|
-
'log_format'
|
51
|
-
'with_context'
|
52
|
-
'fix'
|
53
|
-
'show_ignored'
|
54
|
-
'json'
|
55
|
-
|
49
|
+
'error_level' => :all,
|
50
|
+
'log_format' => '',
|
51
|
+
'with_context' => false,
|
52
|
+
'fix' => false,
|
53
|
+
'show_ignored' => false,
|
54
|
+
'json' => false,
|
55
|
+
'ignore_paths' => ['vendor/**/*.pp'],
|
56
|
+
)
|
56
57
|
end
|
57
58
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PuppetLint::Data do
|
4
|
+
subject(:data) { PuppetLint::Data }
|
5
|
+
let(:lexer) { PuppetLint::Lexer.new }
|
6
|
+
|
7
|
+
describe '.insert' do
|
8
|
+
let(:manifest) { '$x = $a' }
|
9
|
+
let(:new_token) { PuppetLint::Lexer::Token.new(:PLUS, '+', 0, 0) }
|
10
|
+
let(:original_tokens) { lexer.tokenise(manifest) }
|
11
|
+
let(:tokens) { original_tokens.dup }
|
12
|
+
before do
|
13
|
+
data.tokens = tokens
|
14
|
+
data.insert(2, new_token)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'adds token at the given index' do
|
18
|
+
expect(data.tokens.map(&:to_manifest).join).to eq('$x += $a')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'sets the prev_token' do
|
22
|
+
expect(new_token.prev_token).to eq(original_tokens[1])
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'sets the prev_code_token' do
|
26
|
+
expect(new_token.prev_code_token).to eq(original_tokens[0])
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'sets the next_token' do
|
30
|
+
expect(new_token.next_token).to eq(original_tokens[2])
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'sets the next_code_token' do
|
34
|
+
expect(new_token.next_code_token).to eq(original_tokens[2])
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'updates the existing next_token' do
|
38
|
+
expect(tokens[1].next_token).to eq(new_token)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'updates the existing next_code_token' do
|
42
|
+
expect(tokens[0].next_code_token).to eq(new_token)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'updates the existing prev_token' do
|
46
|
+
expect(tokens[3].prev_token).to eq(new_token)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'updates the existing prev_code_token' do
|
50
|
+
expect(tokens[3].prev_code_token).to eq(new_token)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '.delete' do
|
55
|
+
let(:manifest) { '$x + = $a' }
|
56
|
+
let(:token) { tokens[2] }
|
57
|
+
let(:original_tokens) { lexer.tokenise(manifest) }
|
58
|
+
let(:tokens) { original_tokens.dup }
|
59
|
+
before do
|
60
|
+
data.tokens = tokens
|
61
|
+
data.delete(token)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'removes the token' do
|
65
|
+
expect(data.tokens.map(&:to_manifest).join).to eq('$x = $a')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'updates the existing next_token' do
|
69
|
+
expect(tokens[1].next_token).to eq(original_tokens[3])
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'updates the existing next_code_token' do
|
73
|
+
expect(tokens[0].next_code_token).to eq(original_tokens[4])
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'updates the existing prev_token' do
|
77
|
+
expect(tokens[2].prev_token).to eq(original_tokens[1])
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'updates the existing prev_code_token' do
|
81
|
+
expect(tokens[3].prev_code_token).to eq(original_tokens[0])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -4,94 +4,102 @@ describe 'quoted_booleans', :type => :lint do
|
|
4
4
|
let(:msg) { 'quoted boolean value found' }
|
5
5
|
|
6
6
|
context 'with a single line ignore' do
|
7
|
-
let(:code)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
let(:code) do
|
8
|
+
<<-END
|
9
|
+
'true'
|
10
|
+
'true' # lint:ignore:quoted_booleans
|
11
|
+
'false'
|
12
|
+
END
|
13
|
+
end
|
12
14
|
|
13
15
|
it 'should detect three problems' do
|
14
16
|
expect(problems).to have(3).problems
|
15
17
|
end
|
16
18
|
|
17
19
|
it 'should have two warnings' do
|
18
|
-
expect(problems).to contain_warning(msg).on_line(
|
19
|
-
expect(problems).to contain_warning(msg).on_line(
|
20
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(9)
|
21
|
+
expect(problems).to contain_warning(msg).on_line(3).in_column(9)
|
20
22
|
end
|
21
23
|
|
22
24
|
it 'should have one ignored problem' do
|
23
|
-
expect(problems).to contain_ignored(msg).on_line(
|
25
|
+
expect(problems).to contain_ignored(msg).on_line(2).in_column(9)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
29
|
context 'with a single line ignore and a reason' do
|
28
|
-
let(:code)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
let(:code) do
|
31
|
+
<<-END
|
32
|
+
'true'
|
33
|
+
'true' # lint:ignore:quoted_booleans some good reason
|
34
|
+
'false'
|
35
|
+
END
|
36
|
+
end
|
33
37
|
|
34
38
|
it 'should detect three problems' do
|
35
39
|
expect(problems).to have(3).problems
|
36
40
|
end
|
37
41
|
|
38
42
|
it 'should have two warnings' do
|
39
|
-
expect(problems).to contain_warning(msg).on_line(
|
40
|
-
expect(problems).to contain_warning(msg).on_line(
|
43
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(9)
|
44
|
+
expect(problems).to contain_warning(msg).on_line(3).in_column(9)
|
41
45
|
end
|
42
46
|
|
43
47
|
it 'should have one ignored problem with a reason' do
|
44
|
-
expect(problems).to contain_ignored(msg).on_line(
|
48
|
+
expect(problems).to contain_ignored(msg).on_line(2).in_column(9).with_reason('some good reason')
|
45
49
|
end
|
46
50
|
end
|
47
51
|
|
48
52
|
context 'with a block ignore' do
|
49
|
-
let(:code)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
let(:code) do
|
54
|
+
<<-END
|
55
|
+
'true'
|
56
|
+
# lint:ignore:quoted_booleans
|
57
|
+
'false'
|
58
|
+
'true'
|
59
|
+
# lint:endignore
|
60
|
+
'true'
|
61
|
+
END
|
62
|
+
end
|
57
63
|
|
58
64
|
it 'should detect four problems' do
|
59
65
|
expect(problems).to have(4).problems
|
60
66
|
end
|
61
67
|
|
62
68
|
it 'should have two warnings' do
|
63
|
-
expect(problems).to contain_warning(msg).on_line(
|
64
|
-
expect(problems).to contain_warning(msg).on_line(
|
69
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(9)
|
70
|
+
expect(problems).to contain_warning(msg).on_line(6).in_column(9)
|
65
71
|
end
|
66
72
|
|
67
73
|
it 'should have two ignored problems' do
|
68
|
-
expect(problems).to contain_ignored(msg).on_line(
|
69
|
-
expect(problems).to contain_ignored(msg).on_line(
|
74
|
+
expect(problems).to contain_ignored(msg).on_line(3).in_column(9)
|
75
|
+
expect(problems).to contain_ignored(msg).on_line(4).in_column(9)
|
70
76
|
end
|
71
77
|
end
|
72
78
|
|
73
79
|
context 'with a block ignore and a reason' do
|
74
|
-
let(:code)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
80
|
+
let(:code) do
|
81
|
+
<<-END
|
82
|
+
'true'
|
83
|
+
# lint:ignore:quoted_booleans another reason
|
84
|
+
'false'
|
85
|
+
'true'
|
86
|
+
# lint:endignore
|
87
|
+
'true'
|
88
|
+
END
|
89
|
+
end
|
82
90
|
|
83
91
|
it 'should detect four problems' do
|
84
92
|
expect(problems).to have(4).problems
|
85
93
|
end
|
86
94
|
|
87
95
|
it 'should have two warnings' do
|
88
|
-
expect(problems).to contain_warning(msg).on_line(
|
89
|
-
expect(problems).to contain_warning(msg).on_line(
|
96
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(9)
|
97
|
+
expect(problems).to contain_warning(msg).on_line(6).in_column(9)
|
90
98
|
end
|
91
99
|
|
92
100
|
it 'should have two ignored problems with a reason' do
|
93
|
-
expect(problems).to contain_ignored(msg).on_line(
|
94
|
-
expect(problems).to contain_ignored(msg).on_line(
|
101
|
+
expect(problems).to contain_ignored(msg).on_line(3).in_column(9).with_reason('another reason')
|
102
|
+
expect(problems).to contain_ignored(msg).on_line(4).in_column(9).with_reason('another reason')
|
95
103
|
end
|
96
104
|
end
|
97
105
|
|
@@ -106,4 +114,27 @@ describe 'quoted_booleans', :type => :lint do
|
|
106
114
|
expect(problems).to contain_ignored(msg).on_line(1).in_column(1).with_reason('a reason')
|
107
115
|
end
|
108
116
|
end
|
117
|
+
|
118
|
+
context 'disable multiple checks in a block' do
|
119
|
+
let(:code) do
|
120
|
+
<<-END
|
121
|
+
|
122
|
+
# lint:ignore:double_quoted_string lint:ignore:quoted_booleans lint:ignore:arrow_alignment
|
123
|
+
foo { "bar":
|
124
|
+
test => 'true',
|
125
|
+
other_test => 'false',
|
126
|
+
}
|
127
|
+
# lint:endignore
|
128
|
+
END
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should detect 2 problems' do
|
132
|
+
expect(problems).to have(2).problems
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should ignore both problems' do
|
136
|
+
expect(problems).to contain_ignored(msg).on_line(4).in_column(19).with_reason('')
|
137
|
+
expect(problems).to contain_ignored(msg).on_line(5).in_column(25).with_reason('')
|
138
|
+
end
|
139
|
+
end
|
109
140
|
end
|