Last active
May 24, 2016 05:02
-
-
Save YumaInaura/d6154e5a3b261a065ab2 to your computer and use it in GitHub Desktop.
Rubocop がチェックしてくれるもの一覧表 (Style編) ref: http://qiita.com/Yinaura/items/9928e32fa9fc9092f24c
This file contains hidden or 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
#例: | |
Style/RegexpLiteral: | |
EnforcedStyle: percent_r |
This file contains hidden or 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
# bad | |
class SomeClass | |
private | |
def private_method | |
# ... | |
end | |
end | |
# good | |
class SomeClass | |
private | |
def private_method | |
# ... | |
end | |
end |
This file contains hidden or 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
# bad | |
def set_attribute(value) ... | |
# good | |
def attribute=(value) | |
# bad | |
def get_attribute ... | |
# good | |
def attribute ... |
This file contains hidden or 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
# bad | |
$ORIGINAL_PATH = '/path/to/user' | |
puts $ORIGINAL_PATH | |
# good | |
puts $LOAD_PATH |
This file contains hidden or 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
# bad | |
hash = { :kind => 'Apple' } | |
# good | |
hash = { kind: 'Apple' } | |
This file contains hidden or 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
def test | |
puts 'hello' | |
- puts 'world' | |
+ puts 'world' | |
end |
This file contains hidden or 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
# bad | |
def test | |
puts 'hello' | |
end | |
# good | |
def test | |
puts 'hello' | |
end |
This file contains hidden or 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
# bad | |
if cond then | |
end | |
# good | |
if cond | |
end | |
# good | |
if cond then a | |
elsif cond then b | |
end |
This file contains hidden or 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
- expect{ subject } | |
+ expect { subject } |
This file contains hidden or 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
# bad | |
true ? | |
yes : | |
no | |
# good | |
true ? yes : no | |
# good | |
if true | |
yes | |
else | |
no | |
end |
This file contains hidden or 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
# bad | |
some_str = 'ala' + | |
'bala' | |
some_str = 'ala' << | |
'bala' | |
# good | |
some_str = 'ala' \ | |
'bala' |
This file contains hidden or 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
# bad | |
def some_method() | |
# body omitted | |
end | |
# good | |
def some_method | |
# body omitted | |
end | |
# bad | |
def some_method_with_parameters param1, param2 | |
# body omitted | |
end | |
# good | |
def some_method_with_parameters(param1, param2) | |
# body omitted | |
end |
This file contains hidden or 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
# bad | |
def ExampleMethod | |
end | |
# good | |
def example_method | |
end |
This file contains hidden or 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
# 悪い例 | |
%w(one two three) * ', ' | |
# => 'one, two, three' | |
# 良い例 | |
%w(one two three).join(', ') | |
# => 'one, two, three' | |
This file contains hidden or 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
# bad | |
if x != nil | |
if !x.nil? | |
# good | |
if x |
This file contains hidden or 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
# good | |
def signed_in? | |
!current_user.nil? | |
end |
This file contains hidden or 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
# bad | |
if (a && b) | |
end | |
# good | |
if a && b | |
end | |
# good | |
if (a && b) || c | |
end |
This file contains hidden or 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
# bad | |
def is_even?(value) ... | |
# good | |
def even?(value) | |
# bad | |
def has_value? ... | |
# good | |
def value? ... |
This file contains hidden or 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
def redundant | |
begin | |
ala | |
bala | |
rescue StandardError => e | |
something | |
end | |
end | |
def preferred | |
ala | |
bala | |
rescue StandardError => e | |
something | |
end |
This file contains hidden or 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
# bad | |
raise RuntimeError, 'message' | |
# good - signals a RuntimeError by default | |
raise 'message' |
This file contains hidden or 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
# maybe bad | |
def test | |
return something | |
end | |
# maybe good | |
def test | |
something | |
end | |
This file contains hidden or 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
# bad | |
begin | |
something | |
rescue | |
puts 'error' | |
end | |
# good | |
begin | |
something | |
rescue | |
puts 'error' | |
end |
This file contains hidden or 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
# EnforcedStyle の設定が slashes / mixed の場合は良い。 percent_r の場合は悪い。 | |
snake_case = /^[\dA-Z_]+$/ | |
# EnforcedStyle の設定が percent_r の場合は良い。 slashes / mixed の場合は悪い。 | |
snake_case = %r{^[\dA-Z_]+$} | |
# EnforcedStyle の設定が slashes の場合は良い。 percent_r / mixed の場合は悪い。 | |
regex = / | |
foo | |
(bar) | |
(baz) | |
/x | |
# EnforcedStyle の設定が percent_r / mixed の場合は良い。 slashes の場合は悪い。 | |
regex = %r{ | |
foo | |
(bar) | |
(baz) | |
}x | |
# スラッシュ記法の中でスラッシュを使わないこと。 | |
# AllowInnerSlashes の設定を true にしていれば警告しない。 | |
x =~ /home\// |
This file contains hidden or 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
# EnforcedStyle の設定が slashes / mixed の場合は良い。 percent_r の場合は悪い。 | |
snake_case = /^[\dA-Z_]+$/ | |
# EnforcedStyle の設定が percent_r の場合は良い。 slashes / mixed の場合は悪い。 | |
snake_case = %r{^[\dA-Z_]+$} | |
# EnforcedStyle の設定が slashes の場合は良い。 percent_r / mixed の場合は悪い。 | |
regex = / | |
foo | |
(bar) | |
(baz) | |
/x | |
# EnforcedStyle の設定が percent_r / mixed の場合は良い。 slashes の場合は悪い。 | |
regex = %r{ | |
foo | |
(bar) | |
(baz) | |
}x | |
# スラッシュ記法の中でスラッシュを使わないこと。 | |
# AllowInnerSlashes の設定を true にしていれば警告しない。 | |
x =~ /home\// |
This file contains hidden or 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
# bad | |
if x = 1 | |
end |
This file contains hidden or 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
# bad | |
x = x + 1 | |
# good | |
x += 1 |
This file contains hidden or 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
# bad | |
def method; nil; end | |
# good | |
def method | |
nil | |
end |
This file contains hidden or 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
# bad | |
x = 1;y = 2 | |
# good | |
x = 1; y = 2 |
This file contains hidden or 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
# bad | |
hash.map! {|k, v|v } | |
# bad | |
hash.map { | k, v | v } | |
# good | |
hash.map { |k, v| v } |
This file contains hidden or 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
#bad | |
['Apple','Banana','Strawberry'] | |
#good | |
['Apple', 'Banana', 'Strawberry'] |
This file contains hidden or 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
# bad | |
if(a && b) || c then result end | |
# good_ | |
if (a && b) || c then result end |
This file contains hidden or 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
# bad | |
def func (x) | |
end | |
# good | |
def func(x) | |
end |
This file contains hidden or 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
# bad | |
! something | |
# good | |
!something |
This file contains hidden or 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
# bad | |
x = 1;y = 2; | |
# good | |
x = 1; y = 2; |
This file contains hidden or 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
# bad | |
def example(value='') | |
end | |
# good | |
def example(value = '') | |
end |
This file contains hidden or 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
# 例 | |
attr_accessor :getter_with_setter | |
attr_reader :getter1, :getter2, :getter3 | |
attr_writer :setter1, :setter2, :setter3 |
This file contains hidden or 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
# bad | |
x=1+1 | |
# bad | |
x = 1 + 1 | |
# good | |
x = 1 + 1 |
This file contains hidden or 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
# bad | |
x = 2 ** 3 | |
# good | |
x = 2**3 |
This file contains hidden or 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
# bad | |
(1..10).each{ |i| i } | |
# good | |
(1..10).each { |i| i } |
This file contains hidden or 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
# bad | |
method# Comment | |
# good | |
method # Comment |
This file contains hidden or 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
# bad | |
result if(a && b) || c | |
# good | |
result if (a && b) || c |
This file contains hidden or 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
# bad | |
(1..10).each {|i| i} | |
# good | |
(1..10).each { |i| i } |
This file contains hidden or 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
# bad | |
furuits = {apple: 10, banana: 20} | |
# good | |
furuits = { apple: 10, banana: 20 } |
This file contains hidden or 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
# bad | |
some( arg ).other | |
[ 1, 2, 3 ].size | |
# good | |
some(arg).other | |
[1, 2, 3].size |
This file contains hidden or 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
# bad | |
1 .. 3 | |
# good | |
1..3 | |
# bad | |
'a' .. 'z' | |
# good | |
'a'..'z' |
This file contains hidden or 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
$: => $LOAD_PATH | |
$" => $LOADED_FEATURES | |
$0 => $PROGRAM_NAME | |
$! => $ERROR_INFO | |
$@ => $ERROR_POSITION | |
$; => $FIELD_SEPARATOR / $FS | |
$, => $OUTPUT_FIELD_SEPARATOR / $OFS | |
$/ => $INPUT_RECORD_SEPARATOR / $RS | |
$\\ => $OUTPUT_RECORD_SEPARATOR / $ORS | |
$. => $INPUT_LINE_NUMBER / $NR | |
$_ => $LAST_READ_LINE | |
$> => $DEFAULT_OUTPUT | |
$< => $DEFAULT_INPUT | |
$$ => $PROCESS_ID / $PID | |
$? => $CHILD_STATUS | |
$~ => $LAST_MATCH_INFO | |
$= => $IGNORECASE | |
$* => $ARGV => / => ARGV | |
$& => $MATCH | |
$` => $PREMATCH | |
$\' => $POSTMATCH | |
$+ => $LAST_PAREN_MATCH | |
This file contains hidden or 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
# 悪い例 | |
== begin | |
comment line | |
another comment line | |
== end | |
# 良い例 | |
# comment line | |
# another comment line |
This file contains hidden or 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
# bad | |
:symbol" | |
# good | |
:symbol |
This file contains hidden or 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
# bad | |
something.map { |s| s.upcase } | |
# good | |
something.map(&:upcase) |
This file contains hidden or 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
# maybe bad | |
x_ = 1 |
This file contains hidden or 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
# bad | |
class Foo | |
def example=(value) | |
@example = value | |
end | |
def example | |
@example | |
end | |
end | |
# good | |
class Foo | |
attr_accessor :example | |
end |
This file contains hidden or 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
# bad | |
someVar = 5 | |
# good | |
some_var = 5 |
This file contains hidden or 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
# bad | |
when x; apple | |
# good | |
when x then apple |
This file contains hidden or 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
# bad | |
while x > 5 do | |
# body omitted | |
end | |
until x > 5 do | |
# body omitted | |
end | |
# good | |
while x > 5 | |
# body omitted | |
end | |
until x > 5 | |
# body omitted | |
end |
This file contains hidden or 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
# bad | |
class Example | |
def some_method(argument1, argument2, argument3, argument4, argument5, argument6) | |
end | |
end |
This file contains hidden or 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
# bad | |
case | |
when song.name == 'Misty' | |
puts 'Not again!' | |
when song.duration > 120 | |
puts 'Too long!' | |
when Time.now.hour > 21 | |
puts "It's too late" | |
else | |
song.play | |
end | |
# good | |
case | |
when song.name == 'Misty' | |
puts 'Not again!' | |
when song.duration > 120 | |
puts 'Too long!' | |
when Time.now.hour > 21 | |
puts "It's too late" | |
else | |
song.play | |
end |
This file contains hidden or 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
# bad | |
#FIXME Comment | |
# good | |
# FIXME: Comment |
This file contains hidden or 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
some_array = [] | |
some_hash = {} | |
some_string = '' |
This file contains hidden or 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
# bad | |
if x % 2 == 0 | |
# good | |
if x.even? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment