rodjek / puppet-lint

Check that your Puppet manifests conform to the style guide
MIT License
820 stars 204 forks source link

Changing parenthesis to braces with -f #928

Closed jguidini closed 3 years ago

jguidini commented 4 years ago

Hi!

Today using puppet-lint I had a strange behavior, and I don't no where the mistake.

My setup: SO: Debian 8 amd64 Puppet Server: 6.12 Puppet agent: 6.17.0 Puppet-lint: puppet-lint (2.4.2)

See a sample of code from my params.pp (yes, still exists here), this code works without errors:

[lot of code truncated]
175   # Comment
176   if lookup("${module_name}_chroot_dir_${trusted[hostname]}",Data,undef,false) {
177     $chroot_dir = lookup("${module_name}_chroot_dir_${trusted[hostname]}")
178   }
179   else {
180     $chroot_dir = undef
181     fail ( "Variável chroot_dir não retornada pelo Hiera - módulo: ${module_name} - trusted_hostname: ${trusted[hostname]}" )
182   }
183 
184   # Comment
185   if lookup("${module_name}_bind_user_${trusted[hostname]}",Data,undef,false) {
186     $bind_user = lookup("${module_name}_bind_user_${trusted[hostname]}")
187   }
188   else {
189     $bind_user = undef
190     fail ( "Variável bind_user não retornada pelo Hiera - módulo: ${module_name} - trusted_hostname: ${trusted[hostname]}" )
191   }
192 
193   # Comment
[lot of code truncated]

I Changed the code (on another file, config.pp. I not touch the params.pp) and run the tests:

$ puppet parser validate *.pp
$ puppet-lint -f *.pp
somefile.pp - WARNING: line has more than 140 characters on line 148

Ok, more tha 140 characters is not too bad.. works. My module run on agent and fails on sintax! Ups.. some thing wrong..

$ puppet parser validate *.pp
Error: Could not parse for environment production: Syntax error at '}' (file: PATH/params.pp, line: 181, column: 126)

See the line 181:

[lot of code truncated]
175   # Comment
176   if lookup("${module_name}_chroot_dir_${trusted[hostname]}",Data,undef,false) {
177     $chroot_dir = lookup("${module_name}_chroot_dir_${trusted[hostname]}")
178   }
179   else {
180     $chroot_dir = undef
181     fail ( "Variável chroot_dir não retornada pelo Hiera - módulo: ${module_name} - trusted_hostname: ${trusted[hostname]}"  }
182 
183   # Comment
184   if lookup("${module_name}_bind_user_${trusted[hostname]}",Data,undef,false) {
185     $bind_user = lookup("${module_name}_bind_user_${trusted[hostname]}")
186   }
187   else {
188     $bind_user = undef
189     fail ( "Variável bind_user não retornada pelo Hiera - módulo: ${module_name} - trusted_hostname: ${trusted[hostname]}"  }
190 
191   # Comment
[lot of code truncated]

Puppet-lint changed ) to } , breaking the code, of course.

In a diff form the result file and original:

$ diff params.pp params.pp_ori
181c181,182
<     fail ( "Variável chroot_dir não retornada pelo Hiera - módulo: ${module_name} - trusted_hostname: ${trusted[hostname]}"  }
---
>     fail ( "Variável chroot_dir não retornada pelo Hiera - módulo: ${module_name} - trusted_hostname: ${trusted[hostname]}" )
>   }
189c190,191
<     fail ( "Variável bind_user não retornada pelo Hiera - módulo: ${module_name} - trusted_hostname: ${trusted[hostname]}"  }
---
>     fail ( "Variável bind_user não retornada pelo Hiera - módulo: ${module_name} - trusted_hostname: ${trusted[hostname]}" )
>   }
197c199,200
<     fail ( "Variável bind_group não retornada pelo Hiera - módulo: ${module_name} - trusted_hostname: ${trusted[hostname]}"  }
---
>     fail ( "Variável bind_group não retornada pelo Hiera - módulo: ${module_name} - trusted_hostname: ${trusted[hostname]}" )
>   }
205c208,209
<     fail ( "Variável bind_url_download não retornada pelo Hiera - módulo: ${module_name} - trusted_hostname: ${trusted[hostname]}"  }
---
>     fail ( "Variável bind_url_download não retornada pelo Hiera - módulo: ${module_name} - trusted_hostname: ${trusted[hostname]}" )
>   }
214c218,219
<            trusted_hostname: ${trusted[hostname]}"  }
---
>            trusted_hostname: ${trusted[hostname]}" )
>   }
260c265
<       fail ( "Variável home_dsc não definida!! - ${module_name}"
---
>       fail ( "Variável home_dsc não definida!! - ${module_name}" )
267c272
<       fail ( "Variável user_dsc não definida!! - ${module_name}"
---
>       fail ( "Variável user_dsc não definida!! - ${module_name}" )
274c279
<       fail ( "Variável group_dsc não definida!! - ${module_name}"
---
>       fail ( "Variável group_dsc não definida!! - ${module_name}" )
281c286
<       fail ( "Variável maquina_dsp não definida!! - ${module_name}"
---
>       fail ( "Variável maquina_dsp não definida!! - ${module_name}" )
288c293
<       fail ( "Variável grupo_dsp não definida!! - ${module_name}"
---
>       fail ( "Variável grupo_dsp não definida!! - ${module_name}" )
295c300
<       fail ( "Variável path_conf_dsc não definida!! - ${module_name}"
---
>       fail ( "Variável path_conf_dsc não definida!! - ${module_name}" )
302c307
<       fail ( "Variável socket_dnstap_dsc não definida!! - ${module_name}"
---
>       fail ( "Variável socket_dnstap_dsc não definida!! - ${module_name}" )
309c314
<       fail ( "Variável url_geoip_dsc não definida!! - ${module_name}"
---
>       fail ( "Variável url_geoip_dsc não definida!! - ${module_name}" )

Of course I'm doing something wrong.. got to Puppet Style Guide search... and nothing .. search on puppet-lint manual, nothing..

Try puppet-lint talk more:

$ puppet-lint -f --with-context --with-filename --error-level all --show-ignored params.pp

And nothing show, but the file was modified in all the times that -f is used.

So, can you help me to identify if it is my mistake or a puppet mistake and how to solve this?

Best Regards!

rodjek commented 3 years ago

Hi @jguidini,

This is actually a duplicate of #912 (same underlying cause anyway, just presenting with a different broken behaviour). The fix will be included in the next release of puppet-lint.