puppet-editor-services
puppet-editor-services copied to clipboard
Display puppet parser warnings
Summary of the new feature
The puppet parser validate command display some problematic lexical construct as warnings. Examples:
$server = 'localhost'
notify{"Path: ${server}\foo":}
Parser Warning: Unrecognized escape sequence '\f' (file: lexer.pp, line: 2, column: 29)
$number1 = 5000
$number2 = '6000'
$sum = $number1 + $number2
notify{"Sum: $sum":}
Parser Warning: The string '6000' was automatically coerced to the numerical value 6000 (file: lexer.pp, line: 3, column: 19)
I would like VSCode to show that warnings to the developer, so that they are aware of the problematic lexical construct they are using.
As a puppet code developer I want to be able to see lexer warning that puppet parser validates provides, so that I'm aware of problematical constructs in my code.
Thanks @SPIRIT-Betrieb . We will try and repo this
Okay, so the parser validation is only outputing the warnings to the console:
I, [2019-12-19T16:57:12.247540 #34376] INFO -- : Initializing settings...
I, [2019-12-19T16:57:12.248104 #34376] INFO -- : Using Facter v2.5.6
I, [2019-12-19T16:57:12.248658 #34376] INFO -- : Skipping preloading Puppet
--- Time to rock-n-roll
D, [2019-12-19T16:57:12.262523 #34376] DEBUG -- : [PUPPET LOG] [warning] Unrecognized escape sequence '\f'
---
Looks like we'll need to monkey_patch the lexer
https://github.com/puppetlabs/puppet/blob/55ca3acbbcc2aa91a3dab3b20046ecdd960746c5/lib/puppet/pops/parser/lexer_support.rb#L54-L63
We won't be able to do the number coercion though. That happens during a catalog compile, not parser validation. And compilations are an "expensive" thing to do.
Given a manifest of
$server = 'localhost'
notify{"Path: ${server}\foo":}
$number1 = 5000
$number2 = '6000'
$sum = $number1 + $number2
notify{"Sum: $sum":}
C:\Source\puppet-editor-services [master ≡ +0 ~1 -0 !]> puppet parser validate tmp/bah.pp
Warning: Unrecognized escape sequence '\f' (file: C:/Source/puppet-editor-services/tmp/bah.pp, line: 2, column: 29)
C:\Source\puppet-editor-services [master ≡ +0 ~1 -0 !]> puppet apply tmp/bah.pp
Failed to load feature test for cfpropertylist: cannot load such file -- CFPropertyList
Warning: Unrecognized escape sequence '\f' (file: C:/Source/puppet-editor-services/tmp/bah.pp, line: 2, column: 29)
Warning: The string '6000' was automatically coerced to the numerical value 6000 (file: C:/Source/puppet-editor-services/tmp/bah.pp, line: 6, column: 19)
Notice: Compiled catalog for xxxx in environment workstation_production in 0.10 seconds
Notice: Path: localhost\foo
Notice: /Stage[main]/Main/Notify[Path: localhost\foo]/message: defined 'message' as 'Path: localhost\foo'
Notice: Sum: 11000
Notice: /Stage[main]/Main/Notify[Sum: 11000]/message: defined 'message' as 'Sum: 11000'
Notice: Applied catalog in 0.06 seconds
I've raised a bug in puppet-lint as it appears it should be raising the warnings already
https://github.com/rodjek/puppet-lint/issues/907
I've got a WIP PR up to detect the issue. https://github.com/glennsarti/puppet-editor-services/tree/gh-211-lexer-warnings
I'll hold off a bit to see if puppet-lint fix the error first.
Just for your information: I raised a ticket for the compiler as well: https://tickets.puppetlabs.com/browse/PUP-10176 (I was the one raising this FR).