Bug 247314 - Code style does not match comments given in review related to newlines and preprocessor conditionals
Summary: Code style does not match comments given in review related to newlines and pr...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-11-01 05:17 PDT by Kimmo Kinnunen
Modified: 2022-11-01 09:07 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kimmo Kinnunen 2022-11-01 05:17:13 PDT
Code style does not match comments given in review related to newlines and preprocessor conditionals

C++ code snippet under review:

  #include "IPCTesterProxy.h"

  #if ENABLE(IPC_TESTING_API)
  namespace WebKit {

Was denied with comment
 
  > Also need a blank line between #if and namespace.

Define what is the rule to follow in this case and codify it somehow in the code style.


This is a currently non-deterministic in current reviews: some people might require, some allow and some deny.

This causes un-needed churn during review, wasting time in review as well as re-authoring, rebasing, re-submitting and re-waiting slow EWS results and patch landings.
Comment 1 Radar WebKit Bug Importer 2022-11-01 05:17:25 PDT
<rdar://problem/101801755>
Comment 2 Kimmo Kinnunen 2022-11-01 05:30:42 PDT
One review example in https://github.com/WebKit/WebKit/pull/5952 but possibly there are others.

Ryosuke, would you have a rule suggestion or requirement?

I'm interpreting your rule something like:

[](#linebreaking-mandatory-new-line) A new line should follow each of the lines containing following source elements:
 * End of the initial license block comment
 * After last consecutive preprocessor statement in preprocessor conditionals `#if`, `#else`, `#elif` and `#endif` 
 * After last non-preprocessor statement before above mentioned preprocessor statements
 * Last line of `.h`, `.cpp`, `.js`, `.html` and `.css` files



Example:
---
#if ENABLE(IPC_TESTING_API)
 
namespace WebKit {
  // ...
}
  
#endif

namespace WTF {
  // ..
}

--- 


Example (Connection.h):
--
#if USE(UNIX_DOMAIN_SOCKETS)
#include <wtf/unix/UnixFileDescriptor.h>
#endif

#if OS(DARWIN)
#include <mach/mach_port.h>
#include <wtf/MachSendRight.h>
#include <wtf/OSObjectPtr.h>
#include <wtf/spi/darwin/XPCSPI.h>
#endif

#if OS(WINDOWS)
#include <wtf/win/Win32Handle.h>
#endif

#if USE(GLIB)
#include <wtf/glib/GSocketMonitor.h>
#endif

#if ENABLE(IPC_TESTING_API)
#include "MessageObserver.h"
#endif

---


Example wrong in current Connection.h:
---
#if USE(UNIX_DOMAIN_SOCKETS)
    using Handle = UnixFileDescriptor;
#elif OS(WINDOWS)
    using Handle = Win32Handle;
#elif OS(DARWIN)
    using Handle = MachSendRight;
#endif
--


Example current Connection.h should be:
--
#if USE(UNIX_DOMAIN_SOCKETS)

    using Handle = UnixFileDescriptor;

#elif OS(WINDOWS)

    using Handle = Win32Handle;

#elif OS(DARWIN)

    using Handle = MachSendRight;

#endif
--




Or is the comment more of just the first file-global ifdef that comments out the code?
Something like:

[](#linebreaking-mandatory-new-line) A new line should follow each of the lines containing following source elements:
 * End of the initial license block comment
 * After last preprocessor statement in preprocessor conditionals `#if`, `#else`, `#elif` and `#endif`  that begins the enablement of conditionally compiled code in .cpp
 * After last non-preprocessor statement before above mentioned preprocessor statements
Comment 3 Ryosuke Niwa 2022-11-01 08:40:37 PDT
I think this code is correct:

#if USE(UNIX_DOMAIN_SOCKETS)
    using Handle = UnixFileDescriptor;
#elif OS(WINDOWS)
    using Handle = Win32Handle;
#elif OS(DARWIN)
    using Handle = MachSendRight;
#endif

In this case, statements within if-elif is indented, so we don't need to insert a blank line to differentiate / distinguish if-elif-endif further.
Comment 4 Darin Adler 2022-11-01 09:07:42 PDT
I agree with Ryosuke on this.