rodjek / puppet-lint

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

Erroneous "WARNING: indentation of => is not properly aligned" since 2.4.0 #912

Closed jeremie-pierson closed 4 years ago

jeremie-pierson commented 4 years ago

Since the 2.4.0 version, we have seen new warnings pop up in our code base. The "=>" seems to be properly aligned, but each warning points to a line where there are non-ASCII characters in a double quoted string (french accented "é" for example).

Digging through the changelog for 2.4.0, I see that double-quoted strings scanning has been rewritten. Looking at the new code, it seems to me that the "length" local variable in PuppetLint::Lexer#tokenise refers to the chunk length in characters, but now is the length in bytes for double-quoted strings. Maybe this is related to these new spurrious warnings?

rodjek commented 4 years ago

Hi @jeremie-pierson, could you provide an example of a manifest that demonstrates the problem?

jeremie-pierson commented 4 years ago

Oh sorry, should have thought about that from the start :-)

A minimal example with only the problematic warning (tested with v2.4.2) :

# Demonstrate a problem in puppet-lint
class warn_indent {
  $var1 = 'value1'
  $var2 = 'value2'
  $var3 = 'value3'

  my_defined_type { 'title':
    barbaz => $var3,
    quux   => "Caractères accentués et variable 1 ${var1}",
    foo    => "Caractères accentués et variable 2 ${var2}",
  }
}

It seems the bug may be a bit more complex than I thought...

rodjek commented 4 years ago

Thanks for the example. Hah yeah, that's quite broken!

jeremie-pierson commented 4 years ago

I tried the above patch and can confirm it fixes the issue. Thanks 👍

dioni21 commented 4 years ago

Is it possible to make the code aware of pre/post 2.0 ruby? We are still in puppet 3.3, with ruby 1.9.3 (please, don't blame the messenger), and this still happens in our setup. Curiously, only if UTF chars come in pairs:

See this example code:

define bugs::a () {
  fail( "á${::osfamily}á" )
  #fail( "${::osfamily}á" ) # No error
  #fail( "á${::osfamily}" ) # No error
  #fail( 'áá' ) # No error

  bugs::b{ 'test':

It returns with the following errors, even after the patch:

BEGIN puppet-lint

bugs/a.pp - ERROR: Resource bugs::b in global space on line 7

  bugs::b{ 'test':
    ^

bugs/a.pp - WARNING: indent should be 4 chars and is 2 on line 3

  #fail( "${::osfamily}á" ) # No error
  ^

bugs/a.pp - WARNING: indent should be 4 chars and is 2 on line 4

  #fail( "á${::osfamily}" ) # No error
  ^

bugs/a.pp - WARNING: indent should be 4 chars and is 2 on line 5

  #fail( 'áá' ) # No error
  ^

bugs/a.pp - WARNING: indent should be 4 chars and is 2 on line 7

  bugs::b{ 'test':
  ^

bugs/a.pp - WARNING: indent should be 4 chars and is 2 on line 8

  }
  ^

bugs/a.pp - WARNING: indent should be 2 chars and is 0 on line 9

  }
  ^

END puppet-lint