[TIMOB-18355] Create formatting files for C++, Objective-C, Java, and JavaScript
GitHub Issue | n/a |
Type | Improvement |
Priority | High |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | TiAPI |
Labels | n/a |
Reporter | Ingo Muschenetz |
Assignee | Unknown |
Created | 2015-01-09T18:42:11.000+0000 |
Updated | 2018-02-28T19:55:24.000+0000 |
Description
We have a number of different formats in use across our various languages. I would like to come up with one format for each language and a set of tools that can implement/enforce that format.
In general, we seek three goals:
Where possible, we create a formatting file for existing code bases that creates the least amount of formatting changes.
If changes are necessary, it is because we wish to make those code bases similar to other existing code bases.
When choosing tooling, we prefer configuring built-in tooling (i.e. adding a formatting file to Eclipse) vs using an external third-party formatter. This is to reduce the amount of effort needed for contributors to adhere to this format.
Some cross-language tenets we adhere to:
* Indentation: Tabs, with spaces for alignment. Most of our existing code uses tabs.
* Opening curly brace: New line, except for blocks and flow control and lambdas
* Closing curly brace: New line
* Max line length: Prefer 120, but might keep at 200 for existing code bases to reduce formatting
* Tab Width: 4
Comments
JSON Source
For C++ and Objective-C I have been experimenting with Clang-Format. First, I think it would be helpful to create a test file for Objective-C that demonstrates the cases shown in https://wiki.appcelerator.org/pages/viewpage.action?pageId=30088343
C++. Our coding standards are based on Google's, with the following modifications (using clang-format as an example):
BasedOnStyle: Google
UseTab: ForIndentation
IndentWidth: 4
TabWidth: 4
BreakBeforeBraces: Linux
ColumnLimit: 120
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
Standard: Cpp11
Objective-C. We also base these on the clang-format Google standard, since those seem most similar to our current code base, also using the above modifications. One challenge is that our stand explicitly says no space between the '\+' and '(' here:
+(TiOrientationFlags) TiOrientationFlagsFromObject:(id)args
. I seem to be unable to find a clang-format option to control this.Java: We should see if we can use the same formatting file for Studio and Android
JavaScript:
Next, find tooling and create formatting files as appropriateC++. Create a Visual Studio formatting file and clang-format file and make them agree
Objective-C. Create a clang-format file that we can use in Xcode
Java: Create a Eclipse and Android Studio formatting file and make them agree
JavaScript. Create Appcelerator Studio and Atom formatting files. The Appcelerator Studio defaults should be tweaked to match this.
[~vduggal] [~msamah] [~cng] [~jalter] please review: https://github.com/appcelerator/titanium_mobile/pull/6675