php-getter-setter.vim
php-getter-setter.vim copied to clipboard
Trailing whitespaces after inserting getters or setters
Hi,
After generating a getter or a setter, an empty line with trailing whitespaces appears:
class foo
{
private $bar;
....
/**
* Get bar.
*
* @return bar.
*/
public function getBar()
{
return $this->bar;
}
}
This happens because the concerned line contains the \n character, and the indentation spaces are prepend to it.
What needs to be done is to not prepend the spaces to empty lines, as I did here.
Note: I wanted to do a PR, but my changes didn't work as expected, so I decided to create an issue instead.
Cheers.
oops, I'm really sorry answering you so late! I'll try to check what's happening.
Have the same issue, anyway @Dinduks you can trim trailing whitespace via autocommand for the whole file if that's okay for you:
function! StripTrailingWhitespace()
execute ':%s/\s\+$//e'
endfunction
This can be executed via autocommands, e.g.:
augroup code
autocmd!
" Remove whitespace at end of line
autocmd BufWritePre *.erb,*.rb,*.php,*.html,*.js,*.css,*.vim,*.vimrc,*.scss :call StripTrailingWhitespace()
augroup END
yep, I have something similar to clean trailing spaces. BTW, it's unrelated to this issue, but since then, I totally changed my mind about getters and setters. It's an antipattern to avoid if possible.