Skip to content

Auto Format makes functional changes to sketch code #1674

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
Pexje opened this issue Nov 14, 2022 · 3 comments
Closed
3 tasks done

Auto Format makes functional changes to sketch code #1674

Pexje opened this issue Nov 14, 2022 · 3 comments
Assignees
Labels
status: waiting for information More information must be provided before work can proceed type: imperfection Perceived defect in any part of project

Comments

@Pexje
Copy link

Pexje commented Nov 14, 2022

Describe the problem

When using Auto Format in Arduino IDE 2.0.1 some code in beginning of sketch goes wrong:

Wrong

This gives Compilation error.

To reproduce

Please fix this bug.

Expected behavior

This is good working code before using Auto Format:

Good

Arduino IDE version

2.0.1

Operating system

Windows

Operating system version

11

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
@Pexje Pexje added the type: imperfection Perceived defect in any part of project label Nov 14, 2022
@per1234
Copy link
Contributor

per1234 commented Nov 15, 2022

Thanks for your report @Pexje.

This gives Compilation error.

Although I am able to reproduce the formatting change you describe:

before

#define DEBUG_SERIAL if (DEBUG) Serial

after

#define DEBUG_SERIAL \
  if (DEBUG) Serial

I am not able to reproduce the compilation error you claim. I will need you to provide enough information for me to reproduce it:

  • A complete minimal sketch that compiles before formatting and does not compile after formatting.
  • Does the problem occur if you select Tools > Board > Arduino AVR Boards > Arduino Uno from the Arduino IDE menus before compiling the formatted sketch? If not, which board do you have selected when compilation does fail?
  • The full an exact text of the compiler error message shown in the "Output" panel at the bottom of the Arduino IDE window.

Investigation

I looked for a setting in the ClangFormat options (ClangFormat is the tool used by the Arduino IDE "Auto Format" feature) that would cause it to not add this line break. I did not find any.

It is not clear whether the addition of this break is intentional behavior of the formatter or a bug. I found this similar bug report: llvm/llvm-project#53180. I also found this related bug report llvm/llvm-project#49164, which has been fixed, but that fix did not fix the problem you report here.

A more minimal demonstration code:

#define FOO if(true) {}
#define BAR while(true) {}
#define BAZ for(;;) {}

Formats to:

#define FOO \
  if (true) {}
#define BAR \
  while (true) {}
#define BAZ \
  for (;;) {}

Workaround

You can selectively disable formatting by adding special comments to your sketch code:

https://releases.llvm.org/14.0.0/tools/clang/docs/ClangFormatStyleOptions.html#disabling-formatting-on-a-piece-of-code

So if you don't like the line break, you can do this:

// clang-format off
#define DEBUG_SERIAL if (DEBUG) Serial
// clang-format on

@per1234 per1234 self-assigned this Nov 15, 2022
@per1234 per1234 added the status: waiting for information More information must be provided before work can proceed label Nov 15, 2022
@per1234
Copy link
Contributor

per1234 commented Dec 16, 2022

Hi @Pexje. We are still waiting for you to provide the information requested in the previous reply so that we can proceed with the investigation or evaluation of this.

@per1234 per1234 changed the title Problem with Auto Format in Arduino IDE 2.0.1 Auto Format makes functional changes to sketch code Sep 26, 2023
@per1234
Copy link
Contributor

per1234 commented Sep 26, 2023

Since the requested code demonstrating a functional change to the code was never provided, and since the formatting style is not objectively bad from an aesthetic standpoint, I will close this as declined/invalid.

If someone can provide a sketch that demonstrates the changed formatting causing a functional change to the code then we will investigate further.

@per1234 per1234 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for information More information must be provided before work can proceed type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants