diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..9405088 --- /dev/null +++ b/.clang-format @@ -0,0 +1,53 @@ +--- +BasedOnStyle: LLVM + +# Tabs, matching existing Xcode configuration +UseTab: Always +IndentWidth: 4 +TabWidth: 4 +ContinuationIndentWidth: 4 +ObjCBlockIndentWidth: 4 + +# No column limit — avoids reformatting existing long lines. +# Tighten to 120 once the codebase is cleaned up, if desired. +ColumnLimit: 0 + +# K&R brace style +BreakBeforeBraces: Attach + +# int *x, NSString *name +PointerAlignment: Right + +# Case labels indented inside switch +IndentCaseLabels: true + +# Imports and includes +SortIncludes: Never + +# Objective-C +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true + +# Spacing +SpaceAfterCStyleCast: false +SpaceBeforeParens: ControlStatements +SpacesInContainerLiterals: false + +# Alignment +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignOperands: true +AlignTrailingComments: true + +# Short constructs — keep blocks and control flow multi-line +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false + +# Line breaks +BreakBeforeBinaryOperators: None +KeepEmptyLinesAtTheStartOfBlocks: false +MaxEmptyLinesToKeep: 2 diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3c988ca --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +charset = utf-8 + +[*.{m,h}] +indent_style = tab +indent_size = 4 + +[*.py] +indent_style = space +indent_size = 4 + +[*.{yml,yaml}] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/objective-c-xcode.yml b/.github/workflows/objective-c-xcode.yml index 5aa74a1..ecf6035 100644 --- a/.github/workflows/objective-c-xcode.yml +++ b/.github/workflows/objective-c-xcode.yml @@ -16,6 +16,11 @@ jobs: - name: Checkout uses: actions/checkout@v3 + - name: Check Formatting + run: | + brew install clang-format + Scripts/format.sh --check + - name: Prepare Keychain For Signing env: SECRET_MACOS_CERTIFICATE_B64: ${{ secrets.MACOS_CERTIFICATE }} diff --git a/CoreZen/Database/DatabaseTable.h b/CoreZen/Database/DatabaseTable.h index 0444dad..78566ef 100644 --- a/CoreZen/Database/DatabaseTable.h +++ b/CoreZen/Database/DatabaseTable.h @@ -44,7 +44,7 @@ - (ZENResultSet *)allRows:(ZENDatabase *)database; - (ZENResultSet *)rowByIdentifier:(ZENIdentifier)identifier - database:(ZENDatabase *)database; + database:(ZENDatabase *)database; #pragma mark - Count diff --git a/CoreZen/Domain/DomainCommon.h b/CoreZen/Domain/DomainCommon.h index 43ae355..2c43bf3 100644 --- a/CoreZen/Domain/DomainCommon.h +++ b/CoreZen/Domain/DomainCommon.h @@ -29,10 +29,10 @@ void ZENCallAsyncContinueBlockOnMainThread(ZENAsyncContinueBlock continueBlock); // ======================================== // Call a ZENAsyncCompletionBlock on a thread pool -void ZENCallAsyncCompletionBlockOnThreadPool(ZENAsyncCompletionBlock completionBlock, NSError* error); +void ZENCallAsyncCompletionBlockOnThreadPool(ZENAsyncCompletionBlock completionBlock, NSError *error); // Call a ZENAsyncCompletionBlock on the main thread -void ZENCallAsyncCompletionBlockOnMainThread(ZENAsyncCompletionBlock completionBlock, NSError* error); +void ZENCallAsyncCompletionBlockOnMainThread(ZENAsyncCompletionBlock completionBlock, NSError *error); // ======================================== // ZENFetchResultsBlock @@ -63,4 +63,4 @@ void ZENCallAsyncCountCompletionBlockOnMainThread(ZENAsyncCountCompletionBlock c // ======================================== // Deliver a notification on the main thread -void ZENDeliverNotificationOnMainThread(NSString* notification, id sender, NSDictionary *userData); +void ZENDeliverNotificationOnMainThread(NSString *notification, id sender, NSDictionary *userData); diff --git a/CoreZen/Domain/DomainObject.h b/CoreZen/Domain/DomainObject.h index 2b05f64..93bddc0 100644 --- a/CoreZen/Domain/DomainObject.h +++ b/CoreZen/Domain/DomainObject.h @@ -13,7 +13,7 @@ @protocol ZENDataModel @end -@protocol ZENDomainObject +@protocol ZENDomainObject - (instancetype)initWithDTO:(ZENDataTransferObject *)dto; @@ -23,7 +23,7 @@ @end -@interface ZENDomainObject : NSObject +@interface ZENDomainObject : NSObject @property (nonatomic, strong, readonly) ZENDataTransferObject *basicDTO; diff --git a/CoreZen/Domain/ObjectRepository.h b/CoreZen/Domain/ObjectRepository.h index d777325..e451496 100644 --- a/CoreZen/Domain/ObjectRepository.h +++ b/CoreZen/Domain/ObjectRepository.h @@ -45,11 +45,11 @@ typedef enum : NSUInteger { // Runs asynchronously. Result callback block happens on a thread pool. - (void)fetchObjectByIdentifier:(ZENIdentifier)identifier - completion:(ZENFetchResultsBlock)resultsBlock; + completion:(ZENFetchResultsBlock)resultsBlock; // Same as above, but uiCompletion block happens on the main thread. - (void)fetchObjectByIdentifier:(ZENIdentifier)identifier - uiCompletion:(ZENFetchResultsBlock)resultsBlock; + uiCompletion:(ZENFetchResultsBlock)resultsBlock; // Runs asynchronously. Result callback block happens on a thread pool. - (void)fetchAllObjects:(ZENFetchResultsBlock)resultsBlock; @@ -69,12 +69,12 @@ typedef enum : NSUInteger { // Helper method to call DomainObject +asyncInit: on object before // adding to repository. -- (void) asyncInitAndAdd:(ZENDomainObject *)domainObject - completion:(ZENAsyncContinueBlock)completion; +- (void)asyncInitAndAdd:(ZENDomainObject *)domainObject + completion:(ZENAsyncContinueBlock)completion; // Same as above, but uiCompletion block happens on the main thread. -- (void) asyncInitAndAdd:(ZENDomainObject *)domainObject - uiCompletion:(ZENAsyncContinueBlock)completion; +- (void)asyncInitAndAdd:(ZENDomainObject *)domainObject + uiCompletion:(ZENAsyncContinueBlock)completion; #pragma mark - Update @@ -107,8 +107,8 @@ typedef enum : NSUInteger { @end -extern NSString * const ZENObjectRepositoryNotificationObjectKey; +extern NSString *const ZENObjectRepositoryNotificationObjectKey; -extern NSString * const ZENObjectRepositoryObjectAddedNotification; -extern NSString * const ZENObjectRepositoryObjectUpdatedNotification; -extern NSString * const ZENObjectRepositoryObjectDeletedNotification; +extern NSString *const ZENObjectRepositoryObjectAddedNotification; +extern NSString *const ZENObjectRepositoryObjectUpdatedNotification; +extern NSString *const ZENObjectRepositoryObjectDeletedNotification; diff --git a/CoreZen/Media/MPV/MPVConstants.h b/CoreZen/Media/MPV/MPVConstants.h index 78398ab..8575527 100644 --- a/CoreZen/Media/MPV/MPVConstants.h +++ b/CoreZen/Media/MPV/MPVConstants.h @@ -6,72 +6,72 @@ // // Version properties -extern const char* const kMPVProperty_ffmpeg_version; -extern const char* const kMPVProperty_libass_version; -extern const char* const kMPVProperty_mpv_version; +extern const char *const kMPVProperty_ffmpeg_version; +extern const char *const kMPVProperty_libass_version; +extern const char *const kMPVProperty_mpv_version; // Read-only properties -extern const char* const kMPVProperty_audio_bitrate; -extern const char* const kMPVProperty_audio_codec; -extern const char* const kMPVProperty_audio_codec_name; -extern const char* const kMPVProperty_dheight; -extern const char* const kMPVProperty_duration; -extern const char* const kMPVProperty_dwidth; -extern const char* const kMPVProperty_estimated_frame_count; -extern const char* const kMPVProperty_estimated_frame_number; -extern const char* const kMPVProperty_file_format; -extern const char* const kMPVProperty_file_size; -extern const char* const kMPVProperty_filename; -extern const char* const kMPVProperty_filename_no_ext; -extern const char* const kMPVProperty_height; -extern const char* const kMPVProperty_media_title; -extern const char* const kMPVProperty_path; -extern const char* const kMPVProperty_pause; -extern const char* const kMPVProperty_playlist_count; -extern const char* const kMPVProperty_playlist_playing_pos; -extern const char* const kMPVProperty_sub_bitrate; -extern const char* const kMPVProperty_time_remaining; -extern const char* const kMPVProperty_video_bitrate; -extern const char* const kMPVProperty_video_codec; -extern const char* const kMPVProperty_video_format; -extern const char* const kMPVProperty_video_params_aspect; -extern const char* const kMPVProperty_width; +extern const char *const kMPVProperty_audio_bitrate; +extern const char *const kMPVProperty_audio_codec; +extern const char *const kMPVProperty_audio_codec_name; +extern const char *const kMPVProperty_dheight; +extern const char *const kMPVProperty_duration; +extern const char *const kMPVProperty_dwidth; +extern const char *const kMPVProperty_estimated_frame_count; +extern const char *const kMPVProperty_estimated_frame_number; +extern const char *const kMPVProperty_file_format; +extern const char *const kMPVProperty_file_size; +extern const char *const kMPVProperty_filename; +extern const char *const kMPVProperty_filename_no_ext; +extern const char *const kMPVProperty_height; +extern const char *const kMPVProperty_media_title; +extern const char *const kMPVProperty_path; +extern const char *const kMPVProperty_pause; +extern const char *const kMPVProperty_playlist_count; +extern const char *const kMPVProperty_playlist_playing_pos; +extern const char *const kMPVProperty_sub_bitrate; +extern const char *const kMPVProperty_time_remaining; +extern const char *const kMPVProperty_video_bitrate; +extern const char *const kMPVProperty_video_codec; +extern const char *const kMPVProperty_video_format; +extern const char *const kMPVProperty_video_params_aspect; +extern const char *const kMPVProperty_width; // Read-write properties -extern const char* const kMPVProperty_ao_mute; -extern const char* const kMPVProperty_ao_volume; -extern const char* const kMPVProperty_percent_pos; -extern const char* const kMPVProperty_playback_time; -extern const char* const kMPVProperty_playlist_pos; -extern const char* const kMPVProperty_time_pos; -extern const char* const kMPVProperty_sid; +extern const char *const kMPVProperty_ao_mute; +extern const char *const kMPVProperty_ao_volume; +extern const char *const kMPVProperty_percent_pos; +extern const char *const kMPVProperty_playback_time; +extern const char *const kMPVProperty_playlist_pos; +extern const char *const kMPVProperty_time_pos; +extern const char *const kMPVProperty_sid; // Property keys -extern const char* const kMPVPropertyKey_name; -extern const char* const kMPVPropertyKey_data; -extern const char* const kMPVPropertyKey_id; -extern const char* const kMPVPropertyKey_no; +extern const char *const kMPVPropertyKey_name; +extern const char *const kMPVPropertyKey_data; +extern const char *const kMPVPropertyKey_id; +extern const char *const kMPVPropertyKey_no; // Config options -extern const char* const kMPVOption_hwdec; -extern const char* const kMPVOption_vo; +extern const char *const kMPVOption_hwdec; +extern const char *const kMPVOption_vo; // Config option params -extern const char* const kMPVOptionParam_libmpv; -extern const char* const kMPVOptionParam_videotoolbox; +extern const char *const kMPVOptionParam_libmpv; +extern const char *const kMPVOptionParam_videotoolbox; // Commands -extern const char* const kMPVCommand_loadfile; -extern const char* const kMPVCommand_quit; -extern const char* const kMPVCommand_playlist_play_index; -extern const char* const kMPVCommand_frame_step; -extern const char* const kMPVCommand_frame_back_step; -extern const char* const kMPVCommand_seek; +extern const char *const kMPVCommand_loadfile; +extern const char *const kMPVCommand_quit; +extern const char *const kMPVCommand_playlist_play_index; +extern const char *const kMPVCommand_frame_step; +extern const char *const kMPVCommand_frame_back_step; +extern const char *const kMPVCommand_seek; // Command params -extern const char* const kMPVCommandParam_relative; -extern const char* const kMPVCommandParam_absolute; -extern const char* const kMPVCommandParam_absolute_percent; -extern const char* const kMPVCommandParam_keyframes; -extern const char* const kMPVCommandParam_exact; -extern const char* const kMPVCommandParam_replace; +extern const char *const kMPVCommandParam_relative; +extern const char *const kMPVCommandParam_absolute; +extern const char *const kMPVCommandParam_absolute_percent; +extern const char *const kMPVCommandParam_keyframes; +extern const char *const kMPVCommandParam_exact; +extern const char *const kMPVCommandParam_replace; diff --git a/CoreZen/Media/MPV/MPVFunctions.h b/CoreZen/Media/MPV/MPVFunctions.h index 4f71293..7e34a70 100644 --- a/CoreZen/Media/MPV/MPVFunctions.h +++ b/CoreZen/Media/MPV/MPVFunctions.h @@ -13,13 +13,12 @@ const char *zen_double_to_mpv_string(double d); typedef struct mpv_handle mpv_handle; -void zen_mpv_set_bool_property(mpv_handle* mpv, const char* const property, BOOL value); -void zen_mpv_set_string_property(mpv_handle* mpv, const char* const property, const char* const value); +void zen_mpv_set_bool_property(mpv_handle *mpv, const char *const property, BOOL value); +void zen_mpv_set_string_property(mpv_handle *mpv, const char *const property, const char *const value); -BOOL zen_mpv_compare_strings(const char* const one, const char* const two); +BOOL zen_mpv_compare_strings(const char *const one, const char *const two); -void zen_mpv_init_pthread_mutex_cond(pthread_mutex_t* mutex, pthread_cond_t* cond); -void zen_mpv_destroy_pthread_mutex_cond(pthread_mutex_t* mutex, pthread_cond_t* cond); +void zen_mpv_init_pthread_mutex_cond(pthread_mutex_t *mutex, pthread_cond_t *cond); +void zen_mpv_destroy_pthread_mutex_cond(pthread_mutex_t *mutex, pthread_cond_t *cond); void *zen_mpv_get_opengl_proc_address(void *ctx, const char *name); - diff --git a/CoreZen/Media/MediaFile.h b/CoreZen/Media/MediaFile.h index d01ad7c..a0f9ed5 100644 --- a/CoreZen/Media/MediaFile.h +++ b/CoreZen/Media/MediaFile.h @@ -12,7 +12,7 @@ @property (nonatomic, strong, readonly) NSURL *fileURL; -+ (instancetype)mediaFileWithURL:(NSURL*)url; ++ (instancetype)mediaFileWithURL:(NSURL *)url; // Terminate frame renderer (and frame render controller) if one was created, // then terminate media file format context diff --git a/CoreZenTests/Classes/TestIdentifiable.h b/CoreZenTests/Classes/TestIdentifiable.h index 59f325b..86f9d03 100644 --- a/CoreZenTests/Classes/TestIdentifiable.h +++ b/CoreZenTests/Classes/TestIdentifiable.h @@ -16,4 +16,3 @@ - (instancetype)initWithIdentifier:(ZENIdentifier)identifier; @end - diff --git a/Scripts/format.sh b/Scripts/format.sh new file mode 100755 index 0000000..b3c7f48 --- /dev/null +++ b/Scripts/format.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +set -euo pipefail + +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" +SOURCE_DIRS=("CoreZen" "CoreZenTests") + +if ! command -v clang-format &>/dev/null; then + echo "error: clang-format not found" + echo " Install with: brew install clang-format" + exit 1 +fi + +files=() +for dir in "${SOURCE_DIRS[@]}"; do + target="$REPO_ROOT/$dir" + [ -d "$target" ] || continue + while IFS= read -r -d '' f; do + files+=("$f") + done < <(find "$target" -name '*.m' -o -name '*.h' -print0 2>/dev/null || true) +done + +if [ ${#files[@]} -eq 0 ]; then + echo "No source files found." + exit 0 +fi + +check_only=false +for arg in "$@"; do + case "$arg" in + --check) check_only=true ;; + *) + echo "usage: $(basename "$0") [--check]" + echo " --check Report violations without modifying files (exit 1 if any found)" + exit 1 + ;; + esac +done + +if $check_only; then + echo "Checking formatting of ${#files[@]} files..." + if ! clang-format --dry-run --Werror "${files[@]}"; then + echo "" + echo "Formatting violations found. Run Scripts/format.sh to fix." + exit 1 + fi + echo "All files formatted correctly." +else + echo "Formatting ${#files[@]} files..." + clang-format -i "${files[@]}" + echo "Done." +fi