|author||Tom Ryder <email@example.com>||2017-10-30 17:54:47 +1300|
|committer||Tom Ryder <firstname.lastname@example.org>||2017-10-30 18:08:37 +1300|
|parent||Use `normal!` not `normal` in Vim config macro (diff)|
Switch to VimL functions for whitespace stripper
vim-vint says: >Do not use a command that has unintended side effects (see Google >VimScript Style Guide (Dangerous)) >Avoid commands that rely on user settings (see Google VimScript Style >Guide (Fragile)) In both cases, it's referring to the use of :substitute in this file. The Google style guide on which vim-vint is based says <https://google.github.io/styleguide/vimscriptguide.xml?showone=Fragile_commands#Fragile_commands>: >Avoid :s[ubstitute], as its behavior depends upon a number of local >settings. It also says <https://google.github.io/styleguide/vimscriptguide.xml?showone=Dangerous_commands#Dangerous_commands>: > Avoid using :s[ubstitute] as it moves the cursor and prints error > messages. Prefer functions (such as search()) better suited to > scripts. > > For many vim commands, functions exist that do the same thing with > fewer side effects. See :help functions() for a list of built-in > functions. I reimplemented the function based on an answer I found by `romainl` to a similar question: <https://vi.stackexchange.com/a/5962> There are plenty of other trailing-whitespace-stripping solutions out there, but this one can be mine. It now passes vim-vint. I'll make a plugin out of it at some point. The \m\C shibboleth at the front of the regular expression is to enforce the 'magic' setting for the regular expression, and to enforce case-sensitivity. This is recommended by the style guide: <https://google.github.io/styleguide/vimscriptguide.xml?showone=Dangerous_commands#Regular_Expressions > Prefix all regexes with \m\C. > > In addition to the case sensitivity settings, regex behavior depends > upon the user's nomagic setting. To make regexes act like nomagic and > noignorecase are set, prepend all regexes with \m\C. > > You are welcome to use other magic levels (\v) and case sensitivities > (\c) so long as they are intentional and explicit. Before I committed this, I checked with vint -s to include stylistic recommendations as well, and it insisted on l: prefixes to the `li` and `line` variable to make them explicitly local to the function, so I did that, too.
Diffstat (limited to 'README.md')
0 files changed, 0 insertions, 0 deletions