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

formatter cause syntax error. #14609

Open
zw963 opened this issue May 22, 2024 · 2 comments
Open

formatter cause syntax error. #14609

zw963 opened this issue May 22, 2024 · 2 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:tools:formatter

Comments

@zw963
Copy link
Contributor

zw963 commented May 22, 2024

Bug Report

Following is a valid crystal script.

foo.cr

    foo do
      bar(
        script: "on change put my.value1 into the previous <span/>",
#         script: "
# on change set (previous <input/>).value and (previous <span/>).innerHTML to my.value1
# "
      ) do
      end
    end

But, after format, get following invalid expression.

 ╰─ $ cat foo.cr |crystal tool format -
foo do
  bar(
    script: "on change put my.value1 into the previous <span/>" #         script: "
  # on change set (previous <input/>).value and (previous <span/>).innerHTML to my.value1
  # "
,
  ) do
  end
end
In foo.cr:6:1

 6 | ,
     ^
Error: expecting token ')', not ','

Thanks

@zw963 zw963 added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label May 22, 2024
@zw963
Copy link
Contributor Author

zw963 commented May 23, 2024

Can be reduced:

Before

foo do
      bar(
        arg1: "",
        # arg2: ""
      ) do
      end
    end

After

foo do
  bar(
    arg1: "" # arg2: ""
,
  ) do
  end
end

@straight-shoota
Copy link
Member

This looks like two bug: The formatter should not butcher full-line comments in an argument list. But the parser should also be able to read the resulting code. There's nothing wrong with it.

So keeping this issue focussed on the formatter, I created #14616 for the parser bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:tools:formatter
Projects
None yet
Development

No branches or pull requests

3 participants