diff options
author | classabbyamp <dev@placeviolette.net> | 2022-05-26 22:32:04 -0400 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2022-06-25 00:06:14 +0200 |
commit | 16e6e3e9852c988b5bf0b416fabaeaa03588696f (patch) | |
tree | c65de2ec299cd1d861d71f4579dd36b4a407da95 /xlint | |
parent | 7f4d32a54b868b2413caefb55111625ca1d410b9 (diff) | |
download | xtools-16e6e3e9852c988b5bf0b416fabaeaa03588696f.tar.gz xtools-16e6e3e9852c988b5bf0b416fabaeaa03588696f.tar.xz xtools-16e6e3e9852c988b5bf0b416fabaeaa03588696f.zip |
xlint: lint multi-line value indentation
- use awk because scan (grep) does not work over multiple lines - finds the opening and closing of a variable definition, then checks if it's on the first line and, if not, checks if the first characters are not <space><:graph:> - checks both single- and double-quoted strings, in a loop because shell makes that hard - detects lines in multi-line strings that end in a backslash - `| sort -u -k2` so it does not spam, similar to the other indent lint
Diffstat (limited to 'xlint')
-rwxr-xr-x | xlint | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/xlint b/xlint index d94a507..b8f7893 100755 --- a/xlint +++ b/xlint @@ -47,6 +47,22 @@ explain_make_check() { ' $template } +check_multiline_vars() { + for q in '"' "'"; do + awk "-vargument=$argument" "-vquote=$q" -vOFS=: ' + BEGIN { + reBegin="^[^=]+=" quote "[^" quote "=]*$"; reEnd="^[^" quote "=]*" quote "$"; + firstLine="^[^ ].*=" quote ".*$"; lastLine="^( [[:graph:]]|" quote "$)" + } + ($0 ~ reBegin),($0 ~ reEnd) { + if ($0 !~ firstLine && $0 !~ lastLine) + print(argument, FNR, " indent multi-line continuations with a single space") + if ($0 ~ /\\$/) + print(argument, FNR, " do not use backslashes to end lines in multi-line continuations") + }' $template + done | sort -u -k2 +} + variables_order() { local curr_index max_index max_index_line variables_end message line local line_number max_index_line_number @@ -484,6 +500,7 @@ for argument; do header file_end explain_make_check + check_multiline_vars else echo no such template "$argument" 1>&2 fi | sort -t: -n -k2 -k3 | grep . && ret=1 |