Commit c65b3a5a authored by Petr Hošek's avatar Petr Hošek

JS first part

parent a7d28090
# EasyRedmine JavaScript guidelines
Main goal of this document is to highlight rules and recommendations for creation nice and maintainable JavaScript code.
## Rules strength
Rules described here comes at three different strengths.
- DO or DON'T are mandatory for any Javascript code and it is valid reason for rejection of a merge request if not followed.
- PREFER of AVOID is rules that should by followed but they are mandatory only for core implementation.
- CONSIDER are not mandatory, but it makes the reviewer happy if they are followed
## Default rules
Code style defined in this document is based on W3C standard conventions:
[JavaScript Coding Conventions](https://www.w3schools.com/js/js_conventions.asp)
[JavaScript Best Practices](https://www.w3schools.com/js/js_best_practices.asp)
Exceptions from this coding styles will be described further
## Naming
- DO name common variables with lowerCamelCase style. DON'T use snake_case or hyphens.
- DO name classes with UpperCamelCase.
- CONSIDER naming Constant also with lowerCamelCase
- DO name variables with descriptive names, not by short variables as 'a'.
## Indentation + spaces
- DO use spaces instead tabulators
- PREFER use spaces around operators ( = + - * / ), and after commas:
- PREFER use 2 spaces as a 1 indentation step
- PREFER use 4 spaces for continuation of previous line (if it is too long)
# Blocks
To prevent appearance of the pyramid of hell, this rules are given:
- DO use at most 4 level of indentation.
You can use control statements to flatten the structure
```javascript
// BAD
for (var i = 0; i < 10; i++) {
if (i % 2 === 0) {
for (var j = 0; j < 10; j++) {
if (j !== i) {
// -- do something
}
}
}
}
// GOOD
for (var i = 0; i < 10; i++) {
if (i % 2 !== 0) continue;
for (var j = 0; j < 10; j++) {
if (j === i) continue;
// -- do something
}
}
```
- AVOID defining callback in callback
- AVOID using very short blocks
```javascript
var a = 5;
// BAD
if (a === 5) {
return;
}
// GOOD
if (a === 5) return;
```
- DON'T use multiline `if` statement without `{}`
\ No newline at end of file
......@@ -5,6 +5,7 @@
3. Licence
4. [UI Guide](./UI/README.md)
5. [DEV Guide](./DEV/README.md)
6. [JS Guide](./JS/README.md)
Easy Software Ltd.
https://www.easysoftware.com
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment