CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/rubocop/cop/layout/module_description_indentation_spec.rb
Views: 11655
1
# frozen_string_literal: true
2
require 'spec_helper'
3
require 'rubocop/cop/layout/module_description_indentation'
4
5
RSpec.describe RuboCop::Cop::Layout::ModuleDescriptionIndentation do
6
subject(:cop) { described_class.new(config) }
7
let(:config) do
8
RuboCop::Config.new(
9
'Layout/IndentationWidth' => {
10
'Width' => indentation_width
11
})
12
end
13
let(:indentation_width) { 2 }
14
15
it 'accepts descriptions being on one line being on a new line' do
16
expect_no_offenses(<<~RUBY)
17
class DummyModule
18
def initialize(info = {})
19
super(
20
update_info(
21
info,
22
'Name' => 'Simple module name',
23
'Description' => 'Lorem ipsum dolor sit amet',
24
'Author' => [ 'example1', 'example2' ],
25
'License' => MSF_LICENSE,
26
'Platform' => 'win',
27
'Arch' => ARCH_X86,
28
)
29
)
30
end
31
end
32
RUBY
33
end
34
35
it 'accepts descriptions correctly formatted using %q syntax' do
36
expect_no_offenses(<<~RUBY)
37
class DummyModule
38
def initialize(info = {})
39
super(
40
update_info(
41
info,
42
'Name' => 'Simple module name',
43
'Description' => %q{
44
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.
45
Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque
46
eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.
47
},
48
'Author' => [
49
'example1',
50
'example2'
51
],
52
'License' => MSF_LICENSE,
53
'Platform' => 'win',
54
'Arch' => ARCH_X86,
55
)
56
)
57
end
58
end
59
RUBY
60
end
61
62
it 'registers an offense when a multiline description requires a preceding new line' do
63
expect_offense(<<~RUBY)
64
class DummyModule
65
def initialize(info = {})
66
super(
67
update_info(
68
info,
69
'Name' => 'Simple module name',
70
'Description' => %q(Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.
71
Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque
72
eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.),
73
^ Module descriptions should be properly aligned to the 'Description' key, and within %q{ ... }
74
'Author' => [
75
'example1',
76
'example2'
77
],
78
'License' => MSF_LICENSE,
79
'Platform' => 'win',
80
'Arch' => ARCH_X86,
81
)
82
)
83
end
84
end
85
RUBY
86
87
expect_correction(<<~RUBY)
88
class DummyModule
89
def initialize(info = {})
90
super(
91
update_info(
92
info,
93
'Name' => 'Simple module name',
94
'Description' => %q{
95
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.
96
Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque
97
eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.
98
},
99
'Author' => [
100
'example1',
101
'example2'
102
],
103
'License' => MSF_LICENSE,
104
'Platform' => 'win',
105
'Arch' => ARCH_X86,
106
)
107
)
108
end
109
end
110
RUBY
111
end
112
113
it 'registers an offense when a multiline description requires a preceding new line' do
114
expect_offense(<<~RUBY)
115
class DummyModule
116
def initialize(info = {})
117
super(
118
update_info(
119
info,
120
'Name' => 'Simple module name',
121
'Description' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.
122
Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque
123
eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.",
124
^ Module descriptions should be properly aligned to the 'Description' key, and within %q{ ... }
125
'Author' => [
126
'example1',
127
'example2'
128
],
129
'License' => MSF_LICENSE,
130
'Platform' => 'win',
131
'Arch' => ARCH_X86,
132
)
133
)
134
end
135
end
136
RUBY
137
138
expect_correction(<<~RUBY)
139
class DummyModule
140
def initialize(info = {})
141
super(
142
update_info(
143
info,
144
'Name' => 'Simple module name',
145
'Description' => %q{
146
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.
147
Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque
148
eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.
149
},
150
'Author' => [
151
'example1',
152
'example2'
153
],
154
'License' => MSF_LICENSE,
155
'Platform' => 'win',
156
'Arch' => ARCH_X86,
157
)
158
)
159
end
160
end
161
RUBY
162
end
163
164
it 'registers an offense when descriptions are incorrectly indented' do
165
expect_offense(<<~RUBY)
166
class DummyModule
167
def initialize(info = {})
168
super(
169
update_info(
170
info,
171
'Name' => 'Simple module name',
172
'Description' => %q(
173
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.
174
Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque
175
eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.
176
),
177
^ Module descriptions should be properly aligned to the 'Description' key, and within %q{ ... }
178
'Author' => [
179
'example1',
180
'example2'
181
],
182
'License' => MSF_LICENSE,
183
'Platform' => 'win',
184
'Arch' => ARCH_X86,
185
)
186
)
187
end
188
end
189
RUBY
190
191
expect_correction(<<~RUBY)
192
class DummyModule
193
def initialize(info = {})
194
super(
195
update_info(
196
info,
197
'Name' => 'Simple module name',
198
'Description' => %q{
199
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.
200
Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque
201
eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.
202
},
203
'Author' => [
204
'example1',
205
'example2'
206
],
207
'License' => MSF_LICENSE,
208
'Platform' => 'win',
209
'Arch' => ARCH_X86,
210
)
211
)
212
end
213
end
214
RUBY
215
end
216
217
it 'registers an offense when descriptions are incorrectly indented with the merge_info function' do
218
expect_offense(<<~RUBY)
219
class DummyModule
220
def initialize(info = {})
221
super(
222
merge_info(
223
info,
224
'Name' => 'Simple module name',
225
'Description' => %q(
226
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.
227
Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque
228
eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.
229
),
230
^ Module descriptions should be properly aligned to the 'Description' key, and within %q{ ... }
231
'Author' => [
232
'example1',
233
'example2'
234
],
235
'License' => MSF_LICENSE,
236
'Platform' => 'win',
237
'Arch' => ARCH_X86,
238
)
239
)
240
end
241
end
242
RUBY
243
244
expect_correction(<<~RUBY)
245
class DummyModule
246
def initialize(info = {})
247
super(
248
merge_info(
249
info,
250
'Name' => 'Simple module name',
251
'Description' => %q{
252
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.
253
Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque
254
eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.
255
},
256
'Author' => [
257
'example1',
258
'example2'
259
],
260
'License' => MSF_LICENSE,
261
'Platform' => 'win',
262
'Arch' => ARCH_X86,
263
)
264
)
265
end
266
end
267
RUBY
268
end
269
270
it 'registers an offense when there is additional whitespace' do
271
expect_offense(<<~RUBY)
272
class DummyModule
273
def initialize(info = {})
274
super(
275
merge_info(
276
info,
277
'Name' => 'Simple module name',
278
'Description' => %q(
279
280
281
282
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.
283
Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque
284
eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.
285
286
287
288
),
289
^ Module descriptions should be properly aligned to the 'Description' key, and within %q{ ... }
290
'Author' => [
291
'example1',
292
'example2'
293
],
294
'License' => MSF_LICENSE,
295
'Platform' => 'win',
296
'Arch' => ARCH_X86,
297
)
298
)
299
end
300
end
301
RUBY
302
303
expect_correction(<<~RUBY)
304
class DummyModule
305
def initialize(info = {})
306
super(
307
merge_info(
308
info,
309
'Name' => 'Simple module name',
310
'Description' => %q{
311
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.
312
Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque
313
eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.
314
},
315
'Author' => [
316
'example1',
317
'example2'
318
],
319
'License' => MSF_LICENSE,
320
'Platform' => 'win',
321
'Arch' => ARCH_X86,
322
)
323
)
324
end
325
end
326
RUBY
327
end
328
329
it 'registers an offense when the wrong literal type is used' do
330
expect_offense(<<~RUBY)
331
class DummyModule
332
def initialize(info = {})
333
super(
334
update_info(
335
info,
336
'Name' => 'Simple module name',
337
'Description' => %Q(
338
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.
339
Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque
340
eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.
341
),
342
^ Module descriptions should be properly aligned to the 'Description' key, and within %q{ ... }
343
'Author' => [
344
'example1',
345
'example2'
346
],
347
'License' => MSF_LICENSE,
348
'Platform' => 'win',
349
'Arch' => ARCH_X86,
350
)
351
)
352
end
353
end
354
RUBY
355
356
expect_correction(<<~RUBY)
357
class DummyModule
358
def initialize(info = {})
359
super(
360
update_info(
361
info,
362
'Name' => 'Simple module name',
363
'Description' => %q{
364
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.
365
Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque
366
eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.
367
},
368
'Author' => [
369
'example1',
370
'example2'
371
],
372
'License' => MSF_LICENSE,
373
'Platform' => 'win',
374
'Arch' => ARCH_X86,
375
)
376
)
377
end
378
end
379
RUBY
380
end
381
end
382
383