php-getter-setter.vim icon indicating copy to clipboard operation
php-getter-setter.vim copied to clipboard

Trailing whitespaces after inserting getters or setters

Open Dinduks opened this issue 13 years ago • 3 comments

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.

Dinduks avatar Oct 06 '12 21:10 Dinduks

oops, I'm really sorry answering you so late! I'll try to check what's happening.

docteurklein avatar Apr 04 '13 08:04 docteurklein

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

DanielSiepmann avatar Apr 08 '16 08:04 DanielSiepmann

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.

docteurklein avatar Apr 08 '16 08:04 docteurklein