From adfe1621e43568b993b0ff7006575cbc64d850f2 Mon Sep 17 00:00:00 2001 From: Greg Heo Date: Tue, 28 Jan 2014 20:29:00 -0500 Subject: [PATCH] First try of the uncrustify config file --- uncrustify/README.markdown | 23 ++++++ uncrustify/rw-uncrustify.cfg | 133 +++++++++++++++++++++++++++++++ uncrustify/test-expected.m | 29 +++++++ uncrustify/test-input.m | 36 +++++++++ uncrustify/test-rw-uncrustify.sh | 15 ++++ 5 files changed, 236 insertions(+) create mode 100644 uncrustify/README.markdown create mode 100644 uncrustify/rw-uncrustify.cfg create mode 100644 uncrustify/test-expected.m create mode 100644 uncrustify/test-input.m create mode 100755 uncrustify/test-rw-uncrustify.sh diff --git a/uncrustify/README.markdown b/uncrustify/README.markdown new file mode 100644 index 0000000..db4c90b --- /dev/null +++ b/uncrustify/README.markdown @@ -0,0 +1,23 @@ +# Uncrustification + +**rw-uncrustify.cfg** is a configuration file for the [Uncrustify](http://uncrustify.sourceforge.net/) +source code beautifier. You can install it from source or from the epically-useful [Homebrew](http://brew.sh/). +You can also search the web for Xcode plugins if that's your thing. + +The goal here is to automate the coding conventions of the style guide. + +## Tests + +Of course, there are tests! + +A sample input file `test-input.m` is run through Uncrustify, and its output +is compared to the contents of `test-expected.m`. There should be a perfect +match. + +To run the tests, just run the script `test-rw-uncrustify.sh`. You'll need +the command-line version of uncrustify. + +## Conclusion + +As with all things online, this is a work in progress. Pull requests and contributions are welcome. + diff --git a/uncrustify/rw-uncrustify.cfg b/uncrustify/rw-uncrustify.cfg new file mode 100644 index 0000000..425cdd8 --- /dev/null +++ b/uncrustify/rw-uncrustify.cfg @@ -0,0 +1,133 @@ +# An Uncrustify configuration file to match the +# official raywenderlich.com Objective-C style guide. +# +# https://github.com/raywenderlich/objective-c-style-guide +# + +# General options +newlines = auto + +input_tab_size = 2 +output_tab_size = 2 + +string_escape_char = 92 +string_escape_char2 = 0 + +tok_split_gte = false + +utf8_bom = remove +utf8_byte = false +utf8_force = false + +# Objective-C stuff +indent_oc_block = true +indent_oc_block_msg = 0 +indent_oc_msg_colon = 0 + +sp_after_oc_scope = force +sp_after_oc_colon = remove +sp_before_oc_colon = remove + +sp_after_oc_dict_colon = force +sp_before_oc_dict_colon = remove + +sp_after_send_oc_colon = remove +sp_before_send_oc_colon = remove + +sp_after_oc_type = remove +sp_after_oc_return_type = remove + +sp_after_oc_at_sel = remove +sp_after_oc_at_sel_parens = add +sp_inside_oc_at_sel_parens = remove + +sp_before_oc_block_caret = ignore +sp_after_oc_block_caret = remove +sp_after_oc_msg_receiver = remove +sp_after_oc_property = force + +# Indenting + +indent_columns = 2 +indent_continue = 2 + +indent_with_tabs = 0 +indent_cmt_with_tabs = false +indent_align_string = false +indent_xml_string = 0 +indent_brace = 0 +indent_braces = false +indent_braces_no_func = false +indent_braces_no_class = false +indent_braces_no_struct = false +indent_brace_parent = false +indent_namespace = false +indent_namespace_level = 0 +indent_namespace_limit = 0 +indent_extern = true +indent_class = true +indent_class_colon = false +indent_ctor_init_leading = 2 +indent_ctor_init = 0 +indent_else_if = false +indent_var_def_blk = 0 +indent_var_def_cont = false +indent_func_def_force_col1 = false +indent_func_call_param = false +indent_func_def_param = false +indent_func_proto_param = false +indent_func_class_param = false +indent_func_ctor_var_param = false +indent_template_param = false +indent_func_param_double = false +indent_func_const = 0 +indent_func_throw = 0 +indent_member = 0 +indent_sing_line_comments = 0 +indent_relative_single_line_comments = false +indent_switch_case = 0 +indent_case_shift = 0 +indent_case_brace = 0 +indent_col1_comment = false +indent_label = 1 +indent_access_spec = 1 +indent_access_spec_body = false +indent_paren_nl = false +indent_paren_close = 0 +indent_comma_paren = false +indent_bool_paren = false +indent_first_bool_expr = false +indent_square_nl = false +indent_preserve_sql = false +indent_align_assign = true + +# Spacing +sp_inside_paren = remove +sp_paren_brace = force +sp_before_ptr_star = force +sp_before_unnamed_ptr_star = ignore +sp_between_ptr_star = remove +sp_after_ptr_star = remove +sp_func_call_paren = remove + +nl_after_func_body = 2 +eat_blanks_after_open_brace = true +eat_blanks_before_close_brace = true + +# Newlines +nl_assign_leave_one_liners = true +nl_enum_brace = remove +nl_struct_brace = remove +nl_union_brace = remove +nl_if_brace = remove +nl_brace_else = remove +nl_elseif_brace = remove +nl_else_brace = remove +nl_else_if = remove +nl_for_brace = remove +nl_while_brace = remove +nl_func_decl_end = remove +nl_func_def_end = remove +nl_fcall_brace = remove +nl_fdef_brace = remove + diff --git a/uncrustify/test-expected.m b/uncrustify/test-expected.m new file mode 100644 index 0000000..90c8d66 --- /dev/null +++ b/uncrustify/test-expected.m @@ -0,0 +1,29 @@ +/* + * Some fake Objective-C code to test the uncrustify rules. + */ + +@import Foundation; + +@implementation FooClass : NSObject + +- (NSString *)smilifyString:(NSString *)someString { + NSString *theString = [someString stringByReplacingOccurrencesOfString:@":)" withString:@":]"]; + return theString; +} + +- (NSString *)frownifyString:(NSString *)someString { + NSString *theString = [someString stringByReplacingOccurrencesOfString:@":(" withString:@":["]; + return theString; +} + +- (NSArray *)smilifyStrings:(NSArray *)strings { + NSMutableArray *workingArray = [NSMutableArray array]; + for (NSString *string in strings) { + [workingArray addObject:[self smilifyString:string]]; + } + + return [workingArray copy]; +} + +@end + diff --git a/uncrustify/test-input.m b/uncrustify/test-input.m new file mode 100644 index 0000000..e1efacb --- /dev/null +++ b/uncrustify/test-input.m @@ -0,0 +1,36 @@ +/* + * Some fake Objective-C code to test the uncrustify rules. + */ + +@import Foundation; + +@implementation FooClass : NSObject + +-(NSString*)smilifyString:(NSString*) someString +{ + NSString* theString = [someString stringByReplacingOccurrencesOfString:@":)" withString:@":]"]; + return theString; +} + + +- (NSString*) frownifyString: (NSString*) someString { + NSString* theString = [someString stringByReplacingOccurrencesOfString:@":(" withString:@":["]; + return theString; +} + + +- (NSArray * )smilifyStrings:(NSArray *)strings +{ + NSMutableArray *workingArray = [NSMutableArray array]; + for (NSString *string in strings) + { + [workingArray addObject:[self smilifyString:string]]; + } + + return [workingArray copy]; +} + + + +@end + diff --git a/uncrustify/test-rw-uncrustify.sh b/uncrustify/test-rw-uncrustify.sh new file mode 100755 index 0000000..1a95e19 --- /dev/null +++ b/uncrustify/test-rw-uncrustify.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +if command -v uncrustify > /dev/null; then + uncrustify -q -c rw-uncrustify.cfg -f test-input.m | diff -u - test-expected.m + if [[ $? -ne 0 ]]; then + echo "ERROR: uncrustified output doesn't match the expected output." + exit 1 + fi +else + echo ERROR: cannot find uncrustify. + exit 2 +fi + +echo "OK: rw-uncrustify.cfg did its job correctly." +