-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #732 from nevir/unit-spec-namefixes
Consistent file naming for specs (and *TernaryOperator cops)
- Loading branch information
Showing
6 changed files
with
46 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# encoding: utf-8 | ||
|
||
module Rubocop | ||
module Cop | ||
module Style | ||
# This cop checks for multi-line ternary op expressions. | ||
class MultilineTernaryOperator < Cop | ||
MSG = | ||
'Avoid multi-line ?: (the ternary operator); use if/unless instead.' | ||
|
||
def on_if(node) | ||
loc = node.loc | ||
|
||
# discard non-ternary ops | ||
return unless loc.respond_to?(:question) | ||
|
||
add_offence(node, :expression) if loc.line != loc.colon.line | ||
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
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 | ||
|
||
require 'spec_helper' | ||
|
||
describe Rubocop::Cop::Style::MultilineTernaryOperator do | ||
subject(:cop) { described_class.new } | ||
|
||
it 'registers offence for a multiline ternary operator expression' do | ||
inspect_source(cop, ['a = cond ?', | ||
' b : c']) | ||
expect(cop.offences.size).to eq(1) | ||
end | ||
|
||
it 'accepts a single line ternary operator expression' do | ||
inspect_source(cop, ['a = cond ? b : c']) | ||
expect(cop.offences).to be_empty | ||
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
File renamed without changes.