Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

End-of-Line comment support for keyword line in clause #95

Closed

Conversation

lemonadern
Copy link
Collaborator

@lemonadern lemonadern commented Sep 5, 2024

概要

JOIN句のキーワードと同行の行末コメントをサポートしました。

select 
    * 
from 
    t1
inner join -- supported!
    t2
on
    t1.num = t2.num
;

副作用

もとはJOIN句のキーワード行末にコメントを書けるようにするタスクでしたが、句をパースしているClause一般の処理へ変更を加えた(commit: Add trailing comment support for a keyword line in Clause)ため、Clauseを利用するほかのフォーマット処理の挙動が変わります。

具体的には次のようになります:

  • キーワードと同行の行末コメント(-- after keyword
    • 変更後:フォーマット後も変わらず行末コメントとして出力されます
    • 変更前:キーワードの次行のコメントとして出力されていました
  • キーワード次行のコメント(-- next line
    • これまでと変わらずキーワードの下にフォーマットされます

入力:

select 
  *
from tbl t
where -- after keyword
-- next line
t.id = 1
;

変更前の挙動:

select
	*
from
	tbl	t
where 
-- after keyword
-- next line
	t.id	=	1
;

変更後の挙動:

select
	*
from
	tbl	t
where -- after keyword
-- next line 
	t.id	=	1
;

既存のテストケースから確認された範囲では、where, union, CASE式の when, then, else で同様の挙動変化が見られます。

そのほかにもClauseを利用して処理されている部分では(visitor側でコメントが考慮されていれば)キーワードと同行の行末コメントが書けるようになります。

@lemonadern lemonadern requested a review from tanzaku September 5, 2024 03:20
@lemonadern lemonadern marked this pull request as ready for review September 5, 2024 03:29
@lemonadern lemonadern removed the request for review from tanzaku September 5, 2024 08:24
@lemonadern
Copy link
Collaborator Author

句ではキーワード直後の行末コメントを次行にフォーマットするよう統一することになったので、こちらの変更はクローズします。
JOINキーワードの後のコメントを書けるようにする修正は #96 です。

@lemonadern lemonadern closed this Sep 5, 2024
@lemonadern lemonadern deleted the trailing-comment-support-for-keyword-line-in-clause branch September 5, 2024 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant