diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2020-07-06 13:05:50 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2020-07-06 13:05:50 +0300 |
commit | 43193636d4d8f0a7caa8df8d80aeaddf50316069 (patch) | |
tree | b9fc964ec433d3fcf670d9e18e110c629d3f4a74 /STYLE.md | |
parent | de246fc4268b1db216a348f01f37f54907b21635 (diff) |
Add field name for git.Flag
Go vet, editors, and other tooling will emit warnings when a struct
doens't have the fields names, as it falls back on ordering. That could
introduce bugs when new fields are added with the same type at the
beginning of a struct.
To reduce the number of warnings in my editor, I ran a `sed` script to
update the code.
Diffstat (limited to 'STYLE.md')
-rw-r--r-- | STYLE.md | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -239,15 +239,15 @@ important to mitigate these injection risks: - When toggling an option, prefer a longer flag over a short flag for readability. - - Desired: `git.Flag{"--long-flag"}` is easier to read and audit - - Undesired: `git.Flag{"-L"}` + - Desired: `git.Flag{Name: "--long-flag"}` is easier to read and audit + - Undesired: `git.Flag{Name: "-L"}` - When providing a variable to configure a flag, make sure to include the variable after an equal sign - - Desired: `[]git.Flag{"-a="+foo}` prevents flag injection - - Undesired: `[]git.Flag("-a"+foo)` allows flag injection + - Desired: `[]git.Flag{Name: "-a="+foo}` prevents flag injection + - Undesired: `[]git.Flag(Name: "-a"+foo)` allows flag injection - Always define a flag's name via a constant, never use a variable: - - Desired: `[]git.Flag{"-a"}` - - Undesired: `[]git.Flag{foo}` is ambiguous and difficult to audit + - Desired: `[]git.Flag{Name: "-a"}` + - Undesired: `[]git.Flag{Name: foo}` is ambiguous and difficult to audit ## Go Imports Style |