Skip to content

Commit

Permalink
bump rubocop version and auto-fix
Browse files Browse the repository at this point in the history
Precommit-Verified: ef3f684fca4e118cb72e3dafa6068ff5801ba07c5bfdb9b1287bc1089fb206b2
  • Loading branch information
mattlqx committed Apr 11, 2022
1 parent 6f04ef4 commit 0864367
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ Metrics/AbcSize:
branches, and conditions.
Reference: 'http://c2.com/cgi/wiki?AbcMetric'
Enabled: true

AllCops:
NewCops: enable
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

source 'https://rubygems.org'

gem 'rubocop', '0.77.0'
gem 'rubocop', '~> 1.27.0'
31 changes: 18 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
jaro_winkler (1.5.4)
parallel (1.19.1)
parser (2.7.0.2)
ast (~> 2.4.0)
rainbow (3.0.0)
rubocop (0.77.0)
jaro_winkler (~> 1.5.1)
ast (2.4.2)
parallel (1.22.1)
parser (3.1.1.0)
ast (~> 2.4.1)
rainbow (3.1.1)
regexp_parser (2.3.0)
rexml (3.2.5)
rubocop (1.27.0)
parallel (~> 1.10)
parser (>= 2.6)
parser (>= 3.1.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.16.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
ruby-progressbar (1.10.1)
unicode-display_width (1.6.0)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.17.0)
parser (>= 3.1.1.0)
ruby-progressbar (1.11.0)
unicode-display_width (2.1.0)

PLATFORMS
ruby

DEPENDENCIES
rubocop (= 0.77.0)
rubocop (~> 1.27.0)

BUNDLED WITH
1.17.2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To check Chef cookbook version bumps, use the `chef-cookbook-version` hook. Each
To unit test Ruby changes in your repo, use the `rspec` hook. Each path in your repo with a `spec` directory should have a `Gemfile` that includes your desired version of rspec (or a derivative library). It will be installed via Bundler prior to testing. Rspec will only be run against the closest directory in a changed file's path with a spec dir.

- repo: https://github.com/mattlqx/pre-commit-ruby
rev: v1.3.4
rev: v1.3.5
hooks:
- id: rubocop
- id: foodcritic
Expand Down
2 changes: 1 addition & 1 deletion bin/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def bump_required?(file)
end == true
end

def changed_cookbooks(paths = nil, bump_check: true)
def changed_cookbooks(paths = nil, bump_check: true) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
changed_cookbooks = []
paths ||= ARGV
paths.each do |file|
Expand Down
13 changes: 6 additions & 7 deletions bin/cookbook-wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def file_from_git_history(path)

# Simple metadata.rb reader
class MetadataReader
attr_reader :data
attr_reader :raw
attr_reader :data, :raw

def initialize(metadata, path)
@data = {}
Expand All @@ -36,7 +35,7 @@ def empty?
@data.empty?
end

def method_missing(sym, *args, &_block) # rubocop:disable Metrics/AbcSize, Style/MethodMissingSuper, Style/MissingRespondToMissing, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def method_missing(sym, *args, &_block) # rubocop:disable Metrics/AbcSize, Style/MissingRespondToMissing, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
return @data[sym] if args.empty?

if args.length > 1
Expand Down Expand Up @@ -66,10 +65,10 @@ def method_missing(sym, *args, &_block) # rubocop:disable Metrics/AbcSize, Style

if type == 'rb'
old_metadata = MetadataReader.new(file_from_git_history("#{cookbook}/metadata.rb"), "#{cookbook}/metadata.rb")
new_metadata = MetadataReader.new(IO.read("#{cookbook}/metadata.rb"), "#{cookbook}/metadata.rb")
new_metadata = MetadataReader.new(File.read("#{cookbook}/metadata.rb"), "#{cookbook}/metadata.rb")
else
old_metadata = JSON.parse(file_from_git_history("#{cookbook}/metadata.json")) rescue {} # rubocop:disable Style/RescueModifier
new_metadata = JSON.parse(IO.read("#{cookbook}/metadata.json"))
new_metadata = JSON.parse(File.read("#{cookbook}/metadata.json"))
end

if old_metadata.empty?
Expand All @@ -95,10 +94,10 @@ def method_missing(sym, *args, &_block) # rubocop:disable Metrics/AbcSize, Style
new_metadata_content = new_metadata.raw.sub(
/^(\s+)*version(\s+)(['"])[0-9.]+['"](.*)$/, "\\1version\\2\\3#{bumped_version}\\3\\4"
)
IO.write("#{cookbook}/metadata.rb", new_metadata_content)
File.write("#{cookbook}/metadata.rb", new_metadata_content)
else
new_metadata['version'] = bumped_version
IO.write("#{cookbook}/metadata.json", JSON.dump(new_metadata))
File.write("#{cookbook}/metadata.json", JSON.dump(new_metadata))
end
end

Expand Down
3 changes: 2 additions & 1 deletion bin/cookstyle-wrapper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'English'
require_relative 'common'

# Check each changed file for a spec directory in its heirarchy
Expand All @@ -20,4 +21,4 @@
# Install cookstyle and drop args that are paths
system('bundle install >/dev/null') || exit(false)
system("bundle exec cookstyle --color #{fix} #{changed_cookbooks(bump_check: false).map(&:first).join(' ')}")
exit($?.exitstatus)
exit($CHILD_STATUS.exitstatus)
1 change: 1 addition & 0 deletions bin/foodcritic-wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def spec_walk(path)
test_dirs = []
ARGV.each do |file|
next unless File.exist?(file)

test_dir = spec_walk(file)
test_dirs << test_dir if test_dir
end
Expand Down

0 comments on commit 0864367

Please sign in to comment.