Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Improve error message on trailing comma in method definition

オープン
#205 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
ruby
領域
compilers

調査の方向性

exe/syntax_suggest を使い、/tmp/bad.rb の例で再現するところから始め、その後、末尾のコンマを削除したバージョンと出力を比較します。エラー報告の経路を追跡して、このケースがどこでより明確な診断を受けられるかを特定します。無効な例が、紛らわしい unexpected-colon エラーではなく末尾のコンマを報告すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

The error produced by this (invalid) code is confusing and not helpful:

def run_build_script(
   workspace_dir: ARGV[0],
   output_dir: ARGV[1],
   cache_dir: ARGV[2],
   stack: ENV.fetch("STACK"),
   ruby_version: ENV.fetch("STACK"),
   io: STDOUT,
)
 end
$ exe/syntax_suggest /tmp/bad.rb
--> /tmp/bad.rb

syntax error, unexpected ':', expecting end-of-input

  1  def run_build_script(
> 2     workspace_dir: ARGV[0],
> 3     output_dir: ARGV[1],
> 4     cache_dir: ARGV[2],
> 5     stack: ENV.fetch("STACK"),
> 6     ruby_version: ENV.fetch("STACK"),
> 7     io: STDOUT,
  8  )

The problem is that there's a trailing comma. This code works (when you remove the comma after STDOUT):

$ cat /tmp/bad.rb
def run_build_script(
   workspace_dir: ARGV[0],
   output_dir: ARGV[1],
   cache_dir: ARGV[2],
   stack: ENV.fetch("STACK"),
   ruby_version: ENV.fetch("STACK"),
   io: STDOUT
)
 end
$ exe/syntax_suggest /tmp/bad.rb
Syntax OK

Fix Idea(s)

I'm not sure how to approach this. Possibly we could check for some variation of this regex https://rubular.com/r/aocG0GtGFjEiG2 as a brute force check. There may be a more elegant option.

Sidebar: I would love to see trailing commas allowed in method definitions. I think adding this behavior is an issue for positional args as you want that feedback that your airity is off. Idea: Allow it if and only if the method ends in a kwarg (instead of a positional arg). I don't know if it's been discussed or not.

主要言語
Ruby
スター
350
フォーク
17
平均マージ
48分
マージ済み PR(30日)
5

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ruby/syntax_suggest のほかの issue

ruby/syntax_suggest の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。