Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/rubocop/cop/layout/module_description_indentation_spec.rb
Views: 11655
# frozen_string_literal: true1require 'spec_helper'2require 'rubocop/cop/layout/module_description_indentation'34RSpec.describe RuboCop::Cop::Layout::ModuleDescriptionIndentation do5subject(:cop) { described_class.new(config) }6let(:config) do7RuboCop::Config.new(8'Layout/IndentationWidth' => {9'Width' => indentation_width10})11end12let(:indentation_width) { 2 }1314it 'accepts descriptions being on one line being on a new line' do15expect_no_offenses(<<~RUBY)16class DummyModule17def initialize(info = {})18super(19update_info(20info,21'Name' => 'Simple module name',22'Description' => 'Lorem ipsum dolor sit amet',23'Author' => [ 'example1', 'example2' ],24'License' => MSF_LICENSE,25'Platform' => 'win',26'Arch' => ARCH_X86,27)28)29end30end31RUBY32end3334it 'accepts descriptions correctly formatted using %q syntax' do35expect_no_offenses(<<~RUBY)36class DummyModule37def initialize(info = {})38super(39update_info(40info,41'Name' => 'Simple module name',42'Description' => %q{43Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.44Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque45eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.46},47'Author' => [48'example1',49'example2'50],51'License' => MSF_LICENSE,52'Platform' => 'win',53'Arch' => ARCH_X86,54)55)56end57end58RUBY59end6061it 'registers an offense when a multiline description requires a preceding new line' do62expect_offense(<<~RUBY)63class DummyModule64def initialize(info = {})65super(66update_info(67info,68'Name' => 'Simple module name',69'Description' => %q(Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.70Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque71eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.),72^ Module descriptions should be properly aligned to the 'Description' key, and within %q{ ... }73'Author' => [74'example1',75'example2'76],77'License' => MSF_LICENSE,78'Platform' => 'win',79'Arch' => ARCH_X86,80)81)82end83end84RUBY8586expect_correction(<<~RUBY)87class DummyModule88def initialize(info = {})89super(90update_info(91info,92'Name' => 'Simple module name',93'Description' => %q{94Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.95Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque96eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.97},98'Author' => [99'example1',100'example2'101],102'License' => MSF_LICENSE,103'Platform' => 'win',104'Arch' => ARCH_X86,105)106)107end108end109RUBY110end111112it 'registers an offense when a multiline description requires a preceding new line' do113expect_offense(<<~RUBY)114class DummyModule115def initialize(info = {})116super(117update_info(118info,119'Name' => 'Simple module name',120'Description' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.121Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque122eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.",123^ Module descriptions should be properly aligned to the 'Description' key, and within %q{ ... }124'Author' => [125'example1',126'example2'127],128'License' => MSF_LICENSE,129'Platform' => 'win',130'Arch' => ARCH_X86,131)132)133end134end135RUBY136137expect_correction(<<~RUBY)138class DummyModule139def initialize(info = {})140super(141update_info(142info,143'Name' => 'Simple module name',144'Description' => %q{145Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.146Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque147eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.148},149'Author' => [150'example1',151'example2'152],153'License' => MSF_LICENSE,154'Platform' => 'win',155'Arch' => ARCH_X86,156)157)158end159end160RUBY161end162163it 'registers an offense when descriptions are incorrectly indented' do164expect_offense(<<~RUBY)165class DummyModule166def initialize(info = {})167super(168update_info(169info,170'Name' => 'Simple module name',171'Description' => %q(172Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.173Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque174eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.175),176^ Module descriptions should be properly aligned to the 'Description' key, and within %q{ ... }177'Author' => [178'example1',179'example2'180],181'License' => MSF_LICENSE,182'Platform' => 'win',183'Arch' => ARCH_X86,184)185)186end187end188RUBY189190expect_correction(<<~RUBY)191class DummyModule192def initialize(info = {})193super(194update_info(195info,196'Name' => 'Simple module name',197'Description' => %q{198Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.199Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque200eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.201},202'Author' => [203'example1',204'example2'205],206'License' => MSF_LICENSE,207'Platform' => 'win',208'Arch' => ARCH_X86,209)210)211end212end213RUBY214end215216it 'registers an offense when descriptions are incorrectly indented with the merge_info function' do217expect_offense(<<~RUBY)218class DummyModule219def initialize(info = {})220super(221merge_info(222info,223'Name' => 'Simple module name',224'Description' => %q(225Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.226Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque227eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.228),229^ Module descriptions should be properly aligned to the 'Description' key, and within %q{ ... }230'Author' => [231'example1',232'example2'233],234'License' => MSF_LICENSE,235'Platform' => 'win',236'Arch' => ARCH_X86,237)238)239end240end241RUBY242243expect_correction(<<~RUBY)244class DummyModule245def initialize(info = {})246super(247merge_info(248info,249'Name' => 'Simple module name',250'Description' => %q{251Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.252Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque253eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.254},255'Author' => [256'example1',257'example2'258],259'License' => MSF_LICENSE,260'Platform' => 'win',261'Arch' => ARCH_X86,262)263)264end265end266RUBY267end268269it 'registers an offense when there is additional whitespace' do270expect_offense(<<~RUBY)271class DummyModule272def initialize(info = {})273super(274merge_info(275info,276'Name' => 'Simple module name',277'Description' => %q(278279280281Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.282Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque283eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.284285286287),288^ Module descriptions should be properly aligned to the 'Description' key, and within %q{ ... }289'Author' => [290'example1',291'example2'292],293'License' => MSF_LICENSE,294'Platform' => 'win',295'Arch' => ARCH_X86,296)297)298end299end300RUBY301302expect_correction(<<~RUBY)303class DummyModule304def initialize(info = {})305super(306merge_info(307info,308'Name' => 'Simple module name',309'Description' => %q{310Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.311Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque312eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.313},314'Author' => [315'example1',316'example2'317],318'License' => MSF_LICENSE,319'Platform' => 'win',320'Arch' => ARCH_X86,321)322)323end324end325RUBY326end327328it 'registers an offense when the wrong literal type is used' do329expect_offense(<<~RUBY)330class DummyModule331def initialize(info = {})332super(333update_info(334info,335'Name' => 'Simple module name',336'Description' => %Q(337Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.338Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque339eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.340),341^ Module descriptions should be properly aligned to the 'Description' key, and within %q{ ... }342'Author' => [343'example1',344'example2'345],346'License' => MSF_LICENSE,347'Platform' => 'win',348'Arch' => ARCH_X86,349)350)351end352end353RUBY354355expect_correction(<<~RUBY)356class DummyModule357def initialize(info = {})358super(359update_info(360info,361'Name' => 'Simple module name',362'Description' => %q{363Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque efficitur pulvinar arcu eget ultrices.364Vestibulum at risus at nisi convallis laoreet a sed libero. Nam vestibulum euismod dictum. Pellentesque365eu nunc vitae mi volutpat viverra in id ipsum. Maecenas fermentum condimentum dapibus.366},367'Author' => [368'example1',369'example2'370],371'License' => MSF_LICENSE,372'Platform' => 'win',373'Arch' => ARCH_X86,374)375)376end377end378RUBY379end380end381382383