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

Transfer plugin to Vox Pupuli #10

Merged
merged 4 commits into from
Nov 26, 2021
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
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Release

on:
push:
tags:
- '*'

jobs:
release:
runs-on: ubuntu-latest
if: github.repository_owner == 'voxpupuli'
steps:
- uses: actions/checkout@v2
- name: Install Ruby 3.0
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler: 'none'
- name: Build gem
run: gem build *.gemspec
- name: Publish gem to rubygems.org
run: gem push *.gem
env:
GEM_HOST_API_KEY: '${{ secrets.RUBYGEMS_AUTH_TOKEN }}'
- name: Setup GitHub packages access
run: |
mkdir -p ~/.gem
echo ":github: Bearer ${{ secrets.GITHUB_TOKEN }}" >> ~/.gem/credentials
chmod 0600 ~/.gem/credentials
- name: Publish gem to GitHub packages
run: gem push --key github --host https://rubygems.pkg.github.com/${{ github.repository_owner }} *.gem
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test

on:
- pull_request
- push

env:
BUNDLE_WITHOUT: release

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- ruby: "2.4"
- ruby: "2.5"
- ruby: "2.6"
- ruby: "2.7"
- ruby: "3.0"
coverage: "yes"
env:
COVERAGE: ${{ matrix.coverage }}
name: Ruby ${{ matrix.ruby }}
steps:
- uses: actions/checkout@v2
- name: Install Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run tests
run: bundle exec rake spec
- name: Verify gem builds
run: gem build *.gemspec
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/.bundle/
/.vendor
/vendor/gems/
/Gemfile.lock
pkg/
.ruby-*
*.gem
coverage
vendor/bundle
.vendor/
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

11 changes: 10 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
source 'https://rubygems.org'
source ENV['GEM_SOURCE'] || 'https://rubygems.org'

gemspec

group :release do
gem 'github_changelog_generator', require: false
end

group :coverage, optional: ENV['COVERAGE']!='yes' do
gem 'simplecov-console', :require => false
gem 'codecov', :require => false
end
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
puppet-lint-topscope-variable-check
========================
[![Build Status](https://api.travis-ci.org/sixt/puppet-lint-topscope-variable-check.svg)](https://travis-ci.org/sixt/puppet-lint-topscope-variable-check)
[![Gem Version](https://badge.fury.io/rb/puppet-lint-topscope-variable-check.svg)](https://badge.fury.io/rb/puppet-lint-topscope-variable-check)

[![License](https://img.shields.io/github/license/voxpupuli/puppet-lint-topscope-variable-check.svg)](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/blob/master/LICENSE)
[![Test](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/actions/workflows/test.yml/badge.svg)](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/actions/workflows/test.yml)
[![Release](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/actions/workflows/release.yml/badge.svg)](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/actions/workflows/release.yml)
[![RubyGem Version](https://img.shields.io/gem/v/puppet-lint-topscope-variable-check.svg)](https://rubygems.org/gems/puppet-lint-topscope-variable-check)
[![RubyGem Downloads](https://img.shields.io/gem/dt/puppet-lint-topscope-variable-check.svg)](https://rubygems.org/gems/puppet-lint-topscope-variable-check)

A puppet-lint plugin to check that topscope variables in a class do not begin with $::

Expand Down Expand Up @@ -73,13 +75,22 @@ PuppetLint.configuration.send('disable_topscope_variable')
```
## Limitations

The fix function of this plugin does not work when the variable is used in a string.
The fix function of this plugin does not work when the variable is used in a string and hasn't been enclosed with `{}`.
For example:

``` puppet
$foo = "/etc/$::foobar::path/test"
```

Note: The [Variables Not Enclosed](http://puppet-lint.com/checks/variables_not_enclosed/) check can fix the missing braces and then the fix from this plugin should work.

## Transfer Notice

This plugin and github repository was originally developed and maintained by [Sixt](https://www.sixt.com/).
On 2021/11/24 the github project was transferred to [Voxpupuli](https://voxpupuli.org/) for ongoing improvement and maintenance.

Previously: https://github.com/Sixt/puppet-lint-topscope-variable-check

## License
```
MIT License
Expand Down
16 changes: 14 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

RuboCop::RakeTask.new
RSpec::Core::RakeTask.new(:spec)

task default: :spec

begin
require 'rubygems'
require 'github_changelog_generator/task'

GitHubChangelogGenerator::RakeTask.new :changelog do |config|
config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file."
config.exclude_labels = %w{duplicate question invalid wontfix wont-fix skip-changelog modulesync}
config.user = 'voxpupuli'
config.project = 'puppet-lint-topscope-variable-check'
config.future_release = Gem::Specification.load("#{config.project}.gemspec").version
end
rescue LoadError
end
44 changes: 22 additions & 22 deletions spec/puppet-lint/plugins/topscope_variable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
context 'with fix disabled' do
context 'with correct topscope' do
let(:code) do
<<-PUP.strip_heredoc
<<~PUP
class foo::blub {
notify { 'foo':
message => $foo::bar
Expand All @@ -21,7 +21,7 @@ class foo::blub {

context 'with incorrect topscope' do
let(:code) do
<<-PUP.strip_heredoc
<<~PUP
class foo::blub {
notify { 'foo':
message => $::foo::bar
Expand All @@ -37,7 +37,7 @@ class foo::blub {

context 'with correct topscope in params' do
let(:code) do
<<-PUP.strip_heredoc
<<~PUP
class foo::blub(
String $foo = $params::foo
) {
Expand All @@ -53,7 +53,7 @@ class foo::blub(

context 'with incorrect topscope in params' do
let(:code) do
<<-PUP.strip_heredoc
<<~PUP
class foo::blub(
String $foo = $::foo::params::foo
) {
Expand All @@ -69,7 +69,7 @@ class foo::blub(

context 'with a fact that has been used improperly' do
let(:code) do
<<-PUP.strip_heredoc
<<~PUP
class foo::blub {
notify { 'foo':
message => $blub::bar
Expand All @@ -95,7 +95,7 @@ class foo::blub {

context 'with correct topscope' do
let(:code) do
<<-PUP.strip_heredoc
<<~PUP
class foo::blub {
notify { 'foo':
message => $foo::bar
Expand All @@ -111,7 +111,7 @@ class foo::blub {

context 'with incorrect topscope' do
let(:code) do
<<-PUP.strip_heredoc
<<~PUP
class foo::blub {
notify { 'foo':
message => $::foo::bar
Expand All @@ -129,7 +129,7 @@ class foo::blub {
end

it 'should remove :: after the $' do
expect(manifest).to eq <<-PUP.strip_heredoc
expect(manifest).to eq <<~PUP
class foo::blub {
notify { 'foo':
message => $foo::bar
Expand All @@ -141,7 +141,7 @@ class foo::blub {

context 'with incorrect topscope in quoted variable' do
let(:code) do
<<-PUP.strip_heredoc
<<~PUP
class foo::blub {
notify { 'foo':
message => ">${::foo::bar}<"
Expand All @@ -155,24 +155,24 @@ class foo::blub {
end

it 'should fix the problem' do
expect(problems).to contain_fixed(msg).on_line(3).in_column(19)
end

# it 'should remove :: after the $' do
# expect(manifest).to eq <<-PUP.strip_heredoc
# class foo::blub {
# notify { 'foo':
# message => ">${foo::bar}<"
# }
# }
# PUP
# end
expect(problems).to contain_fixed(msg).on_line(3).in_column(20)
end

it 'should remove :: after the $' do
expect(manifest).to eq <<~PUP
class foo::blub {
notify { 'foo':
message => ">${foo::bar}<"
}
}
PUP
end
end
end

context 'without a class scope' do
let(:code) do
<<-PUP.strip_heredoc
<<~PUP
include ::foo
PUP
end
Expand Down
34 changes: 25 additions & 9 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
require 'coveralls'
Coveralls.wear!
# frozen_string_literal: true

require 'puppet-lint'
PuppetLint::Plugins.load_spec_helper
begin
require 'simplecov'
require 'simplecov-console'
require 'codecov'
rescue LoadError
else
SimpleCov.start do
track_files 'lib/**/*.rb'

add_filter '/spec'

# strip left spaces from heredoc
# this emulates the behaviour of the ~ heredoc from ruby 2.3
class String
def strip_heredoc
gsub(/^#{scan(/^\s*/).min_by(&:length)}/, '')
enable_coverage :branch

# do not track vendored files
add_filter '/vendor'
add_filter '/.vendor'
end

SimpleCov.formatters = [
SimpleCov::Formatter::Console,
SimpleCov::Formatter::Codecov,
]
end

require 'puppet-lint'

PuppetLint::Plugins.load_spec_helper