Skip to content

Commit c142cd2

Browse files
authored
Fix configuration loading on Ruby 3.1 (#771)
1 parent db2eff6 commit c142cd2

23 files changed

+126
-117
lines changed

.github/workflows/lint.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ jobs:
2121

2222
- name: Prepare environment
2323
run: |
24-
git config --local user.email "gh-actions@example.com"
25-
git config --local user.name "GitHub Actions"
24+
git config --global user.email "gh-actions@example.com"
25+
git config --global user.name "GitHub Actions"
2626
bundle exec overcommit --sign
27+
bundle exec overcommit --sign pre-commit
2728
2829
- name: Run pre-commit checks
2930
run: bundle exec overcommit --run

.github/workflows/tests.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ jobs:
1919
- '3.1'
2020
os:
2121
- ubuntu
22-
- windows
2322

2423
steps:
2524
- uses: actions/checkout@v2
@@ -31,7 +30,10 @@ jobs:
3130
bundler-cache: true
3231

3332
- name: Run tests
34-
run: bundle exec rspec
33+
run: |
34+
git config --global user.email "gh-actions@example.com"
35+
git config --global user.name "GitHub Actions"
36+
bundle exec rspec
3537
3638
- name: Code coverage reporting
3739
uses: coverallsapp/github-action@master

.projections.json

-10
This file was deleted.

.simplecov

-6
This file was deleted.

Gemfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ gemspec
88

99
gem 'rspec', '~> 3.0'
1010

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

1414
# Pin RuboCop for Travis builds.
1515
gem 'rubocop', '0.82.0'

appveyor.yml

-61
This file was deleted.

lib/overcommit/cli.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def add_installation_options(opts)
9494
@options[:force] = true
9595
end
9696

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

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

206206
printer = Overcommit::Printer.new(config, log, context)

lib/overcommit/hook/pre_commit/php_lint.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ module Overcommit::Hook::PreCommit
44
# Runs `php -l` against any modified PHP files.
55
class PhpLint < Base
66
# Sample String
7-
# rubocop:disable Metrics/LineLength
7+
# rubocop:disable Layout/LineLength
88
# PHP Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in site/sumo.php on line 12
9-
# rubocop:enable Metrics/LineLength
9+
# rubocop:enable Layout/LineLength
1010
MESSAGE_REGEX = /^(?<type>.+)\:\s+(?<message>.+) in (?<file>.+) on line (?<line>\d+)/.freeze
1111

1212
def run

spec/overcommit/default_configuration_spec.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
describe 'default configuration' do
66
default_config =
7-
YAML.load_file(Overcommit::ConfigurationLoader::DEFAULT_CONFIG_PATH).to_hash
7+
begin
8+
YAML.load_file(Overcommit::ConfigurationLoader::DEFAULT_CONFIG_PATH, aliases: true).to_hash
9+
rescue ArgumentError
10+
YAML.load_file(Overcommit::ConfigurationLoader::DEFAULT_CONFIG_PATH).to_hash
11+
end
812

913
Overcommit::Utils.supported_hook_types.each do |hook_type|
1014
hook_class = Overcommit::Utils.camel_case(hook_type)

spec/overcommit/hook/pre_commit/php_lint_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
context 'when php lint exits unsuccessfully' do
2727
before do
2828
# php -l prints the same to both stdout and stderr
29-
# rubocop:disable Metrics/LineLength
29+
# rubocop:disable Layout/LineLength
3030
sample_output = [
3131
'',
3232
"Parse error: syntax error, unexpected '0' (T_LNUMBER), expecting variable (T_VARIABLE) or '{' or '$' in sample.php on line 3 ",
3333
'Errors parsing invalid.php',
3434
].join("\n")
35-
# rubocop:enable Metrics/LineLength
35+
# rubocop:enable Layout/LineLength
3636

3737
result = double('result')
3838
result.stub(:status).and_return(255)

spec/overcommit/hook/pre_commit/phpcs_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@
3939

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

@@ -53,12 +53,12 @@
5353

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

spec/overcommit/utils_spec.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,17 @@
119119
describe '.supported_hook_types' do
120120
subject { described_class.supported_hook_types }
121121

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

127127
describe '.supported_hook_type_classes' do
128128
subject { described_class.supported_hook_type_classes }
129129

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

135135
describe '.parent_command' do
@@ -190,7 +190,7 @@
190190
it 'invokes CommandSplitter.execute' do
191191
Overcommit::CommandSplitter.
192192
should_receive(:execute).
193-
with(arguments, args: splittable_args).
193+
with(arguments, { args: splittable_args }).
194194
and_return(double(status: 0, stdout: '', stderr: ''))
195195
subject
196196
end

spec/spec_helper.rb

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
# frozen_string_literal: true
22

3-
if ENV['TRAVIS']
4-
# When running in Travis, report coverage stats to Coveralls.
5-
require 'coveralls'
6-
Coveralls.wear!
7-
else
8-
# Otherwise render coverage information in coverage/index.html and display
9-
# coverage percentage in the console.
10-
require 'simplecov'
3+
require 'simplecov'
4+
SimpleCov.start do
5+
add_filter 'bin/'
6+
add_filter 'libexec/'
7+
add_filter 'spec/'
8+
add_filter 'template-dir/'
9+
10+
if ENV['CI']
11+
require 'simplecov-lcov'
12+
13+
SimpleCov::Formatter::LcovFormatter.config do |c|
14+
c.report_with_single_file = true
15+
c.single_report_path = 'coverage/lcov.info'
16+
end
17+
18+
formatter SimpleCov::Formatter::LcovFormatter
19+
end
1120
end
1221

1322
require 'overcommit'

template-dir/hooks/commit-msg

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ end
2929
# Check if Overcommit should invoke a Bundler context for loading gems
3030
require 'yaml'
3131
# rubocop:disable Style/RescueModifier
32-
if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
32+
gemfile =
33+
begin
34+
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
35+
rescue ArgumentError
36+
YAML.load_file('.overcommit.yml')['gemfile']
37+
end rescue nil
38+
39+
if gemfile
3340
ENV['BUNDLE_GEMFILE'] = gemfile
3441
require 'bundler'
3542

template-dir/hooks/overcommit-hook

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ end
2929
# Check if Overcommit should invoke a Bundler context for loading gems
3030
require 'yaml'
3131
# rubocop:disable Style/RescueModifier
32-
if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
32+
gemfile =
33+
begin
34+
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
35+
rescue ArgumentError
36+
YAML.load_file('.overcommit.yml')['gemfile']
37+
end rescue nil
38+
39+
if gemfile
3340
ENV['BUNDLE_GEMFILE'] = gemfile
3441
require 'bundler'
3542

template-dir/hooks/post-checkout

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ end
2929
# Check if Overcommit should invoke a Bundler context for loading gems
3030
require 'yaml'
3131
# rubocop:disable Style/RescueModifier
32-
if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
32+
gemfile =
33+
begin
34+
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
35+
rescue ArgumentError
36+
YAML.load_file('.overcommit.yml')['gemfile']
37+
end rescue nil
38+
39+
if gemfile
3340
ENV['BUNDLE_GEMFILE'] = gemfile
3441
require 'bundler'
3542

template-dir/hooks/post-commit

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ end
2929
# Check if Overcommit should invoke a Bundler context for loading gems
3030
require 'yaml'
3131
# rubocop:disable Style/RescueModifier
32-
if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
32+
gemfile =
33+
begin
34+
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
35+
rescue ArgumentError
36+
YAML.load_file('.overcommit.yml')['gemfile']
37+
end rescue nil
38+
39+
if gemfile
3340
ENV['BUNDLE_GEMFILE'] = gemfile
3441
require 'bundler'
3542

template-dir/hooks/post-merge

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ end
2929
# Check if Overcommit should invoke a Bundler context for loading gems
3030
require 'yaml'
3131
# rubocop:disable Style/RescueModifier
32-
if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
32+
gemfile =
33+
begin
34+
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
35+
rescue ArgumentError
36+
YAML.load_file('.overcommit.yml')['gemfile']
37+
end rescue nil
38+
39+
if gemfile
3340
ENV['BUNDLE_GEMFILE'] = gemfile
3441
require 'bundler'
3542

template-dir/hooks/post-rewrite

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ end
2929
# Check if Overcommit should invoke a Bundler context for loading gems
3030
require 'yaml'
3131
# rubocop:disable Style/RescueModifier
32-
if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
32+
gemfile =
33+
begin
34+
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
35+
rescue ArgumentError
36+
YAML.load_file('.overcommit.yml')['gemfile']
37+
end rescue nil
38+
39+
if gemfile
3340
ENV['BUNDLE_GEMFILE'] = gemfile
3441
require 'bundler'
3542

template-dir/hooks/pre-commit

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ end
2929
# Check if Overcommit should invoke a Bundler context for loading gems
3030
require 'yaml'
3131
# rubocop:disable Style/RescueModifier
32-
if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
32+
gemfile =
33+
begin
34+
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
35+
rescue ArgumentError
36+
YAML.load_file('.overcommit.yml')['gemfile']
37+
end rescue nil
38+
39+
if gemfile
3340
ENV['BUNDLE_GEMFILE'] = gemfile
3441
require 'bundler'
3542

0 commit comments

Comments
 (0)