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

Fix configuration loading on Ruby 3.1 #771

Merged
merged 1 commit into from
Feb 26, 2022
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
5 changes: 3 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ jobs:

- name: Prepare environment
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
bundle exec overcommit --sign
bundle exec overcommit --sign pre-commit

- name: Run pre-commit checks
run: bundle exec overcommit --run
6 changes: 4 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
- '3.1'
os:
- ubuntu
- windows

steps:
- uses: actions/checkout@v2
Expand All @@ -31,7 +30,10 @@ jobs:
bundler-cache: true

- name: Run tests
run: bundle exec rspec
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
bundle exec rspec

- name: Code coverage reporting
uses: coverallsapp/github-action@master
Expand Down
10 changes: 0 additions & 10 deletions .projections.json

This file was deleted.

6 changes: 0 additions & 6 deletions .simplecov

This file was deleted.

4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ gemspec

gem 'rspec', '~> 3.0'

# Generate coverage information in Travis builds
gem 'coveralls', '~> 0.8'
gem 'simplecov', '~> 0.21.0'
gem 'simplecov-lcov', '~> 0.8.0'

# Pin RuboCop for Travis builds.
gem 'rubocop', '0.82.0'
Expand Down
61 changes: 0 additions & 61 deletions appveyor.yml

This file was deleted.

4 changes: 2 additions & 2 deletions lib/overcommit/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def add_installation_options(opts)
@options[:force] = true
end

opts.on('-r [hook]', '--run [hook]', 'Run specified hook against all git tracked files. Defaults to `pre_commit`.') do |arg|
opts.on('-r [hook]', '--run [hook]', 'Run specified hook against all git tracked files. Defaults to `pre_commit`.') do |arg| # rubocop:disable Layout/LineLength
@options[:action] = :run_all
@options[:hook_to_run] = arg ? arg.to_s : 'run-all'
end
Expand Down Expand Up @@ -200,7 +200,7 @@ def sign

def run_all
empty_stdin = File.open(File::NULL) # pre-commit hooks don't take input
context = Overcommit::HookContext.create(@options[:hook_to_run], config, @arguments, empty_stdin)
context = Overcommit::HookContext.create(@options[:hook_to_run], config, @arguments, empty_stdin) # rubocop:disable Layout/LineLength
config.apply_environment!(context, ENV)

printer = Overcommit::Printer.new(config, log, context)
Expand Down
4 changes: 2 additions & 2 deletions lib/overcommit/hook/pre_commit/php_lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module Overcommit::Hook::PreCommit
# Runs `php -l` against any modified PHP files.
class PhpLint < Base
# Sample String
# rubocop:disable Metrics/LineLength
# rubocop:disable Layout/LineLength
# PHP Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in site/sumo.php on line 12
# rubocop:enable Metrics/LineLength
# rubocop:enable Layout/LineLength
MESSAGE_REGEX = /^(?<type>.+)\:\s+(?<message>.+) in (?<file>.+) on line (?<line>\d+)/.freeze

def run
Expand Down
6 changes: 5 additions & 1 deletion spec/overcommit/default_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

describe 'default configuration' do
default_config =
YAML.load_file(Overcommit::ConfigurationLoader::DEFAULT_CONFIG_PATH).to_hash
begin
YAML.load_file(Overcommit::ConfigurationLoader::DEFAULT_CONFIG_PATH, aliases: true).to_hash
rescue ArgumentError
YAML.load_file(Overcommit::ConfigurationLoader::DEFAULT_CONFIG_PATH).to_hash
end

Overcommit::Utils.supported_hook_types.each do |hook_type|
hook_class = Overcommit::Utils.camel_case(hook_type)
Expand Down
4 changes: 2 additions & 2 deletions spec/overcommit/hook/pre_commit/php_lint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
context 'when php lint exits unsuccessfully' do
before do
# php -l prints the same to both stdout and stderr
# rubocop:disable Metrics/LineLength
# rubocop:disable Layout/LineLength
sample_output = [
'',
"Parse error: syntax error, unexpected '0' (T_LNUMBER), expecting variable (T_VARIABLE) or '{' or '$' in sample.php on line 3 ",
'Errors parsing invalid.php',
].join("\n")
# rubocop:enable Metrics/LineLength
# rubocop:enable Layout/LineLength

result = double('result')
result.stub(:status).and_return(255)
Expand Down
8 changes: 4 additions & 4 deletions spec/overcommit/hook/pre_commit/phpcs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@

context 'and it reports a warning' do
before do
# rubocop:disable Metrics/LineLength
# rubocop:disable Layout/LineLength
sample_output = [
'File,Line,Column,Type,Message,Source,Severity,Fixable',
'"/Users/craig/HelpScout/overcommit-testing/invalid.php",5,1,warning,"Possible parse error: FOREACH has no AS statement",Squiz.ControlStructures.ForEachLoopDeclaration.MissingAs,5,0'
].join("\n")
# rubocop:enable Metrics/LineLength
# rubocop:enable Layout/LineLength
result.stub(:stdout).and_return(sample_output)
end

Expand All @@ -53,12 +53,12 @@

context 'and it reports an error' do
before do
# rubocop:disable Metrics/LineLength
# rubocop:disable Layout/LineLength
sample_output = [
'File,Line,Column,Type,Message,Source,Severity,Fixable',
'"/Users/craig/HelpScout/overcommit-testing/invalid.php",5,1,error,"Inline control structures are not allowed",Generic.ControlStructures.InlineControlStructure.NotAllowed,5,1'
].join("\n")
# rubocop:enable Metrics/LineLength
# rubocop:enable Layout/LineLength
result.stub(:stdout).and_return(sample_output)
end

Expand Down
10 changes: 5 additions & 5 deletions spec/overcommit/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,17 @@
describe '.supported_hook_types' do
subject { described_class.supported_hook_types }

# rubocop:disable Metrics/LineLength
# rubocop:disable Layout/LineLength
it { should =~ %w[commit-msg pre-commit post-checkout post-commit post-merge post-rewrite pre-push pre-rebase prepare-commit-msg] }
# rubocop:enable Metrics/LineLength
# rubocop:enable Layout/LineLength
end

describe '.supported_hook_type_classes' do
subject { described_class.supported_hook_type_classes }

# rubocop:disable Metrics/LineLength
# rubocop:disable Layout/LineLength
it { should =~ %w[CommitMsg PreCommit PostCheckout PostCommit PostMerge PostRewrite PrePush PreRebase PrepareCommitMsg] }
# rubocop:enable Metrics/LineLength
# rubocop:enable Layout/LineLength
end

describe '.parent_command' do
Expand Down Expand Up @@ -190,7 +190,7 @@
it 'invokes CommandSplitter.execute' do
Overcommit::CommandSplitter.
should_receive(:execute).
with(arguments, args: splittable_args).
with(arguments, { args: splittable_args }).
and_return(double(status: 0, stdout: '', stderr: ''))
subject
end
Expand Down
25 changes: 17 additions & 8 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
# frozen_string_literal: true

if ENV['TRAVIS']
# When running in Travis, report coverage stats to Coveralls.
require 'coveralls'
Coveralls.wear!
else
# Otherwise render coverage information in coverage/index.html and display
# coverage percentage in the console.
require 'simplecov'
require 'simplecov'
SimpleCov.start do
add_filter 'bin/'
add_filter 'libexec/'
add_filter 'spec/'
add_filter 'template-dir/'

if ENV['CI']
require 'simplecov-lcov'

SimpleCov::Formatter::LcovFormatter.config do |c|
c.report_with_single_file = true
c.single_report_path = 'coverage/lcov.info'
end

formatter SimpleCov::Formatter::LcovFormatter
end
end

require 'overcommit'
Expand Down
9 changes: 8 additions & 1 deletion template-dir/hooks/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ end
# Check if Overcommit should invoke a Bundler context for loading gems
require 'yaml'
# rubocop:disable Style/RescueModifier
if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
gemfile =
begin
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
rescue ArgumentError
YAML.load_file('.overcommit.yml')['gemfile']
end rescue nil

if gemfile
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'

Expand Down
9 changes: 8 additions & 1 deletion template-dir/hooks/overcommit-hook
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ end
# Check if Overcommit should invoke a Bundler context for loading gems
require 'yaml'
# rubocop:disable Style/RescueModifier
if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
gemfile =
begin
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
rescue ArgumentError
YAML.load_file('.overcommit.yml')['gemfile']
end rescue nil

if gemfile
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'

Expand Down
9 changes: 8 additions & 1 deletion template-dir/hooks/post-checkout
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ end
# Check if Overcommit should invoke a Bundler context for loading gems
require 'yaml'
# rubocop:disable Style/RescueModifier
if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
gemfile =
begin
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
rescue ArgumentError
YAML.load_file('.overcommit.yml')['gemfile']
end rescue nil

if gemfile
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'

Expand Down
9 changes: 8 additions & 1 deletion template-dir/hooks/post-commit
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ end
# Check if Overcommit should invoke a Bundler context for loading gems
require 'yaml'
# rubocop:disable Style/RescueModifier
if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
gemfile =
begin
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
rescue ArgumentError
YAML.load_file('.overcommit.yml')['gemfile']
end rescue nil

if gemfile
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'

Expand Down
9 changes: 8 additions & 1 deletion template-dir/hooks/post-merge
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ end
# Check if Overcommit should invoke a Bundler context for loading gems
require 'yaml'
# rubocop:disable Style/RescueModifier
if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
gemfile =
begin
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
rescue ArgumentError
YAML.load_file('.overcommit.yml')['gemfile']
end rescue nil

if gemfile
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'

Expand Down
9 changes: 8 additions & 1 deletion template-dir/hooks/post-rewrite
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ end
# Check if Overcommit should invoke a Bundler context for loading gems
require 'yaml'
# rubocop:disable Style/RescueModifier
if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
gemfile =
begin
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
rescue ArgumentError
YAML.load_file('.overcommit.yml')['gemfile']
end rescue nil

if gemfile
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'

Expand Down
9 changes: 8 additions & 1 deletion template-dir/hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ end
# Check if Overcommit should invoke a Bundler context for loading gems
require 'yaml'
# rubocop:disable Style/RescueModifier
if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
gemfile =
begin
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
rescue ArgumentError
YAML.load_file('.overcommit.yml')['gemfile']
end rescue nil

if gemfile
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'

Expand Down
Loading