Use diff in Code Style Guide, as shown in https://calmcode.io/til/md-diffs.html
parent
177f826f87
commit
1cc3006502
1 changed files with 10 additions and 6 deletions
|
@ -22,19 +22,23 @@ Be reasonable. Keeping within 80 characters is recommended, 120 is the maximum.
|
||||||
Variables
|
Variables
|
||||||
---------
|
---------
|
||||||
|
|
||||||
Limit the scope of variables to `local` when within a function.
|
|
||||||
|
|
||||||
Wrap your variables in `${curly} ${braces}`.
|
Wrap your variables in `${curly} ${braces}`.
|
||||||
|
|
||||||
Use `${snake_case}` for your variable names.
|
Use `${snake_case}` for your variable names.
|
||||||
|
|
||||||
Use existing variables whenever possible:
|
Use existing variables whenever possible:
|
||||||
* Good: `${PWD}` `${USER}`
|
```diff
|
||||||
* Bad: `$(pwd)` `$(whoami)`
|
- print "$(whoami) in $(pwd)"
|
||||||
|
+ print "${USER} in ${PWD}"
|
||||||
|
```
|
||||||
|
|
||||||
|
Limit the scope of variables to `local` when within a function.
|
||||||
|
|
||||||
When declaring a global variable, be explicit and do it using `typeset -g`. This avoids warnings when `WARN_CREATE_GLOBAL` is set:
|
When declaring a global variable, be explicit and do it using `typeset -g`. This avoids warnings when `WARN_CREATE_GLOBAL` is set:
|
||||||
* Good: `if (( ! ${+VAR} )) typeset -g VAR=1`
|
```diff
|
||||||
* Bad: `: ${VAR=1}`
|
- : ${VAR=1}
|
||||||
|
+ if (( ! ${+VAR} )) typeset -g VAR=1
|
||||||
|
```
|
||||||
|
|
||||||
Flow logic
|
Flow logic
|
||||||
----------
|
----------
|
||||||
|
|
Loading…
Reference in a new issue