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

Add .mm extension to coding style check #1871

Merged
merged 4 commits into from
Feb 27, 2022
Merged

Conversation

ngocdh
Copy link
Contributor

@ngocdh ngocdh commented Jun 13, 2021

Review of #1865 by @pljones revealed .mm extension was not checked.

@ngocdh
Copy link
Contributor Author

ngocdh commented Jun 13, 2021

Note that the coding style check for this PR won't pass because of the old iOS POC code, which is normal, but also proves that the proposed change works.

@ngocdh
Copy link
Contributor Author

ngocdh commented Jun 13, 2021

Team, I found the inplace edit option of clang-format (-i). Is it possible to use it to auto-correct style?

Copy link
Member

@ann0see ann0see left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok. @passing since you're the expert on clang format, could you please have a look at this too?

@passing
Copy link
Contributor

passing commented Jun 13, 2021

Didn't notice there's mm files as well. If they can't have cpp as prefix, I guess it makes sense to include them in the style check as proposed. The PR should then just also update the style for these files.

Team, I found the inplace edit option of clang-format (-i). Is it possible to use it to auto-correct style?

We have considered automated fixing of the style (#1702), but due to different constraints agreed to not go for it at the moment.

@ann0see
Copy link
Member

ann0see commented Jun 13, 2021

Ok. Thanks for the comment. No, .mm files can't have a .cpp extension as far as I know (they wouldn't be detected as objective c++ then --> no apple specific code available if we have a .cpp file).

On the automated formatting, I'd agree. But that can be a follow up PR.

@passing
Copy link
Contributor

passing commented Jun 13, 2021

On the automated formatting, I'd agree. But that can be a follow up PR.

also fine, just better merge it directly after this PR then. Otherwise someone forking this repo in between might get a style violation for the non-compliant mm files!

@pljones
Copy link
Collaborator

pljones commented Jun 13, 2021

It looks like in many places the expected style isn't being applied. I'm not sure why. If you look through the reformatting diff output, it's not right, I don't think. Maybe not only do the mm files need checking, the correct style needs selecting?

@ngocdh
Copy link
Contributor Author

ngocdh commented Jun 13, 2021

@pljones could you show an example where it’s not right?
The mm style check seems to work for me: https://github.com/jamulussoftware/jamulus/pull/1871/checks?check_run_id=2814420863

@pljones
Copy link
Collaborator

pljones commented Jun 14, 2021

Possibly just me wanting even more space than the standard -- [...] always seems unspaced compared with everything else we do. So with all the [[NSProcessInfo processInfo] endActivity: pActivity->activityId]; stuff, I'm probably thinking there's something wrong when, according to the style guide, that's correct (it's styles as an subscript into an array). Perhaps there's something to be discussed there?

It results in lines like this:

+    pActivity->activityId = [[NSProcessInfo processInfo]
+        beginActivityWithOptions:options
+                          reason:@"Jamulus provides low latency audio processing and should not be inturrupted by system throttling."];

If that were a C-like cast, there would be much more spacing.

This bit I'd also have expected even more blank line deletion (i.e. inside the method):

--- ./ios/ios_app_delegate.mm	(original)
+++ ./ios/ios_app_delegate.mm	(reformatted)
@@ -7,9 +7,8 @@
 
 @implementation QIOSApplicationDelegate
 
-
-
-- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
+{
 
     return YES;
 }

I'd also expect spacing inside the type casts (BOOL) -> ( BOOL ), etc.

@ngocdh
Copy link
Contributor Author

ngocdh commented Jun 14, 2021

I see, if there can be a better style for objective-c, then we should apply that.

This bit I'd also have expected even more blank line deletion (i.e. inside the method)

I suspect it's the same now for C++ code, not just .mm files.

@passing
Copy link
Contributor

passing commented Jun 14, 2021

just found there's a few configuration options explicitly for Objective-C

  • ObjCBinPackProtocolList
  • ObjCBlockIndentWidth
  • ObjCSpaceAfterProperty
  • ObjCSpaceBeforeProtocolList

we could customize them in our style definition in case we are not happy with the defaults
(see https://releases.llvm.org/10.0.0/tools/clang/docs/ClangFormatStyleOptions.html)

@ngocdh
Copy link
Contributor Author

ngocdh commented Jun 14, 2021

It seems to be possible to detect ObjC (using RawStringFormats?) and define customized format for it (using Language: ObjC).

@pljones
Copy link
Collaborator

pljones commented Jun 14, 2021

Example of what it's not touched that I don't like:

[[AVAudioSession sharedInstance] setMode:AVAudioSessionModeMeasurement error:&audioSessionError];

I'd rather this were

[ [AVAudioSession sharedInstance] setMode: AVAudioSessionModeMeasurement error:& audioSessionError ];

... but of course I've no idea if that syntactically viable ObjC...

@ann0see
Copy link
Member

ann0see commented Sep 5, 2021

@emlynmac this is another one for you ;-).

Is the code @pljones mentioned valid Objective C?
#1871 (comment)

@emlynmac
Copy link
Contributor

emlynmac commented Sep 5, 2021

@emlynmac this is another one for you ;-).

This looks more like a personal preference around white-space. Valid code compiles, which I don't see an issue with here.

In terms of the code, the first version is much clearer to an Obj-C person than the second, i.e.

[[AVAudioSession sharedInstance] setMode: AVAudioSessionModeMeasurement error: &audioSessionError];

is preferred, or if you prefer smaller lines:

[[AVAudioSession sharedInstance] setMode: AVAudioSessionModeMeasurement
                                   error: &audioSessionError];

@ann0see
Copy link
Member

ann0see commented Sep 5, 2021

Ok. Thanks for your input. The first option follows the Apple standards, while the second follows the strict Jamulus standards.
I'd not go with the Jamulus standards, but I'd leave the final decision up to @pljones and @ngocdh

@pljones
Copy link
Collaborator

pljones commented Sep 5, 2021

Valid code compiles, which I don't see an issue with here.

This isn't about code validity, it's about style compliance. The whole of the Jamulus code base complies with a style guide which very, very few C++ developers would be comfortable with. But we live with it for the time being.

I think I'd rather say we'll make a separate style for Objective C that clang-format can check against, rather than try to have the same style applied to both, if it's not going to be adjusted to fit.

Copy link
Member

@ann0see ann0see left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What’s missing here? Can we merge this for the next release?

@softins
Copy link
Member

softins commented Jan 29, 2022

What’s missing here? Can we merge this for the next release?

Although clang-format can be run on the .mm files, there is some discussion above about whether what it does to Obj-C is optimal. Maybe that needs to be resolved first.

@ann0see
Copy link
Member

ann0see commented Jan 31, 2022

Concerning the comment by @pljones : I already stated that I'd prefer to stick to apple not Jamulus code style.

@ann0see
Copy link
Member

ann0see commented Feb 26, 2022

Any updates here?

@pljones pljones added this to the Release 3.9.0 milestone Feb 27, 2022
Copy link
Collaborator

@pljones pljones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the Github Actions with the runs on @ngocdh 's tree have expired -- they ran to clean completion but I'd have liked to see the output. I'm approving anyway.

@ann0see
Copy link
Member

ann0see commented Feb 27, 2022

Ok. Rebased this.

@ann0see ann0see merged commit fac5d9d into jamulussoftware:master Feb 27, 2022
@ann0see
Copy link
Member

ann0see commented Feb 27, 2022

It works and I think it should be ok. Merging on this base.

@ann0see
Copy link
Member

ann0see commented Feb 27, 2022

CHANGELOG: Internal: Check coding style on macOS/iOS code files (.mm extension)

pgScorpio pushed a commit to pgScorpio/jamulus that referenced this pull request Mar 28, 2022
* Add .mm extension to coding style check

Review of jamulussoftware#1865 by @pljones revealed .mm extension was not checked.

* .clang-format for ObjC

* Apply clang-format to sound.mm

* Apply clang format on all .mm files

Co-authored-by: ann0see <[email protected]>
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.

6 participants