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
69 views
69 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 (100)
1 4 11
edit history

Your answer

Preview

Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
By submitting this post you agree to our Terms & Conditions.
To avoid this verification in future, please log in or register.

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 (100)
1 4 11
edit history
...