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

Drop reverse and always require Puppet 4+ style and Ruby 2.1 #21

Merged
merged 4 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
language: ruby
sudo: false
cache: bundler
script:
- bundle exec rake spec
- bundle exec rake spec
rvm:
- 1.9.3
- 2.0.0
- 2.1.5
- "2.1"
- "2.4"
- "2.5"
- "2.6"
matrix:
fast_finish: true
deploy:
provider: rubygems
api_key:
secure: "QpxxVQ8+0af/LVbFtZRYlJcY431xX7VTqPT7jjwO3x0PV3MLJcH+baGvoxAceAEbD0xgHPQGiFxSNhAZIwDBg9hW28ADP089HO0yxPxY/G7hBdLU9ZpSVe14p2V2M30SKcJ+vmNugK4oq26/ebe5NmoUCALClwyjZMNCXHr8OoQ="
on:
rvm: 2.1.5
rvm: "2.6"
tags: true
all_branches: true
notifications:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ source 'https://rubygems.org'
gemspec

group :release do
gem 'github_changelog_generator', :require => false, :git => 'https://github.com/github-changelog-generator/github-changelog-generator' if RUBY_VERSION >= '2.2.2'
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Since this is so rarely released and it usually works on small modules I'd like to avoid it. Especially since this is not managed in any way.

gem 'github_changelog_generator', :require => false
end
15 changes: 3 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ puppet-lint-absolute_classname-check
[![Gem Version](https://img.shields.io/gem/v/puppet-lint-absolute_classname-check.svg)](https://rubygems.org/gems/puppet-lint-absolute_classname-check)
[![Gem Downloads](https://img.shields.io/gem/dt/puppet-lint-absolute_classname-check.svg)](https://rubygems.org/gems/puppet-lint-absolute_classname-check)
[![Coverage Status](https://img.shields.io/coveralls/voxpupuli/puppet-lint-absolute_classname-check.svg)](https://coveralls.io/r/voxpupuli/puppet-lint-absolute_classname-check?branch=master)
[![Gemnasium](https://img.shields.io/gemnasium/voxpupuli/puppet-lint-absolute_classname-check.svg)](https://gemnasium.com/voxpupuli/puppet-lint-absolute_classname-check)
[![Donated by Camptocamp](https://img.shields.io/badge/donated%20by-camptocamp-fb7047.svg)](#transfer-notice)

A puppet-lint plugin to check that classes are included by their absolute name.
Expand Down Expand Up @@ -39,26 +38,18 @@ gem 'puppet-lint-absolute_classname-check', :require => false

### Relative class name inclusion

Including a class by a relative name might lead to unexpected results [in Puppet 3](https://docs.puppet.com/puppet/3/lang_namespaces.html#relative-name-lookup-and-incorrect-name-resolution).
Including a class by a relative name might lead to unexpected results [in Puppet 3](https://docs.puppet.com/puppet/3/lang_namespaces.html#relative-name-lookup-and-incorrect-name-resolution). That's why a lot of manifests explicitly include by the absolute name. Since Puppet 4 names are always absolute and this is no longer needed. This lint check helps to clean up your manifests.

#### What you have done

```puppet
include foobar
include ::foobar
```

#### What you should have done

```puppet
include ::foobar
```

#### Reverse this check

This check can be reversed to check for Puppet > 4.

```ruby
PuppetLint.configuration.absolute_classname_reverse = true
include foobar
```

#### Disabling the check
Expand Down
21 changes: 5 additions & 16 deletions lib/puppet-lint/plugins/check_absolute_classname.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
PuppetLint.new_check(:relative_classname_inclusion) do
def check
message = 'class included by absolute name (::$class)'

tokens.each_with_index do |token, token_idx|
reverse = PuppetLint.configuration.absolute_classname_reverse || false
if reverse
pattern = '^(?!::)'
message = 'class included by absolute name (::$class)'
else
pattern = '^::'
message = 'class included by relative name'
end
if [:NAME,:FUNCTION_NAME].include?(token.type) && ['include','contain','require'].include?(token.value)
s = token.next_code_token
next if s.nil?
Expand All @@ -22,7 +16,7 @@ def check
in_function += 1
elsif in_function > 0 && n && n.type == :RPAREN
in_function -= 1
elsif in_function.zero? && s.value !~ /#{pattern}/
elsif in_function.zero? && s.value.start_with?('::')
notify :warning, {
message: message,
line: s.line,
Expand All @@ -36,7 +30,7 @@ def check
elsif token.type == :CLASS and token.next_code_token.type == :LBRACE
s = token.next_code_token
while s.type != :COLON
if (s.type == :NAME || s.type == :SSTRING) && s.value !~ /#{pattern}/
if (s.type == :NAME || s.type == :SSTRING) && s.value.start_with?('::')
notify :warning, {
message: message,
line: s.line,
Expand All @@ -51,11 +45,6 @@ def check
end

def fix(problem)
reverse = PuppetLint.configuration.absolute_classname_reverse || false
problem[:token].value = if reverse
problem[:token].value[2..-1]
else
'::' + problem[:token].value
end
problem[:token].value = problem[:token].value[2..-1]
end
end
2 changes: 2 additions & 0 deletions puppet-lint-absolute_classname-check.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Gem::Specification.new do |spec|
A puppet-lint plugin to check that classes are included by their absolute name.
EOF

spec.required_ruby_version = '>= 2.1.0'

spec.add_dependency 'puppet-lint', '>= 1.0', '< 3.0'
spec.add_development_dependency 'coveralls'
spec.add_development_dependency 'mime-types'
Expand Down
Loading