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

Ignore data types where trailing commas are illegal #25

Merged
merged 2 commits into from
Sep 30, 2022

Conversation

chelnak
Copy link
Contributor

@chelnak chelnak commented Sep 30, 2022

Prior to this PR the plugin would evaluate a data types value array as a standard array type. This would cause the line to be flagged as invalid.

When running with --fix, the plugin would attempt to fix this condition by appending a comma token to the final element of the array.i

According to puppet-syntax this is invalid.

For example:

Vaid:

  Enum[
    'enforcing',
    'permissive',
    'disabled'
  ] $selinux_setting = 'permissive',

Invalid:

  Enum[
    'enforcing',
    'permissive',
    'disabled',
  ] $selinux_setting = 'permissive',

Running bundle exec rake syntax post fix returns the following
error:

Could not parse for environment *root*: Syntax error at ']' (file: ./test.pp, line: 7, column: 1)

The above is not true for normal array declarations. Puppet syntax will
happily parse a normal array with a trailing comma.

Valid auto-fix from the plugin

 $test = [
    'one',
    'two',
    'three',
  ]

This PR fixes the above by adding functionality to check whether the current array_index is actually an array of data type values.

If the condition is true we skip the current iteration so that it will not be linted.

@chelnak chelnak force-pushed the GH-16-ignore_enum_arrays branch 2 times, most recently from 8b9400c to 7b48fd1 Compare September 30, 2022 11:14
@chelnak chelnak changed the title (GH-16) Ignore Enum arrays (GH-16) Ignore data type arrays Sep 30, 2022
@chelnak
Copy link
Contributor Author

chelnak commented Sep 30, 2022

Doesn't look like these test failures were caused by me!

@ekohl ekohl linked an issue Sep 30, 2022 that may be closed by this pull request
@ekohl
Copy link
Member

ekohl commented Sep 30, 2022

I think #26 should fix that.

@bastelfreak
Copy link
Member

@chelnak tha ks for the PR. can you please rebase and add a unit test with your examples?

@chelnak
Copy link
Contributor Author

chelnak commented Sep 30, 2022

Yeah sure thing!

Prior to this commit the plugin would evaluate a data types value array as a
standard array type. This would cause the line to be flagged as invalid.

When running with `--fix`, the plugin would attempt to fix this condition
by appending a comma token to the final element of the array.i

According to puppet-syntax this is invalid.

For example:

Vaid:

```
  Enum[
    'enforcing',
    'permissive',
    'disabled'
  ] $selinux_setting = 'permissive',

```

Invalid:

```
  Enum[
    'enforcing',
    'permissive',
    'disabled',
  ] $selinux_setting = 'permissive',

```

Running `bundle exec rake syntax` post fix returns the following
error:

```
Could not parse for environment *root*: Syntax error at ']' (file: ./test.pp, line: 7, column: 1)
```

The above is not true for normal array declarations. Puppet syntax will
happily parse a normal array with a trailing comma.

Valid auto-fix from the plugin

```
 $test = [
    'one',
    'two',
    'three',
  ]
```

This commit fixes the above by adding functionality to check whether the current
`array_index` is actually an array of data type values.

If the condition is true we skip the current iteration so that it will
not be linted.
This commit updates the existing spec tests with examples that
demonstrate how the linter would ignore data type values.
@codecov
Copy link

codecov bot commented Sep 30, 2022

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage 👍

Coverage data is based on head (e425048) compared to base (078b7cf).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #25   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           60        61    +1     
=========================================
+ Hits            60        61    +1     
Impacted Files Coverage Δ
lib/puppet-lint/plugins/check_trailing_comma.rb 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@chelnak
Copy link
Contributor Author

chelnak commented Sep 30, 2022

Tests added an rebased.

From testing on my side, I'm pretty sure that this fixes the original issue. However, there might be cases that I haven't thought about or some further hardening that we can do.

Also I was purposely explicit with the extra next statement as I thought it might enhance readability somewhat.. More than happy to refactor this though.

Just let me know what you think 👍

@chelnak
Copy link
Contributor Author

chelnak commented Sep 30, 2022

I've also opened puppetlabs/puppet-lint#48

Even though it might take a while for everything to converge it should mean that we can remove a bit of duplication here in the future.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ekohl ekohl merged commit 19ee9a9 into voxpupuli:master Sep 30, 2022
@chelnak chelnak deleted the GH-16-ignore_enum_arrays branch October 1, 2022 07:01
@chelnak
Copy link
Contributor Author

chelnak commented Oct 1, 2022

Thanks for the merge!

Is there anything that I can do to help get this released?

@ekohl ekohl changed the title (GH-16) Ignore data type arrays Ignore data types Oct 1, 2022
@ekohl ekohl added the bug label Oct 1, 2022
@ekohl ekohl changed the title Ignore data types Ignore data types where trailing commas are illegal Oct 1, 2022
@ekohl
Copy link
Member

ekohl commented Oct 1, 2022

I wanted to add you as a reviewer on #28 but I noticed you're not in the VP org so I've invited you.

@chelnak
Copy link
Contributor Author

chelnak commented Oct 1, 2022

Thank you. I've joined, reviewed and approved.

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

Successfully merging this pull request may close these issues.

Adds comma after last element in Enum array
3 participants