rodjek / vim-puppet

Puppet niceties for your Vim setup
Apache License 2.0
500 stars 137 forks source link

auto-indent wrong after a parameter named "include" #99

Closed lelutin closed 5 years ago

lelutin commented 5 years ago

hi there!

I'm currently using this plugin at commit 5680f0d (so current master) and I'm seeing an auto indentation bug.

Here's a case where the problem can be reproduced:

some::resource { 'blah':
  include => 'gnaaaa',<enter here>
    <we're now placed one indentation level deeper without a good reason>

I can also see the same in resource that's already written with one of its parameters named "include" and using the '=' command to fix indentation.

This only happens when there is a parameter named "include". For some reason, that triggers an indent level.

I haven't investigated the plugin's code yet to know where this can come from.

lelutin commented 5 years ago

I've figured out that it was caused by this elseif block https://github.com/rodjek/vim-puppet/blob/master/indent/puppet.vim#L70

I've managed to fix the issue by changing line 70's regular expression to make it more specific to the include case with class names on different lines.

The style might not be the best.. if you find a better way to fix this, please adjust as you see accordingly fit:

70     elseif pline =~ '^\s*include\(\s\+[a-zA-Z0-9_:]\+,\)\+$'

the above makes sure that only alphanum chars, underscores and colons are present between the space and the last comma. It also lets one have multiple class names separated by commas before the end of the line. thus, it excludes all other cases which includes the case of a resource parameter named "include" as in the example in the previous comment