code-conduct.en.md 6.7 KB
Newer Older
T
terrymanu 已提交
1
+++
T
terrymanu 已提交
2
title = "Code of Conduct" 
T
terrymanu 已提交
3
weight = 4
T
terrymanu 已提交
4 5 6
chapter = true
+++

T
terrymanu 已提交
7 8 9
The following code of conduct is based on full compliance with [ASF CODE OF CONDUCT](https://www.apache.org/foundation/policies/conduct.html).

## Development Guidelines
T
terrymanu 已提交
10 11

 - Write codes with heart. Pursue clean, simplified and extremely elegant codes. Agree with concepts in <Refactoring: Improving the Design of Existing Code> and <Clean Code: A Handbook of Agile Software Craftsmanship>.
T
terrymanu 已提交
12 13 14
 - Be familiar with codes already had, to keep consistent with the style and use.
 - Highly reusable, no duplicated codes or configurations.
 - Delete codes out of use in time.
T
terrymanu 已提交
15

T
terrymanu 已提交
16
## Contributor Covenant Submitting of Conduct
T
terrymanu 已提交
17

J
Jared Tan 已提交
18
 - Make sure all the test cases are passed, Make sure `./mvnw clean install` can be compiled and tested successfully.
19
 - Make sure the test coverage rate is not lower than the master branch.
kimmking's avatar
kimmking 已提交
20
 - Make sure to check codes with Checkstyle. codes that violate check rules should have special reasons. Find checkstyle template from `https://github.com/apache/shardingsphere/blob/master/src/resources/checkstyle.xml`, please use checkstyle `8.8` to run the rules.
J
Juan Pan(Trista) 已提交
21 22
 - Careful consideration for each `pull request`; Small and frequent `pull request` with complete unit function is welcomed.
 - Conform to `Contributor Covenant Code of Conduct` below.
W
wubingting 已提交
23
 - If using IDEA,you can import the recommended [Settings](https://shardingsphere.apache.org/community/data/shardingsphere-settings.jar).
T
terrymanu 已提交
24

T
terrymanu 已提交
25
## Contributor Covenant Code of Conduct
T
terrymanu 已提交
26

T
terrymanu 已提交
27 28
 - Use linux line separators.
 - Keep indents (including blank lines) consistent with the previous one.
T
terrymanu 已提交
29
 - Keep one blank line after class definition.
T
terrymanu 已提交
30
 - No meaningless blank lines. Please extract private methods to instead of blank lines if too long method body or different logic code fragments.
T
terrymanu 已提交
31 32 33
 - Use meaningful class, method and variable names, avoid to use abbreviate. 
 - Return values are named with `result`; Variables in the loop structure are named with `each`; Replace `each` with `entry` in map.
 - Exceptions when catch are named with `ex`; Exceptions when catch but do nothing are named with `ignored`.
K
kimmking 已提交
34
 - Name property files with `Spinal Case`(a variant of `Snake Case` which uses hyphens `-` to separate words). 
T
terrymanu 已提交
35
 - Split codes that need to add notes with it into small methods, which are explained with method names.
T
terrymanu 已提交
36
 - Have constants on the left and variable on the right in `=` and `equals` conditional expressions; Have variable on the left and constants on the right in `greater than` and `less than` conditional expressions.
T
terrymanu 已提交
37
 - Beside using same names as input parameters and global fields in assign statement, avoid using `this` modifier.
T
terrymanu 已提交
38
 - Design class as `final` class expect abstract class for extend.
T
terrymanu 已提交
39
 - Make nested loop structures a new method.
T
terrymanu 已提交
40
 - Order of members definition and parameters should be consistent during classes and methods.
T
terrymanu 已提交
41 42 43
 - Use guard clauses in priority.
 - Minimize the access permission for classes and methods.
 - Private method should be just next to the method in which it is used; writing private methods should be in the same as the appearance order of private methods.
T
terrymanu 已提交
44
 - No `null` parameters or return values.
T
terrymanu 已提交
45
 - Replace if else return and assign statement with ternary operator in priority.
T
terrymanu 已提交
46
 - Replace constructors, getters, setter methods and log variable with lombok in priority.
T
terrymanu 已提交
47 48
 - Use `LinkedList`  in priority. Use `ArrayList` for use index to get element only.
 - Use capacity based `Collection` such as `ArrayList`, `HashMap` must indicate initial capacity to avoid recalculate capacity.
T
terrymanu 已提交
49 50 51
 - Use English in all the logs and javadoc.
 - Include Javadoc, todo and fixme only in the comments.
 - Only `public` classes and methods need javadoc, other methods, classes and override methods do not need javadoc.
T
terrymanu 已提交
52

T
terrymanu 已提交
53
## Contributor Covenant Unit Test of Conduct
T
terrymanu 已提交
54

T
terrymanu 已提交
55
 - Test codes and production codes should follow the same kind of code of conduct.
T
terrymanu 已提交
56 57 58 59 60 61 62 63 64
 - Unit test should follow AIR (Automatic, Independent, Repeatable) principle.
   - Automatic: Unit test should run automatically, not interactively. Check test result manually and `System.out`, `log` are prohibited, use assert to check test results.
   - Independent: Call each other and sequence dependency during unit test cases are prohibited. Every test case should run independent.
   - Repeatable: Unit test case should not dependency external environment, they can run repeatable.
 - Unit test should follow BCDE (Border, Correct, Design, Error) design principle.
   - Border: Border value test, test for loop border, special value and value sequence to get expect result.
   - Correct: Correct value test, test for correct value to get expect result.
   - Design: Design with production codes.
   - Error: Error value test, test for error input, exception to get expect result.
T
terrymanu 已提交
65
 - Without particular reasons, test cases should be fully covered.
T
terrymanu 已提交
66
 - Every test case need precised assertion.
T
terrymanu 已提交
67 68 69 70 71 72
 - Environment preparation codes should be separate from test codes.
 - Only those that relate to junit `Assert`, hamcrest `CoreMatchers` and `Mockito` can use static import.
 - For single parameter asserts, `assertTrue`, `assertFalse`, `assertNull` and `assertNotNull` should be used.
 - For multiple parameter asserts, `assertThat` should be used.
 - For accurate asserts, try not to use `not`, `containsString` to make assertions.
 - Actual values of test cases should be named `actualXXX`, expected values `expectedXXX`.
T
terrymanu 已提交
73
 - Class for test case and `@Test` annotation do not need javadoc.
T
terrymanu 已提交
74

T
terrymanu 已提交
75
## Contributor Covenant G4 Code of Conduct
T
terrymanu 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88
 - Common Conduct
   - Every line cannot over `200` chars, guarantee every line have complete semantics.
 - Lexer Conduct
   - Every rule should be in single line, no empty line between rules.
   - Rule of lexer name should capitalization. If name composite with more than one word, use `underline` to separate. Rule name of `DataType` and `Symbol` should end with `underline`. If rule name is conflicted with ANTLR's keyword, should take an `underline` behind rule name.
   - For private rule in lexer should use `fragment`, rule with `fragment` should define behind of public rule which they served.
   - Common rule of lexer should put in file `Keyword.g4`, every database may has customized rule file by themselves. For example: `MySQLKeyword.g4`.
 - Parser Conduct
   - After every rule finish, blank line should no indents.
   - No space before rule name definition. One space between `colon` and rule, `semicolon` should take a new line and keep indents (including blank lines) consistent with the previous one.
   - If a rule's branch is over than `5`, every branch take a new line.
   - Rule name of parser should same with java variable's camel case.
   - Define separate files for every SQL type, file name should consist of `database` + `SQL type` + `Statement`. For example: `MySQLDQLStatement.g4`.