Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# encoding: utf-8 | ||
|
||
module Rubocop | ||
module Cop | ||
module Style | ||
# This cop checks for BEGIN blocks. | ||
class EndBlock < Cop | ||
MSG = 'Avoid the use of END blocks. Use `Kernel#at_exit` instead.' | ||
|
||
def on_postexe(node) | ||
add_offence(:convention, node.loc.expression, MSG) | ||
|
||
super | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
module Rubocop | ||
module Cop | ||
module Style | ||
describe EndBlock do | ||
let(:cop) { EndBlock.new } | ||
|
||
it 'reports an offence for an END block' do | ||
src = ['END { test }'] | ||
inspect_source(cop, src) | ||
expect(cop.offences.size).to eq(1) | ||
end | ||
end | ||
end | ||
end | ||
end |