Overview
Resilience / 彈性
Stronger and easier to restore infrastructure. 更強大,更容易還原基礎架構
Safety / 安全
Stable code and infrastructure to have as less issues as possible by testing. 穩定的代碼和基礎架構可以通過測試減少問題的發生
Transparency / 透明度
Standard way of doing code following precise rules. 遵循精確規則的標準代碼編寫方式
Tools:
ESLint Example / ESLint示例 Helping you writing cleaner code / 幫助您編寫更簡潔的代碼
All our projects are made with JavaScript as possible.
If you need to use another language, check first if this is really required.
For now, we are still using JavaScript and not TypeScript.
Use Docker to run our software instead of doing by hands.
Main goal: Keep the same environment for everyone and everywhere (for developers, and production on Bobby / GCP / AWS).Code should contain the less warning as possible and be lint.
代碼應包含盡可能少的警告,並應是不起毛的。Env variables should be used.
應該使用環境變數。
Main Goal: Don't push secrets on GitLab + Every env different (SQL Server, Email server, etc).DNS can be changed to new IP without breaking code.
DNS可以更改為新IP,而不會破壞代碼。
Main Goal: Code shouldn't be dependant on infrastructure.CI / CD should deploy automatically if requirements are met.
如果滿足要求,CI / CD應該自動部署。
Old code can be updated but new code must follow the new way.
![]()
Please follow camelCase as possible.
const pesDowntimeReasonList = "";
const isOk;
const isStillOk
const is_not_ok;
Space
When you are writing statement, please use spaces:
true
const [video, setVideo] = useState();
const test = "Brilltek";
This is one is wrong
false
const [video,setVideo]=useState();
const test="Brilltek";
if, while, for and foreach should be followed by a space, and bracket preceded by space
true
if (a == b) {
a = 'foo';
}
_________________________
false
if(a == b){
a = 'foo';
}
Braces are placed on the same line as the start of the function, conditional, loop, etc. The else/elseif is placed on the same line as the previous closing brace.
const foo = (var) => {
if (is_null(var)) {
return true;
} else {
return false;
}
}
Do not put spaces in brackets.
true
$a = ['foo', 'bar'];
$c = $a[0];
$x = [];
_________________________
false
$a = [ 'foo', 'bar' ];
$c = a[ 0 ];
$x = [ ];
Switch
You need a good reason to use switch, don't use it when you can use an array or a JSON.
```js
switch(case) {
case "start":
color = "#FFFFF"
case "stop":
color = "#00000"
case "pause":
color = "#efefef"
}
```
This is example of bad usage of switch. This will just make your code more dirty.
Instead you can use a JSON structure like this :
const colors = {
start: "#FFFFF",
stop: "#00000",
pause: "#efefef"
}
color = colors[case]
Back End
Migrations
Always check field or column before create, update or delete.
You need to create a new migration that change the field of first one.
Routes
Keep your routes as simple as possible.
true
create:
POST /user
read:
GET /user
update:
PUT /user
delete:
DELETE /user
_________________________
false
create:
POST /user/create
read:
GET /user/get
update:
POST /user/update
DELETE:
POST /user/delete
Avoid repeat a word inside route or variable like this:
Bad: /pes/pes_downtime_badReason/DowntimeBadReasonUpdate
Change to PUT /pes/downtime/badReason