Skip to content

Commit 6ae6788

Browse files
committed
Merge pull request ribot#12 from ribot/add_extra_rules
Add a few extra rules
2 parents e5be6f5 + 7500ce6 commit 6ae6788

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

project_and_code_guidelines.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class MyClass {
199199

200200
Braces around the statements are required unless the condition and the body fit on one line.
201201

202-
If the condition and the body fit on one line and that line is shorter than the max line length, then do __not__ use braces e.g.
202+
If the condition and the body fit on one line and that line is shorter than the max line length, then braces are not required, e.g.
203203

204204
```java
205205
if (condition) body();
@@ -212,7 +212,9 @@ if (condition)
212212
body(); // bad!
213213
```
214214
215-
### 2.2.6 Use standard Java annotations
215+
### 2.2.6 Annotations
216+
217+
#### 2.2.6.1 Annotations practices
216218

217219
According to the Android code style guide, the standard practices for some of the predefined annotations in Java are:
218220

@@ -222,6 +224,26 @@ According to the Android code style guide, the standard practices for some of th
222224

223225
More information about annotations guidelines can be found [here](http://source.android.com/source/code-style.html#use-standard-java-annotations).
224226

227+
#### 2.2.6.2 Annotations style
228+
229+
__Classes, Methods and Constructors__
230+
231+
When annotations are applied to a class, method or constructor they are listed after the documentation block and should appear as __one annotation per line__ .
232+
233+
```java
234+
/* This is the documentation block about the class */
235+
@AnnotationA
236+
@AnnotationB
237+
public class MyAnnotatedClass { }
238+
```
239+
240+
__Fields__
241+
242+
Annotations applying to fields should be listed __on the same line__, unless the line reaches the maximum line length.
243+
244+
```java
245+
@Nullable @Mock DataManager mDataManager;
246+
```
225247

226248
### 2.2.7 Limit variable scope
227249

@@ -431,6 +453,24 @@ There are two __exceptions__ where is possible to have lines longer than 100:
431453

432454
There isn't an exact formula that explains how to line-wrap and quite often different solutions are valid. However there are a few rules that can be applied to common cases.
433455

456+
__Break at operators__
457+
458+
When the line is broken at an operator, the break comes __before__ the operator. For example:
459+
460+
```java
461+
int longName = anotherVeryLongVariable + anEvenLongerOne - thisRidiculousLongOne
462+
+ theFinalOne;
463+
```
464+
465+
__Assignment Operator Exception__
466+
467+
An exception to the break at operators rule is the assignment operator `=`, where the line break should happen __after__ the operator.
468+
469+
```java
470+
int longName =
471+
anotherVeryLongVariable + anEvenLongerOne - thisRidiculousLongOne + theFinalOne;
472+
```
473+
434474
__Method chain case__
435475

436476
When multiple methods are chained in the same line - for example when using Builders - every call to a method should go in its own line, breaking the line before the `.`

0 commit comments

Comments
 (0)