このコミットが含まれているのは:
2026-07-14 18:39:24 +09:00
コミット d035da99ad
14個のファイルの変更188行の追加232行の削除
+56 -124
ファイルの表示
@@ -141,140 +141,72 @@ npm run preview
- Ruby の multi-line hash literal / keyword-like argument hash では、opening
`{` を最初の pair と同じ行に置き、closing `}` を最後の pair と同じ行に
置く。Prettier 的な縦開き・縦閉じをしない。
- Ruby の `if` / `unless` / `case` 条件で、複数行に分けるだけで安易に
`if ... end` へ展開しない。局所の既存コードが modifier 形式ならそれに
そろえる。
- Ruby の guard 条件は、1 行で収まるなら modifier 形式を優先する。2 行以上に
なるなら通常の block 形式へ切り替へてよい。
- Ruby の method chain や call argument を折り返す際、call-site の `)`
直前で行を空けたり、closing delimiter を block のやうに独立させない。
- Ruby の guard 条件は、1 行で収まるなら modifier 形式を優先する。
99 文字を超えるなら block 形式へ切り替へるか、message 定数化などで縮める。
- Ruby の method chain や call argument を折り返す際、call-site の `)`
block close のやうに独立させない。
Bad:
```rb
source =
if params[:format] == 'google_sheets'
PostImportGoogleSheetsFetcher.fetch!(params[:source],
rate_key: current_user.id)
else
params[:source]
end
parsed = PostImportSourceParser.new(
source:,
format:,
has_header: params[:has_header],
json_path: params[:json_path],
).parse
```
Good:
```rb
source =
if params[:format] == 'google_sheets'
PostImportGoogleSheetsFetcher.fetch!(params[:source],
rate_key: current_user.id)
else
params[:source]
end
parsed = PostImportSourceParser.new(
source:,
format:,
has_header: params[:has_header],
json_path: params[:json_path]).parse
```
Bad:
```rb
result[field] = {
'kind' => kind,
'value' => value['value'].to_s,
'columns' => Array(columns).map { Integer(_1) },
}
```
Good:
```rb
result[field] = {
'kind' => kind,
'value' => value['value'].to_s,
'columns' => Array(columns).map { Integer(_1) } }
```
Bad:
```rb
unless rows.all? { |row|
values = Array(row['values'])
values.length <= columns.length &&
values.all? { |value|
value.is_a?(String) &&
value.bytesize <= PostImportSourceParser::MAX_CELL_BYTES
}
}
raise ArgumentError, '解析結果のセルが不正です.'
end
```
Good:
```rb
raise ArgumentError, '解析結果のセルが不正です.' unless rows.all? { |row|
values = Array(row['values'])
values.length <= columns.length && values.all? { |value|
value.is_a?(String) && value.bytesize <= PostImportSourceParser::MAX_CELL_BYTES
}
}
```
Bad:
```rb
if row['url'].to_s.bytesize > PostImportSourceParser::MAX_CELL_BYTES
raise ArgumentError, 'URL が長すぎます.'
end
```
Good:
```rb
raise ArgumentError, 'URL が長すぎます.' if row['url'].to_s.bytesize > PostImportSourceParser::MAX_CELL_BYTES
```
Bad:
```rb
parameters = row.is_a?(ActionController::Parameters) ? row :
ActionController::Parameters.new(row)
```
Good:
```rb
parameters =
row.is_a?(ActionController::Parameters) ? row : ActionController::Parameters.new(row)
```
Bad:
```rb
PostTagSection.create!(
post_id: post.id,
tag_id:,
begin_ms:,
end_ms:,
response = Example.fetch(
value,
option: option,
)
```
Good:
```rb
PostTagSection.create!(post_id: post.id,
tag_id:,
begin_ms:,
end_ms:)
response = Example.fetch(
value,
option: option)
```
Bad:
```rb
payload = {
title: title,
url: url,
}
```
Good:
```rb
payload = {
title: title,
url: url }
```
Bad:
```rb
raise ArgumentError, 'URL が長すぎます.' if url.bytesize > MAX_URL_BYTES && flag.present?
```
Good:
```rb
if url.bytesize > MAX_URL_BYTES && flag.present?
raise ArgumentError, 'URL が長すぎます.'
end
```
Bad:
```rb
records.each {
do_work(_1) }
```
Good:
```rb
records.each {
do_work(_1)
}
```
- TypeScript and Python: use GNU-style spacing before parentheses where
syntactically valid.