Ur
Ur's own style for languages with no reference formatter, which breaks long lines where each language lets them break.
- Formats
- Shell, TOML, Urscal
- In
ur.toml [format] style = "ur"
Shell, formatted
cart.sh, as written#!/usr/bin/env bash
# What a cart costs: the sum of each item's price times its quantity, read from a CSV file of items.
set -euo pipefail
test -f "$1" || { echo "usage: cart.sh items.csv" >&2; exit 1; }
tail -n +2 "$1" | awk -F, '{ sum += $2 * $3 } END { printf "%.2f\n", sum }' | tee --append subtotals.log
ur format --style ur cart.sh#!/usr/bin/env bash
# What a cart costs: the sum of each item's price times its quantity, read from
# a CSV file of items.
set -euo pipefail
test -f "$1" || { echo "usage: cart.sh items.csv" >&2; exit 1; }
tail -n +2 "$1" | awk -F, '{ sum += $2 * $3 } END { printf "%.2f\n", sum }' |
tee --append subtotals.log
TOML, formatted
cart.toml, as written# What a cart holds: each item's name, price, and quantity, and the codes that discount them.
[cart]
items = [{ name = "hammer", price = 12.5, quantity = 1 }, { name = "nail", price = 0.05, quantity = 100 }]
codes = ["SPRING", "WELCOME", "FRIENDS-AND-FAMILY"]
ur format --style ur cart.toml# What a cart holds: each item's name, price, and quantity, and the codes that
# discount them.
[cart]
items = [{ name = "hammer", price = 12.5, quantity = 1 },
{ name = "nail", price = 0.05, quantity = 100 }]
codes = ["SPRING", "WELCOME", "FRIENDS-AND-FAMILY"]
Urscal, formatted
Discounts.rsc, as writtenmodule cart::Discounts
// Whether a cart's codes discount it: a code the store knows, on a cart holding more than one item.
bool discounted(Tree cart) = any(c <- codes(cart), contains(["SPRING", "WELCOME", "FRIENDS-AND-FAMILY"], unparse(c))) when size(items(cart)) > 1;
default bool discounted(Tree _) = false;
ur format --style ur Discounts.rscmodule cart::Discounts
// Whether a cart's codes discount it: a code the store knows, on a cart holding
// more than one item.
bool discounted(Tree cart) = any(c <- codes(cart),
contains(["SPRING", "WELCOME", "FRIENDS-AND-FAMILY"], unparse(c)))
when size(items(cart)) > 1;
default bool discounted(Tree _) = false;
Defaults
The shared options, as Ur sets them when nothing configures it. Its own names for them are read from its configuration files, but ur.toml sets them by the shared name only.
| Option | Default | Ur calls it |
|---|---|---|
width | 80 | |
max-width | ||
indent.width | 4 | |
indent.style | ||
line-ending | "auto" | |
trailing-comma.add | "preserve" | |
trailing-comma.forces-break | false | |
quotes | "preserve" | |
target |
Its own options
Ur takes no options of its own beyond the shared ones.