lint: check for bad white space habits
A little coding hygiene cannot hurt. Add a simple awk script to check all source files for bad white space habits: - trailing white space - trailing new lines at the end of files - missing new line at the end of files - spaces followed by tabs The script outputs color when the terminal supports it. It exits with a non-zero code when there was at least one white space issue found. Call the script in the lint step. Example output of the awk script: config/default_styleset:1:# <-- trailing whitespace config/default_styleset:3:# <-- trailing whitespace doc/aerc.1.scd:78: Executes an arbitrary command in the background. Aerc will set the <-- trailing whitespace doc/aerc.1.scd:234: <-- trailing whitespace doc/aerc.1.scd:237: <-- trailing whitespace worker/types/thread_test.go:74: // return ErrSkipThread<-- space(s) followed by tab(s) worker/lib/testdata/message/invalid/hexa: trailing new line(s) Fix issues reported by the script. NB: The ENDFILE match is a GNU extension. It will be ignored on BSD-awk and trailing new lines will not be detected. The lint make target is only invoked on alpine linux which has GNU awk anyway. NB: Empty cells in scdoc tables require trailing white space... Avoid this by setting content in these cells. I don't really see a use for empty cells. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Moritz Poldrack <moritz@poldrack.dev>
This commit is contained in:
parent
b22639ab20
commit
ebcd6fcea1
9 changed files with 77 additions and 39 deletions
1
Makefile
1
Makefile
|
@ -61,6 +61,7 @@ fmt:
|
|||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
@contrib/check-whitespace `git ls-files` && echo white space ok.
|
||||
@$(GO) run mvdan.cc/gofumpt -l . | grep ^ \
|
||||
&& echo The above files need to be formatted, please run make fmt && exit 1 \
|
||||
|| echo all files formatted.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#
|
||||
#
|
||||
# aerc default styleset
|
||||
#
|
||||
#
|
||||
# This styleset uses the terminal defaults as its base.
|
||||
# More information on how to configure the styleset can be found in
|
||||
# the aerc-stylesets(7) manpage. Please read the manual before
|
||||
|
|
51
contrib/check-whitespace
Executable file
51
contrib/check-whitespace
Executable file
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/awk -f
|
||||
|
||||
BEGIN {
|
||||
isatty = system("test -t 1") == "0"
|
||||
retcode = 0
|
||||
}
|
||||
|
||||
function color(code, s) {
|
||||
if (isatty) {
|
||||
return "\033[" code "m" s "\033[0m"
|
||||
}
|
||||
return s
|
||||
}
|
||||
function red(s) { return color("31", s) }
|
||||
function green(s) { return color("32", s) }
|
||||
function magenta(s) { return color("35", s) }
|
||||
function cyan(s) { return color("36", s) }
|
||||
function bg_red(s) { return color("41", s) }
|
||||
function hl_ws(s, pattern) {
|
||||
gsub(pattern, bg_red("&"), s)
|
||||
# convert tab characters to 8 spaces to allow coloring
|
||||
gsub(/\t/, " ", s)
|
||||
return s
|
||||
}
|
||||
|
||||
/ +\t+/ {
|
||||
retcode = 1
|
||||
print magenta(FILENAME) cyan(":") green(FNR) cyan(":") \
|
||||
hl_ws($0, " +\\t+") red("<-- space(s) followed by tab(s)")
|
||||
}
|
||||
|
||||
/[ \t]+$/ {
|
||||
retcode = 1
|
||||
print magenta(FILENAME) cyan(":") green(FNR) cyan(":") \
|
||||
hl_ws($0, "[ \\t]+$") red("<-- trailing whitespace")
|
||||
}
|
||||
|
||||
ENDFILE {
|
||||
# will only match on GNU awk, ignored on non-GNU versions
|
||||
if ($0 ~ /^[ \t]*$/) {
|
||||
retcode = 1
|
||||
print magenta(FILENAME) cyan(": ") red("trailing new line(s)")
|
||||
} else if (RT != "\n") {
|
||||
retcode = 1
|
||||
print magenta(FILENAME) cyan(": ") red("no new line at end of file")
|
||||
}
|
||||
}
|
||||
|
||||
END {
|
||||
exit retcode
|
||||
}
|
|
@ -390,7 +390,7 @@ These options are configured in the *[statusline]* section of aerc.conf.
|
|||
| %T
|
||||
: general on/off information (e.g. passthrough, threading, sorting)
|
||||
| %>
|
||||
: does not print anything but all format specifier that follow will be right justified.
|
||||
: does not print anything but all format specifier that follow will be right justified.
|
||||
|
||||
*separator*
|
||||
Specifies the separator between grouped statusline elements (e.g. for
|
||||
|
@ -854,7 +854,7 @@ each binding context:
|
|||
*$ex*
|
||||
This can be set to a keystroke which will bring up the command input in this
|
||||
context.
|
||||
|
||||
|
||||
Default: ':'
|
||||
|
||||
In addition to letters, special keys may be specified in <angle brackets>. The
|
||||
|
@ -867,63 +867,63 @@ following special keys are supported:
|
|||
| semicolon
|
||||
: ;
|
||||
| tab
|
||||
:
|
||||
: Tab
|
||||
| enter
|
||||
:
|
||||
: Enter
|
||||
| up
|
||||
:
|
||||
: Up arrow
|
||||
| c-up
|
||||
: Ctrl+Up
|
||||
| a-up
|
||||
: Alt+Up
|
||||
| down
|
||||
:
|
||||
: Down arrow
|
||||
| c-down
|
||||
: Ctrl+Down
|
||||
| a-down
|
||||
: Alt+Down
|
||||
| right
|
||||
:
|
||||
: Right arrow
|
||||
| c-right
|
||||
: Ctrl+Right
|
||||
| a-right
|
||||
: Alt+Right
|
||||
| left
|
||||
:
|
||||
: Left arrow
|
||||
| c-left
|
||||
: Ctrl+Left
|
||||
| a-left
|
||||
: Alt+Left
|
||||
| pgup
|
||||
:
|
||||
: Page Up
|
||||
| c-pgup
|
||||
: Ctrl+PageUp
|
||||
| a-pgup
|
||||
: Alt+PageUp
|
||||
| pgdn
|
||||
:
|
||||
: Page Down
|
||||
| c-pgdn
|
||||
: Ctrl+PageDn
|
||||
| a-pgdn
|
||||
: Alt+PageDn
|
||||
| home
|
||||
:
|
||||
: Home
|
||||
| end
|
||||
:
|
||||
: End
|
||||
| insert
|
||||
:
|
||||
: Insert
|
||||
| delete
|
||||
:
|
||||
: Delete
|
||||
| exit
|
||||
:
|
||||
: Exit
|
||||
| cancel
|
||||
:
|
||||
: Cancel
|
||||
| print
|
||||
:
|
||||
: Print screen
|
||||
| pause
|
||||
:
|
||||
: Pause
|
||||
| backtab
|
||||
:
|
||||
: Shift+Tab
|
||||
| c-space
|
||||
: Ctrl+Space
|
||||
| a-space
|
||||
|
|
|
@ -83,11 +83,10 @@ styling.
|
|||
[[ *Style Object*
|
||||
:[ *Description*
|
||||
| default
|
||||
: The default style object used for normal ui elements while not
|
||||
using specialized configuration.
|
||||
: The default style object used for normal ui elements while not using specialized configuration.
|
||||
| error
|
||||
: The style used to show errors.
|
||||
| warning
|
||||
| warning
|
||||
: The style used when showing warnings.
|
||||
| success
|
||||
: The style used for success messages.
|
||||
|
@ -158,8 +157,7 @@ For example, the following wildcards can be made using this syntax.
|
|||
| \*.fg=blue
|
||||
: Set the foreground color of all style objects to blue.
|
||||
| \*list.bg=hotpink
|
||||
: Set the background color of all style objects that end in list
|
||||
to hotpink.
|
||||
: Set the background color of all style objects that end in list to hotpink.
|
||||
|
||||
## Selected modifier
|
||||
Selected modifier can be applied to any style object. The style provided for
|
||||
|
|
|
@ -76,7 +76,7 @@ These commands work in any context.
|
|||
as a delta from the selected tab.
|
||||
|
||||
*exec* <command...>
|
||||
Executes an arbitrary command in the background. Aerc will set the
|
||||
Executes an arbitrary command in the background. Aerc will set the
|
||||
environment variables *$account* and *$folder* when the command is
|
||||
executed from an Account tab or an opened message.
|
||||
|
||||
|
@ -237,10 +237,8 @@ message list, the message in the message viewer, etc).
|
|||
|
||||
Seen
|
||||
Message has been read
|
||||
|
||||
Answered
|
||||
Message has been answered
|
||||
|
||||
Flagged
|
||||
Message is flagged for urgent/special attention
|
||||
|
||||
|
|
2
worker/lib/testdata/message/invalid/hexa
vendored
2
worker/lib/testdata/message/invalid/hexa
vendored
|
@ -24,5 +24,3 @@ Content-Type: text/html; charset=utf-8
|
|||
<ObJECT>
|
||||
|
||||
--Nextpart_1Q2YJhd197991794467076Pgfa--
|
||||
|
||||
|
||||
|
|
|
@ -135,18 +135,13 @@ func (w *worker) handleMessage(msg types.WorkerMessage) error {
|
|||
case *types.CheckMail:
|
||||
go w.handleCheckMail(msg)
|
||||
return nil
|
||||
|
||||
// not implemented, they are generally not used
|
||||
// in a notmuch based workflow
|
||||
// case *types.DeleteMessages:
|
||||
// case *types.CopyMessages:
|
||||
// return w.handleCopyMessages(msg)
|
||||
// case *types.AppendMessage:
|
||||
// return w.handleAppendMessage(msg)
|
||||
// case *types.CreateDirectory:
|
||||
// return w.handleCreateDirectory(msg)
|
||||
// case *types.RemoveDirectory:
|
||||
// return w.handleRemoveDirectory(msg)
|
||||
}
|
||||
return errUnsupported
|
||||
}
|
||||
|
|
|
@ -70,9 +70,6 @@ func TestNewWalk(t *testing.T) {
|
|||
var prefix []string
|
||||
lastLevel := 0
|
||||
tree.Walk(func(t *Thread, lvl int, e error) error {
|
||||
// if t.Uid%2 != 0 {
|
||||
// return ErrSkipThread
|
||||
// }
|
||||
if e != nil {
|
||||
fmt.Printf("ERROR: %v\n", e)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue