6

I'm trying to get a configuration for UncrustifyX that will work with Swift using the Allman Style. I'm using BBUncrustifyPlugin in Xcode. Here's what I have so far:

# indent using tabs
input_tab_size                           = 8
output_tab_size                          = 4
indent_columns                           = output_tab_size
indent_with_tabs                         = 1

# indent case
indent_switch_case                       = indent_columns
indent_case_brace                        = 0

# indent class body
indent_class                             = True

# newlines
nl_after_semicolon                       = true

# spaces
# add in general
sp_before_sparen                         = add
# but remove for
sp_version_paren                         = remove
sp_catch_paren                           = remove
sp_scope_paren                           = remove
sp_func_call_user_paren                  = remove

# Allman style for curly braces
nl_assign_brace                          = add
nl_enum_brace                            = add
nl_union_brace                           = add
nl_struct_brace                          = add
nl_class_brace                           = add
nl_do_brace                              = add
nl_if_brace                              = add
nl_for_brace                             = add
nl_else_brace                            = add
nl_while_brace                           = add
nl_switch_brace                          = add
nl_fcall_brace                           = add
nl_fdef_brace                            = add
nl_brace_else                            = add
nl_brace_while                           = remove
nl_case_colon_brace                      = add
nl_after_brace_open                      = true

# one liners
nl_func_leave_one_liners                 = true
nl_enum_leave_one_liners                 = true
nl_create_if_one_liner                   = true
nl_create_for_one_liner                  = true
nl_create_while_one_liner                = true

It gets most of the braces right, but pulls apart exclamation marks and question marks and has some other problems. I'm not sure what else I can do to make it work right.

I made a gist here:

Bryan Cimo
  • 1,268
  • 1
  • 19
  • 34
  • Hi, did you found any better configuration or improved this? I'm searching for good swift-code formater for our team and found your question – sage444 Mar 28 '16 at 15:46
  • Not yet, I'm interested if you find something please let me know. I'm still using the above. – Bryan Cimo Mar 28 '16 at 16:39
  • Maybe http://www.swiftcleanapp.com is an option, since I did not get uncrustify to work consistently with Swift. – Binarian May 17 '16 at 12:20

1 Answers1

2

First I have to say: I can't help you with the configuration of uncrustify.

But perhaps I can offer you another solution: You should have a look at the open source command line tool swiftformat. Among others it supports the allman- aka east-coast- style too.

https://github.com/nicklockwood/SwiftFormat

Kai Zimmer
  • 21
  • 2