Skip to content

Autoformat removes new-line before EOF #1487

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

Closed
3 tasks done
kaysievers opened this issue Sep 23, 2022 · 1 comment · Fixed by #1623
Closed
3 tasks done

Autoformat removes new-line before EOF #1487

kaysievers opened this issue Sep 23, 2022 · 1 comment · Fixed by #1623
Assignees
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@kaysievers
Copy link

Describe the problem

The autoformat feature removes the last line's new-line, disturbs all sorts of diff / git tools.

Quoting the C++ standard: A source file that is not empty and that does not end in a new-line character, or that ends in a splice, shall be processed as if an additional new-line character were appended to the file.

Could this be changed to leave the new-line in place, or maybe even add one if it is missing?

Thanks!

Example:
Screen Shot 2022-09-23 at 11 51 35

To reproduce

Press CMD-T and save. Look at the last character in the sketch file.

Expected behavior

Leave the new-line before EOF in place.

Arduino IDE version

2.0-nightly-202209

Operating system

macOS

Operating system version

12.6

Additional context

No response

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest nightly build
  • My report contains all necessary details
@kaysievers kaysievers added the type: imperfection Perceived defect in any part of project label Sep 23, 2022
@per1234 per1234 added the topic: code Related to content of the project itself label Sep 23, 2022
@per1234
Copy link
Contributor

per1234 commented Sep 23, 2022

Thanks for reporting this @kaysievers. The ClangFormat formatting tool used by Arduino IDE 2.x does not remove the newline, so it is a bug in the Arduino IDE code itself.

maybe even add one if it is missing?

Surprisingly for such a comprehensive tool, ClangFormat doesn't provide this capability:

llvm/llvm-project#38042

Also surprising is that the Eclipse Theia IDE framework Arduino IDE 2.x is built on doesn't provide an setting for this, as VS Code does with its files.insertFinalNewline.


I think there is a way for the user to set up Arduino IDE 2.x do this, which would even counteract the formatter's current removal of the newline. However, discussion of that is not really appropriate for the issue tracker. I'm certain that if you post over on the Arduino forum someone will provide you with instructions:

https://forum.arduino.cc/c/software/arduino-ide-2-0/93

kittaakos pushed a commit that referenced this issue Nov 3, 2022
Otherwise, it always causes a _no newline at the end of file_ problem.

Closes #1487

Signed-off-by: Akos Kitta <[email protected]>
kittaakos pushed a commit that referenced this issue Nov 8, 2022
Otherwise, it always causes a _no newline at the end of file_ problem.

Closes #1487

Signed-off-by: Akos Kitta <[email protected]>
@per1234 per1234 added the conclusion: resolved Issue was resolved label Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants