Skip to content
Snippets Groups Projects
Commit 9551cb59 authored by Natanael Copa's avatar Natanael Copa
Browse files

CODINSTYLE: adjust to current defacto standards

- rename to CODINGSTYLE.md
- use "recommendations" instead of "rules"
- remove reference to unpackaged shellcheck
- try shorten text
- mention eval
parent f76efb35
No related merge requests found
...@@ -2,35 +2,61 @@ ...@@ -2,35 +2,61 @@
Thank you for taking interest in contributing to our aports repository. Thank you for taking interest in contributing to our aports repository.
As consistency and readability are so important for the quality of our APKBUILD As consistency and readability are so important for the quality of our APKBUILD
and thus the quality of Alpine Linux, we kindly ask to follow these rules. and thus the quality of Alpine Linux, we kindly ask to follow these
recommendations.
## Language ## Language
Alpine Linux APKBUILD files are inherently just shell scripts. As such, they Alpine Linux APKBUILD files are inherently just POSIX shell scripts. Try avoid
should pass the shellcheck linter. extensions, even if they work or are accepted by busybox ash. (using keyword
`local` is an exception)
## Naming convention ## Naming convention
APKBUILD files uses snake_case. For example functions, variable names etc. are Use snake_case. Functions, variables etc. should be lower-cased with
all lower-cased with using an underscore as a separator/space. Local 'private' underscores to separate words.
variables and functions are pre-fixed with a single underscore. Double
underscores are reserved and should not be used. Local 'private' variables and functions n global scope should be pre-fixed
with a single underscore to avoid nameclash with internal variables in
`abuild`.
Double underscores are reserved and should not be used.
```sh ```sh
_my_variable="data" _my_variable="data"
``` ```
### Bracing ### Bracing
Curly braces for functions are on the next line, to indicate a function. Curly braces for functions are on the same line.
```sh
prepare() {
...
}
```
Markers to indicate a compound statement, are on the same line. Markers to indicate a compound statement, are on the same line.
#### if ...; then
```sh ```sh
prepare()
{
if [ true ]; then if [ true ]; then
echo "It is so" echo "It is so"
fi fi
} }
``` ```
#### while ...; do
```sh
while ...; do
...
done
```
#### for ...; do
```sh
for ...; do
...
done
```
### Spacing ### Spacing
All keywords and operators are separated by a space. All keywords and operators are separated by a space.
...@@ -49,42 +75,37 @@ prepare() ...@@ -49,42 +75,37 @@ prepare()
This ensures code is always neatly aligned and properly indented. This ensures code is always neatly aligned and properly indented.
Space before tab should be avoided.
## Line length ## Line length
A line should not be longer then 80 lines. While this is not a hard limit, it A line should not be longer then 80 lines. While this is not a hard limit, it
is strongly recommended to avoid having longer lines, as long lines reduce is strongly recommended to avoid having longer lines, as long lines reduce
readability and invite deep nesting. readability and invite deep nesting.
## Variables ## Variables
### Quoting ### Quoting
Always quote strings. As in shell there is no concept of data types (other then Quote strings containing variables, command substitutions, spaces or shell meta
strings). There is no such thing as characters, integers or booleans. All data characters, unless careful unquoted expansion is required.
should thus be quoted.
```sh Don't quote _literal_ integers.
pkgver="0"
```
### Bracing ### Bracing
Always use curly braces around variables. While shells do not require this, Only use curly braces around variables when needed.
being consistent in variable usage helps. Also there is no need to try to
determine what the actual variable is and if it may not end up being empty.
```sh
foo_bar="foobar"
foo="bar"
```
In the above, it could be argued it is immediately visible that ***$foo_bar***
is the string 'foobar'. However if the variable is defined var away from the
invocation, this is not clear any longer. To avoid these amigo ties, always
use curly braces.
```sh ```sh
foo="${foo}_bar" foo="${foo}_bar"
foo_bar="${foo}" foo_bar="$foo"
``` ```
## Subshell usage ## Subshell usage
Always use `$()` syntax, not backticks, as backticks are hard to spot. Use `$()` syntax, not backticks, as backticks are hard to spot.
## Sorting ## Sorting
Some items tend to benefit from being sorted. A list of sources, dependencies Some items tend to benefit from being sorted. A list of sources, dependencies
etc. Always try to find a reasonable sort order, where alphabetically tends to etc. Always try to find a reasonable sort order, where alphabetically tends to
be the most useful one. be the most useful one.
## Eval
`eval` is evil and should be avoided.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment