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

(CONT-666) Skip classref types #93

Merged
merged 2 commits into from
Feb 28, 2023
Merged

Conversation

chelnak
Copy link

@chelnak chelnak commented Feb 27, 2023

This PR updates the resource_indexes method so that it will skip CLASSREF tokens.

For more background on this PR please see #31

@chelnak chelnak requested a review from a team as a code owner February 27, 2023 17:12
@chelnak chelnak self-assigned this Feb 27, 2023
@chelnak chelnak added the bug Something isn't working label Feb 27, 2023
@chelnak chelnak force-pushed the CONT-666-skip_classref_types branch 2 times, most recently from aa19756 to 6c74495 Compare February 27, 2023 17:20
lib/puppet-lint/data.rb Show resolved Hide resolved
lib/puppet-lint/data.rb Show resolved Hide resolved
spec/unit/puppet-lint/data_spec.rb Show resolved Hide resolved
lib/puppet-lint/data.rb Show resolved Hide resolved
@chelnak chelnak requested a review from ekohl February 28, 2023 09:27
lib/puppet-lint/data.rb Outdated Show resolved Hide resolved
This commit fixes voxpupuli/puppet-lint-trailing_comma-check#31.

It appears that the `resource_indexes` method cannot differentiate between a
resource declaration and a defaults declaration.

If we compare the two, you can see that a defaults declaration type starts with a
capital letter whereas a resource declaration does not.

```puppet
Service { 'foo':
  ensure => running,
}
```

```puppet
service { 'foo':
  ensure => running,
}
```

When the `resource_indexes` method runs, it initially selects tokens by the
presence of a colon then works to the right to decide if there are any violations.

That means we are actually only starting to collect information about the
declaration after the name.. so we never know the actual type of the declaration.

```puppet
Service { 'foo':
               ↑ (here)
  ensure => running,
}
```

https://github.com/puppetlabs/puppet-lint/blob/main/lib/puppet-lint/data.rb#L167

In contrast, `defaults_indexes` will skip any tokens that do not have a type of
`:CLASSREF` because we know that a defaults declaration will always start
with a capital letter (See [puppet-lint.com](http://puppet-lint.com/developer/tokens/)
for more information on token types).

This commit fixes the above by ensuring that `resource_indexes` checks
the type of resource that it is analysing and skips the itteration if it
detects a `:CLASSREF`.
This commit introduces some new spec test for the resource_indexes
method.

We check that it does not pick up any defaults declarations and also
that it can properly parse resource declarations after the change.
Copy link

@GSPatton GSPatton left a comment

Choose a reason for hiding this comment

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

looks great!

@GSPatton GSPatton merged commit 2fd501a into main Feb 28, 2023
@GSPatton GSPatton deleted the CONT-666-skip_classref_types branch February 28, 2023 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants