Strict rules
In the terminalela --spec strict-rules
Ela refuses to guess. Each rule below is an error with a message that says what to write instead.
| Rule | Error example | Write instead |
|---|---|---|
| Text and numbers never mix | "5" + 1, "10" < 9, "5" == 5 | int($x) + 1 |
No + on strings | "a" + "b" | "${a}${b}" |
| Conditions are booleans | if $name, if 1 | if $name != "", if len($xs) > 0 |
and, or, not take booleans | 1 and true | a comparison |
| Integers never wrap | 9223372036854775807 + 1 | a smaller number, or one written with a fraction, 9223372036854775807.0 + 1; float(...) of a whole number stays whole |
| Undefined variables | $typo | define it first |
| A glob matches nothing | ls *.nope | quote it to pass the text: ls '*.nope' |
| Missing map keys | $m["nope"] | has($m, "nope") first |
null is stored, compared and passed on, nothing else | $s.port + 1, "${v}", if $v when it is null | has($s, "port") or $v != null first |
| Struct literals give every field | P{x: 1} when P has two fields | all fields |
| Every parameter gets one argument | deploy(), deploy("a", target = "b") | each parameter without a default, once, by position or by name |
| Named arguments name a parameter | deploy("a", retry = 5) | a name the proc has: retries = 5 |
| Named arguments come last | deploy(retries = 5, "a") | deploy("a", retries = 5) |
| Defaults after the parameters without | proc f(a = 1, b) | proc f(b, a = 1) |
| A variadic parameter is never named or defaulted | proc f(xs: ..string = []), f(xs = "a") | proc f(xs: ..string), f("a") |
| Positions stay inside | $xs[5], $xs[-6:] on five items | -min(n, len($xs)), or len first |
_ holds nothing | echo $_ | name the value to keep it |
| A built-in's result is kept | list.append($xs, 1) or str.upper($s) alone on a line | xs = list.append($xs, 1), s = str.upper($s) (Results are kept) |
The environment through env | $HOME, export PATH = ... | $env.HOME, env.PATH = ... |
| A proc sees no script variable | $branch inside a proc, set by the script | a parameter: proc f(branch: string) |
| A constant is set once | ENDED = [] after ENDED :: [...] | another name |
| No backticks in a command | echo `date` | echo $(date), or 'date' for the text |
No Bash ${...} forms | ${NAME:-x}, ${#xs}, ${s%.txt} | env.get("NAME", "x"), len($xs), str.trim_suffix($s, ".txt") |
break and continue in a loop | break outside for or while | return, or exit |
- Text is known before the run.
ela --lintreports+between two strings and a field read on a string as the errors the run would give, where the script makes the value text: a string literal,$env.NAME, a constant declared as one, or a variable every assignment in its scope gives one.VERSION = "1.2"then"app-$VERSION.tar.gz"fails before any line runs; write"app-${VERSION}.tar.gz". - Values, not references. Assigning or passing a list, map or struct copies it. Changing a copy never changes the original. A loop's value is one too:
for i, x in $xschanges an item withxs[$i]["n"] = 0, andela --lintwarns of a change toxthat nothing after it reads. - A proc sees no script variable. It gets what it needs as parameters and gives back what it changes with
return(What a proc sees). - Blocks don't create scopes. Variables set inside
if,forandwhilestay visible after the block. - Declarations go at the top level and may be used before the line that declares them.
- Every call names a proc. Before the first line runs, ela checks each call in the script, in its procs and in the files it imports: a proc no file declares (
deploy()with noproc deploy), a package proc ela lacks (str.starts_with, wherestr.has_prefixis meant) and a proc an import lacks (git.clne) each stop the script there, with the message the call would give, so no line runs first.ela --checkreports every one. - Division.
//and%truncate towards zero, as in Go and Odin:-7 // 2is -3,-7 % 2is -1. - Command failures stop the script with the command's own exit code; a missing command exits with 127.
- Commands are only found on PATH. A name without a slash never runs a file from the current directory, and relative PATH entries are skipped.