diff --git a/README.md b/README.md index dcc3aac..95b5ccb 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,1513 @@ -Java Code Styles +Java/Android Code Styles ================ IntelliJ IDEA code style settings for Square's Java and Android projects. - Installation ------------ - - * Run the `install.sh` script. - * Restart IntelliJ if it's running. - * Open IntelliJ Project Settings -> Code Styles, change the code style for the +* Run the __`install.sh`__ script. +* Restart IntelliJ if it's running. +* Open IntelliJ/AS Project Settings -> Code Styles, change the code style for the project to the one you want. +
+Code styles changes from the AS default ones +------------------------------------------------ +### CesardsAndroid + +- __Code Styles__ + - __Java__ + - __Tabs and Indents__ + - __Spaces__ + - __Wrapping and Braces__ + - __Blank Lines__ + - __JavaDoc__ + - __Imports__ + - __Arrangement__ + - __Code Generation__ + - __XML__ + - __Tabs and Indents__ + - __Other__ + - __Android__ + - __Groovy__ + - __Tabs and Indents__ + - __Wrapping and Braces__ + - __Blank Lines__ + - __Imports__ + +
+ + +#### Code Styles + +__Indents Detection__ + +- __✓ Detect and use existing file indents for editing__ + + ```xml + +##### Java + + +###### Tabs and Indents + +- __Tab size: 2 / Indent: 2 / Continuation indent: 4__ + + ```xml + + + ``` + + +###### Spaces + +▼__Before Left Brace__ + +- __✓ Array initializer left brace__ + + ```xml + +###### Wrapping and Braces + +▼ __Keep when reformatting__ + +- __✗ Comment at first column__ + + ```xml + +###### Blank Lines + +__In declarations ⇨ 1__ + +```xml + +###### JavaDoc + +▼ __Alignment__ + +- __✗ Align parameter descriptions__ + + ```xml +

+ * Line with manual + * line feed. + */ + ``` + + +###### Imports + +__Class count to use import with `*` ⇨ 999__ + +```xml + +###### Arrangement + +__Grouping rules__ + +- __✓ Keep getters and setters together__ + + ```xml + + GETTERS_AND_SETTERS + KEEP + + ``` + +- __✓ Keep overriden methods together (keep order)__ + + ```xml + + OVERRIDDEN_METHODS + KEEP + + ``` + + +###### Code Generation + +__Final Modifier__ + +- __✓ Make generated local variables final__ + + ```xml + +##### XML + + +###### Tabs and Indents + +- __Tab size: 2 / Indent: 2 / Continuation indent: 4__ + + ```xml + + + ``` + + +###### Other + +__✓ Keep line breaks__ + +```xml + +###### Android + +__Layout Files__ + +- __✗ Insert blank line before tag__ + + ```xml + + ``` + +__Other XML resource files__ + +- __✗ Insert line break before first attribute__ + + ```xml + + ``` + + +##### Groovy + + +###### Tabs and Indents + +- __Tab size: 2 / Indent: 2 / Continuation indent: 4__ + + ```xml + + + ``` + + +###### Wrapping and Braces + +▼ __Keep when reformatting__ + +- __✗ Comment at first column__ + + ```xml + +###### Blank Lines + +__In declarations ⇨ 1__ + +```xml + +###### Imports + +__Class count to use import with `*` ⇨ 999__ + +```xml + +#### Related sources + +- [Android Code Styles comparison](https://github.com/ogaclejapan/android-code-styles) License ------- - [![Public domain](https://licensebuttons.net/p/zero/1.0/88x31.png)](https://creativecommons.org/publicdomain/zero/1.0/legalcode) diff --git a/configs/codestyles/CesardsAndroid.xml b/configs/codestyles/CesardsAndroid.xml new file mode 100644 index 0000000..3a30658 --- /dev/null +++ b/configs/codestyles/CesardsAndroid.xml @@ -0,0 +1,385 @@ + + + + +

+ + + + xmlns:android + Namespace: + + + +
+
+ + + + xmlns:.* + Namespace: + + + BY_NAME + +
+
+ + + + .*:id + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + ^$ + + + +
+
+ + + + style + ^$ + + + +
+
+ + + + .* + ^$ + + + BY_NAME + +
+
+ + + + .*:layout_width + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:layout_height + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:layout_.* + http://schemas.android.com/apk/res/android + + + BY_NAME + +
+
+ + + + .*:width + http://schemas.android.com/apk/res/android + + + BY_NAME + +
+
+ + + + .*:height + http://schemas.android.com/apk/res/android + + + BY_NAME + +
+
+ + + + .* + http://schemas.android.com/apk/res/android + + + BY_NAME + +
+
+ + + + .* + .* + + + BY_NAME + +
+ + + + \ No newline at end of file diff --git a/configs/coding-standards.md b/configs/coding-standards.md new file mode 100644 index 0000000..c2a6614 --- /dev/null +++ b/configs/coding-standards.md @@ -0,0 +1,69 @@ +Java/Android Coding guidelines +============================== + +-
__Comments__ +- __Naming__ +- __Others__ + +
+ + +#### Comments + +- If it is totally necessary (naming should be good enough to not doing this), write down a class description like this: + ```java + /** + * Class description (if its totally necessary) + */ + public class DomainModel { + ... + } + ``` + +- Objects/Methods documentation should follow this format (Starting in _capitalize_ and ending with _dot_). + ```java + /** One-line comment. */ + public abstract String sampleMethod2(); + ``` + +
+ +
+#### Naming + +- Don't use abbreviations for naming your methods/objects. They will be much less descriptive. + ```java + private ImageView panoramaImg; // ✗ + private ImageView panoramaImage; // ✓ + ``` + +- Don't use Hungarian notation. Good reasons on [Jake Wharton's post](http://jakewharton.com/just-say-no-to-hungarian-notation/) + +
+ +
+#### Others + +- Don't use magic values. Hardcoded Strings/numbers won't be allowed. Make declarative constants instead. + ```java + private static final int ANIMATION_DURATION_IN_MILLIS = 1000; + ``` + +- Include unit type in members. + ```java + private long animationTimeInMillis = ANIMATION_DURATION_IN_MILLIS; + ``` + +- A method should contain as much 15-20 lines of code. Split and win. Divide your responsabilitites. Pretty sure a big +method can be splitted in smaller ones delegating some responsabilitites. + +- Preconditions are __good__. + ```java + if (preConditionFailed()) { + return; + } + ``` + +- Non Null checks in Presentation/Domain layers. We __must__ avoid `null` checks in those layers. Having in +consideration that ideally, the only API we could get null values from is an external data source, we must avoid +doing unnecessary `null` checks and that way avoid filling our code with annotations like `@NonNull` or `@Null` diff --git a/configs/inspection/Square.xml b/configs/inspection/Square.xml old mode 100644 new mode 100755 diff --git a/configs/templates/ISSUE_TEMPLATE.md b/configs/templates/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..6cf97ec --- /dev/null +++ b/configs/templates/ISSUE_TEMPLATE.md @@ -0,0 +1,9 @@ +If you are raising a bug, please include this information: + +1. Steps taken to see the issue. +2. Observed behaviour +3. Expected behaviour. +4. Device and OS. +5. Can you reproduce it? How often: 100% of the time, 50%, just.. sometimes? + +Ideally include screenshots too where appropriate. diff --git a/configs/templates/Timber.xml b/configs/templates/Timber.xml new file mode 100644 index 0000000..9348f21 --- /dev/null +++ b/configs/templates/Timber.xml @@ -0,0 +1,61 @@ + + + + + + + + + + \ No newline at end of file diff --git a/install.sh b/install.sh index b7617b1..c2944d4 100755 --- a/install.sh +++ b/install.sh @@ -1,7 +1,7 @@ #!/bin/bash -# Installs Square's IntelliJ configs into your user configs. +# Installs cesards's IntelliJ/AndroidStudio configs into your user configs. -echo "Installing Square IntelliJ configs..." +echo "Installing cesards code style configs..." CONFIGS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/configs" @@ -12,7 +12,7 @@ for i in $HOME/Library/Preferences/IntelliJIdea* \ $HOME/.IdeaIC*/config \ $HOME/.AndroidStudio*/config do - if [ -d $i ]; then + if [[ -d $i ]]; then # Install codestyles mkdir -p $i/codestyles @@ -21,9 +21,12 @@ do # Install inspections mkdir -p $i/inspection cp -frv "$CONFIGS/inspection"/* $i/inspection + + # Install templates + mkdir -p $i/inspection + cp -frv "$CONFIGS/templates"/* $i/templates fi done echo "Done." echo "" -echo "Restart IntelliJ and/or AndroidStudio, go to preferences, and apply 'Square' or 'SquareAndroid'."