Improve error message on trailing comma in method definition
まだ誰も着手していません。
評価
調査の方向性
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
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ruby/syntax_suggest のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
ruby/syntax_suggest#258 · コメント 6 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
ruby/syntax_suggest#206 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
ruby/syntax_suggest#171 · コメント 3 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
ruby/syntax_suggest#118 · コメント 3 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 45/100
ruby/syntax_suggest#109 · コメント 1 件 ·
ruby/syntax_suggest の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
TheOdinProject/curriculum#31417 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
glossarist/glossarist-ruby#238 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
palladius/rails8-app-on-gcp#145 ·