From 4624d7f65862608776741777d52520dcad157eaa Mon Sep 17 00:00:00 2001 From: epaew Date: Wed, 20 May 2020 14:20:47 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Fixup=20ruby/README.md:=20=E9=9D=9E=20Rails?= =?UTF-8?q?=20=E3=83=97=E3=83=AD=E3=82=B8=E3=82=A7=E3=82=AF=E3=83=88?= =?UTF-8?q?=E3=81=AE=E5=A0=B4=E5=90=88=E3=82=82=20vendor/=20=E9=85=8D?= =?UTF-8?q?=E4=B8=8B=E3=81=AF=20RuboCop=20=E5=AF=BE=E8=B1=A1=E5=A4=96?= =?UTF-8?q?=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruby/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ruby/README.md b/ruby/README.md index c641649..e62bca4 100644 --- a/ruby/README.md +++ b/ruby/README.md @@ -57,6 +57,8 @@ AllCops: TargetRubyVersion: 2.7 + Exclude: + - vendor/**/* # 必要な場合は、ここにプロジェクトごとのカスタム設定を書く ``` From 9dcc0184cebd42e81143638051976fddc351f4d5 Mon Sep 17 00:00:00 2001 From: epaew Date: Wed, 20 May 2020 12:15:59 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Layout=20Cops=20=E3=82=92=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruby/rubocop/base.yml | 161 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 159 insertions(+), 2 deletions(-) diff --git a/ruby/rubocop/base.yml b/ruby/rubocop/base.yml index 2e55c7a..98b67d1 100644 --- a/ruby/rubocop/base.yml +++ b/ruby/rubocop/base.yml @@ -9,14 +9,171 @@ require: rubocop-performance ######################################## -# Layout Cops: TODO -######################################## +# Layout Cops +######################################## + +# end の位置は、Block の開始レベルに合わせるi +# - Block の Scope がわかりやすくなる +# +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutblockalignment +# +Layout/BlockAlignment: + EnforcedStyleAlignWith: start_of_block + +# クラス内の要素定義順を、Style Guide の推奨順に強制する +# - 迷いがちなので、強制されたほうが楽 +# +# Style Guide: https://rubystyle.guide/#classes-modules +# Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutclassstructure +# +Layout/ClassStructure: + Enabled: true + +# メソッド定義終了の end の位置は、def の開始レベルに合わせる +# - メソッドの Scope がわかりやすくなる +# +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutdefendalignment +# +Layout/DefEndAlignment: + AutoCorrect: true + EnforcedStyleAlignWith: def + +# AttributeAccessor の定義の前後には空行を入れる +# - NOTE: from 0.83 +# +# Style Guide: https://rubystyle.guide/#empty-lines-around-attribute-accessor +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutemptylinesaroundattributeaccessor +# +Layout/EmptyLinesAroundAttributeAccessor: + Enabled: true + +# end の位置は、if,class などキーワードの開始レベルに合わせる +# - Scope がわかりやすくなる +# - NOTE: AutoCorrect を有効化 +# +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutendalignment +# +Layout/EndAlignment: + AutoCorrect: true + +# 複数行の配列の第1要素の改行時のインデントは、1レベルのみ下げる: +# - 1行あたりの長さを抑えたい +# - Hashのルールに合わせる +# +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutfirstarrayelementindentation +# +Layout/FirstArrayElementIndentation: + EnforcedStyle: consistent + +# 複数行の配列の第1要素は必ず改行後に書く: +# - Hash、メソッド引数のルールに合わせる +# +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutfirstarrayelementlinebreak +# +Layout/FirstArrayElementLineBreak: + Enabled: true + +# 複数行のHashの第1要素の改行時のインデントは、1レベルのみ下げる: +# - 1行あたりの長さを抑えたい +# - 配列のルールに合わせる +# +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutfirsthashelementindentation +# +Layout/FirstHashElementIndentation: + EnforcedStyle: consistent + +# 複数行のHashの第1要素は必ず改行後に書く: +# - 配列、メソッド引数のルールに合わせる +# +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutfirsthashelementlinebreak +# +Layout/FirstHashElementLineBreak: + Enabled: true + +# メソッド引数が複数行に渡る場合、第1引数は必ず改行後に書く: +# - 配列、Hashのルールに合わせる +# +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutfirstmethodargumentlinebreak +# +Layout/FirstMethodArgumentLineBreak: + Enabled: true + +# メソッド引数の定義が複数行に渡る場合、第1引数は必ず改行後に書く: +# - 配列、Hashのルールに合わせる +# +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutfirstmethodparameterlinebreak +# +Layout/FirstMethodParameterLineBreak: + Enabled: true + +# HashのKey, Valueの揃え方: +# - Key, Value ともに頭を揃える +# +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layouthashalignment +# +Layout/HashAlignment: + EnforcedColonStyle: table + EnforcedHashRocketStyle: table + +# メソッド引数に Heredoc が含まれる場合、メソッド引数の閉じ括弧はHeredocの開始よりも前に書く +# +# Style Guide: https://rubystyle.guide/#heredoc-argument-closing-parentheses +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutheredocargumentclosingparenthesis +# +Layout/HeredocArgumentClosingParenthesis: + Enabled: true + +# TODO: 1 行あたりの最大文字数を100文字とする。 +# - Style Guideでは80文字だが、80文字だと少し短いことが多い +# +# Style Guide: https://rubystyle.guide/#80-character-limits +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutlinelength +# +Layout/LineLength: + Max: 100 + +# メソッド呼び出しを複数行に渡りChainする場合、メソッドの呼び出しはレシーバーよりインデントを1レベル下げる +# - インデントしない場合、行継続かどうかがパッと見でわかりづらい +# +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutmultilinemethodcallindentation +# +Layout/MultilineMethodCallIndentation: + EnforcedStyle: indented_relative_to_receiver + +# if, return 等の引数を複数行に渡って書く場合、2行目以降のインデントを1レベル下げる +# - 同上 +# +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutmultilineoperationindentation +# +Layout/MultilineOperationIndentation: + EnforcedStyle: indented + +# メソッド呼び出し時に、.とメソッド名の間にスペースを入れない +# - NOTE: from 0.82 +# +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutspacearoundmethodcalloperator +# +Layout/SpaceAroundMethodCallOperator: + Enabled: true + +# 行末のスペースを許可しない +# - NOTE: Heredoc の中でも許可しない(Markdownなどを書くときは magic comment で個別に disable する) +# +# RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layouttrailingwhitespace +# +Layout/TrailingWhitespace: + AllowInHeredoc: false ######################################## # Linting Cops: TODO ######################################## +# +# +# RuboCop Docs: +# + ######################################## # Metrics Cops: TODO From aa8952b3fd3eab49b03c2c0b376365ba781b088f Mon Sep 17 00:00:00 2001 From: epaew Date: Fri, 22 May 2020 13:28:44 +0900 Subject: [PATCH 3/3] Update ruby/rubocop/base.yml - fix typo - Set Layout/LineLength.Max to 120 --- ruby/rubocop/base.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ruby/rubocop/base.yml b/ruby/rubocop/base.yml index 98b67d1..8c638c7 100644 --- a/ruby/rubocop/base.yml +++ b/ruby/rubocop/base.yml @@ -12,7 +12,7 @@ require: rubocop-performance # Layout Cops ######################################## -# end の位置は、Block の開始レベルに合わせるi +# end の位置は、Block の開始レベルに合わせる # - Block の Scope がわかりやすくなる # # RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutblockalignment @@ -123,14 +123,14 @@ Layout/HashAlignment: Layout/HeredocArgumentClosingParenthesis: Enabled: true -# TODO: 1 行あたりの最大文字数を100文字とする。 -# - Style Guideでは80文字だが、80文字だと少し短いことが多い +# 1 行あたりの最大文字数を120文字とする。 +# - RuboCop のデフォルト(> 0.84.0)に合わせる # # Style Guide: https://rubystyle.guide/#80-character-limits # RuboCop Docs: https://docs.rubocop.org/en/stable/cops_layout/#layoutlinelength # Layout/LineLength: - Max: 100 + Max: 120 # メソッド呼び出しを複数行に渡りChainする場合、メソッドの呼び出しはレシーバーよりインデントを1レベル下げる # - インデントしない場合、行継続かどうかがパッと見でわかりづらい