Skip to content

Commit

Permalink
rubocop: autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Apr 21, 2023
1 parent 364ab60 commit 9c6df48
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
inherit_from: .rubocop_todo.yml

# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

Expand Down
54 changes: 54 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-04-21 15:31:06 UTC using RuboCop version 1.50.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: ForbiddenDelimiters.
# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$))
Naming/HeredocDelimiterNaming:
Exclude:
- 'puppet-lint-variable_contains_upcase.gemspec'

# Offense count: 6
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/puppet-lint/plugins/variable_contains_upcase_spec.rb'

# Offense count: 1
# Configuration parameters: IgnoredMetadata.
RSpec/DescribeClass:
Exclude:
- '**/spec/features/**/*'
- '**/spec/requests/**/*'
- '**/spec/routing/**/*'
- '**/spec/system/**/*'
- '**/spec/views/**/*'
- 'spec/puppet-lint/plugins/variable_contains_upcase_spec.rb'

# Offense count: 2
RSpec/RepeatedExampleGroupDescription:
Exclude:
- 'spec/puppet-lint/plugins/variable_contains_upcase_spec.rb'

# Offense count: 5
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Exclude:
- 'Gemfile'
- 'Rakefile'
- 'lib/puppet-lint/plugins/variable_contains_upcase.rb'
- 'puppet-lint-variable_contains_upcase.gemspec'
- 'spec/puppet-lint/plugins/variable_contains_upcase_spec.rb'

# Offense count: 1
Style/MultilineBlockChain:
Exclude:
- 'lib/puppet-lint/plugins/variable_contains_upcase.rb'
21 changes: 11 additions & 10 deletions lib/puppet-lint/plugins/variable_contains_upcase.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
PuppetLint.new_check(:variable_contains_upcase) do
def check
tokens.select { |r|
tokens.select do |r|
Set[:VARIABLE, :UNENC_VARIABLE].include? r.type
}.each do |token|
if token.value.gsub(/\[.+?\]/, '').match(/[A-Z]/)
notify :warning, {
:message => 'variable contains a capital letter',
:line => token.line,
:column => token.column,
:token => token,
}
end
end.each do |token|
next unless /[A-Z]/.match?(token.value.gsub(/\[.+?\]/, ''))

notify :warning, {
message: 'variable contains a capital letter',
line: token.line,
column: token.column,
token: token,
}
end
end

def fix(problem)
problem[:token].value.downcase!
end
Expand Down
10 changes: 2 additions & 8 deletions puppet-lint-variable_contains_upcase.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Gem::Specification.new do |spec|
spec.name = 'puppet-lint-variable_contains_upcase'
spec.name = 'puppet-lint-variable_contains_upcase'
spec.version = '1.4.0'
spec.homepage = 'https://github.com/fiddyspence/puppetlint-variablecase'
spec.license = 'MIT'
Expand All @@ -11,18 +11,12 @@ Gem::Specification.new do |spec|
'lib/**/*',
'spec/**/*',
]
spec.test_files = Dir['spec/**/*']
spec.summary = 'puppet-lint variable_case check'
spec.description = <<-EOF
Extends puppet-lint to ensure that your variables are all lower case
EOF

spec.required_ruby_version = '>= 2.7.0'

spec.add_dependency 'puppet-lint', '>= 3', '< 5'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rspec-its', '~> 1.0'
spec.add_development_dependency 'rspec-collection_matchers', '~> 1.0'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec-json_expectations'
spec.add_dependency 'puppet-lint', '>= 3', '< 5'
end
22 changes: 12 additions & 10 deletions spec/puppet-lint/plugins/variable_contains_upcase_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
context 'a variable containing a capital' do
let(:code) { '$fOobar' }

it 'should only detect a single problem' do
it 'onlies detect a single problem' do
expect(problems).to have(1).problem
end

it 'should create a warning' do
it 'creates a warning' do
expect(problems).to contain_warning(msg).on_line(1).in_column(1)
end
end

context 'variable containing a capital' do
let(:code) { '" $fOobar"' }

it 'should only detect a single problem' do
it 'onlies detect a single problem' do
expect(problems).to have(1).problem
end

it 'should create a warning' do
it 'creates a warning' do
expect(problems).to contain_warning(msg).on_line(1).in_column(3)
end
end
Expand All @@ -39,37 +39,39 @@
context 'fix variable containing a capital' do
let(:code) { '" $fOobar"' }

it 'should only detect a single problem' do
it 'onlies detect a single problem' do
expect(problems).to have(1).problem
end

it 'should fix the manifest' do
it 'fixes the manifest' do
expect(problems).to contain_fixed(msg).on_line(1).in_column(3)
end

it 'should downcase the variable name' do
it 'downcases the variable name' do
expect(manifest).to eq('" $foobar"')
end
end

context 'a hash with an upcase key should not fail' do
let(:code) { ' $myhash["Foo"]' }

it 'should not detect a single problem' do
it 'does not detect a single problem' do
expect(problems).to have(0).problem
end
end

context 'a hash with an upcase key should not fail' do
let(:code) { ' $myhash["Foo"]["bAr"]' }

it 'should not detect a single problem' do
it 'does not detect a single problem' do
expect(problems).to have(0).problem
end
end

context 'a hash variable with an upcase key should fail' do
let(:code) { ' $myHash["foo"]["bar"]' }

it 'should detect a single problem' do
it 'detects a single problem' do
expect(problems).to have(1).problem
end
end
Expand Down

0 comments on commit 9c6df48

Please sign in to comment.