Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

whitespace is enforced asymetric #8

Closed
bastelfreak opened this issue Aug 2, 2020 · 8 comments
Closed

whitespace is enforced asymetric #8

bastelfreak opened this issue Aug 2, 2020 · 8 comments

Comments

@bastelfreak
Copy link
Member

Hi!
first off, sorry for the bad issue title. given the following code:

function yum::bool2num_hash_recursive($arg) {
  assert_type(Hash, $arg)
  $arg.map |$key, $value| {
    $return_value = $value ? {
      Boolean => bool2num($value),
      Hash    => yum::bool2num_hash_recursive($value),
      default => $value,
    }
    Hash( { $key => $return_value })
  }.reduce |$attrs_memo, $kv| {
    merge($attrs_memo, $kv)
  }
}

this puppet-lint plugin assumes that this code is fine. However I think the following line is bad:

    Hash( { $key => $return_value })

I don't understand why the plugin enforces a whitespace between ( and {, but not between } and ). This looks really odd. I think the first space needs to go away or a space should be added at the end.

@alexjfisher
Copy link
Member

I encountered a similar issue when using reduce with an empty hash as the starting value. eg

$servers.reduce({}) |$memo, $server| {
...
}

This fails manifest_whitespace_opening_brace_before. Trying to fix it by adding spaces either side of the hash didn't work.
ie

$servers.reduce( {} ) |$memo, $server| {

Now I get manifest_whitespace_closing_brace_after

The plugin is happy with

$servers.reduce( {}) |$memo, $server| {

though.

@cocker-cc
Copy link

Me too:

  $pub_key = ssh_keygen({ name => $username, public => true })                      
leads to: there should be a single space before an opening brace

  $pub_key = ssh_keygen( { name => $username, public => true } )                    
leads to: there should be either a bracket, punctuation mark, closing quote or a newline after a closing brace, or whitespace and none of the aforementioned

only
  $pub_key = ssh_keygen( { name => $username, public => true })                     
is happy

@jovandeginste
Copy link
Contributor

seems to be fixed

jovandeginste added a commit that referenced this issue Oct 6, 2022
Signed-off-by: Jo Vandeginste <[email protected]>
@natemccurdy
Copy link

natemccurdy commented Oct 6, 2022

@jovandeginste With version 0.2.0 of the gem, I still see inconsistent behavior in this check.

For example, given this manifest, only the first line should pass.
The last three lines should all report a problem:

Hash({ $key => $return_value })

Hash( { $key => $return_value } )
Hash( { $key => $return_value })
Hash(       { $key => $return_value })

However only line 3 reports a problem:

ERROR:manifest_whitespace_closing_brace_after - there should be either a bracket, punctuation mark, closing quote or a newline after a closing brace, or whitespace and none of the aforementioned on line 3

Seems like the whitespace to the right of an open parenthesis isn't being checked?

@jovandeginste
Copy link
Contributor

Yes, I added tests to track this. Work to be done!

@jovandeginste
Copy link
Contributor

I thinks this is fixed in v0.2.1

@jovandeginste
Copy link
Contributor

(Please provide more test cases if you find more issues!)

@natemccurdy
Copy link

Looks fixed to me. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants