Guidelines

This site is for tech Q&A. Please keep your posts focused on the subject at hand.

Ask one question at a time. Don't conflate multiple problems into a single question.

Make sure to include all relevant information in your posts. Try to avoid linking to external sites.

Links to documentation are fine, but in addition you should also quote the relevant parts in your posts.

0 votes
377 views
377 views

I'm using the following settings to automatically run puppet validate on a manifest when I'm saving the file:

autocmd FileType puppet set makeprg=puppet_validate.sh\ %
autocmd BufWritePost *.pp :silent make | redraw!

However, we're also using Bolt, and Bolt plans written in the Puppet language also have the extension .pp. Validating those files produces an error like this:

Error: Could not parse for environment production: Syntax error at 'targets'

because the validator doesn't support bolt-specific syntax.

How can I skip validation for bolt plans?

in Scripting
by (115)
2 18 33
edit history

Please log in or register to answer this question.

1 Answer

0 votes
 

Define a different file type for bolt plans. In ~/.vim/ftdetect/puppet.vim change the line

au! BufRead,BufNewFile *.pp setfiletype puppet

to something like this:

au! BufRead,BufNewFile *.pp if search('^plan ', 'n') == 0 | setfiletype puppet | else | setfiletype bolt | endif

The search() function returns the line number of the next line matching the given expression (the parameter 'n' tells vim to not move the cursor to that line). A result of 0 means that no matching line was found (i.e. you have a Puppet manifest) and the file type is set to puppet. Otherwise the file type is set to bolt. Since makeprg=puppet_validate.sh is defined only for the file type puppet the command is not being run when saving files with the type bolt.

If you want to keep the syntax highlighting, copy ~/.vim/syntax/puppet.vim to ~/.vim/syntax/bolt.vim (the name of the file must match the file type you set for Bolt plans).

by (115)
2 18 33
edit history
...