Skip to content
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
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@ on:

jobs:
spec:
name: RSpec
name: RSpec (Ruby ${{ matrix.ruby }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby: ['3.0', '3.1', '3.2', '3.3', '3.4']
env:
DANGER_SKIP_SWIFTLINT_INSTALL: 'YES'
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: bundle exec rake spec

# FIXME: rubocop is pinned to Ruby 2.7 because the gem is pinned at ~> 0.50.0
# (2017) and won't load on Ruby 3.x (parser/racc, Psych 4). Bump rubocop to a
# modern release ASAP and drop this `ruby-version` override.
rubocop:
name: RuboCop
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '2.7'
bundler-cache: true
- run: bundle exec rubocop
Comment on lines 26 to 34

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem worth to run RuboCop on a matrix as it's less important than test coverage, as the latter could discover genuine compatibility issues. But, it should be relatively cheap to add a matrix here too.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this is the right tradeoff 👍

35 changes: 23 additions & 12 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
# FIXME: rubocop is pinned at ~> 0.50.0 (released 2017) and its `TargetRubyVersion`
# table maxes out at Ruby 2.4. Modern Ruby (3.x) also breaks the gem's parser/Psych
# dependencies. To keep the linter running in CI we force the target down to 2.4
# and pin the rubocop job to Ruby 2.7 (the newest version where 0.50.0 still
# loads). This is a temporary band-aid: bump rubocop to a modern release ASAP
# and remove this block (and the Ruby pin in .github/workflows/ci.yml).
AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: 3.0
NewCops: disable

# Disable linting of Dangerfile.
Style/FrozenStringLiteralComment:
Exclude:
- 'Dangerfile'

# Customize some cops.
Metrics/LineLength:
Layout/LineLength:
Max: 120
Exclude:
- '*.gemspec'
Metrics/ClassLength:
Max: 150

# The danger_plugin.rb file presents unique challenges, ignore it.
Max: 250
Metrics/MethodLength:
Max: 15
Exclude:
- 'lib/danger_plugin.rb'
Metrics/PerceivedComplexity:
Exclude:
- 'lib/danger_plugin.rb'
- 'ext/swiftlint/swiftlint.rb'

# `run` is the plugin's public surface; its parameter list is part of
# the API contract and can't be tightened without a breaking change.
Metrics/ParameterLists:
Exclude:
- 'ext/swiftlint/swiftlint.rb'

# Rake tasks define their constants inside the task block by convention.
Lint/ConstantDefinitionInBlock:
Exclude:
- 'ext/swiftlint/Rakefile'

# The gemspec sets `required_ruby_version` for downstream consumers and
# is independent of the version we lint against here.
Gemspec/RequiredRubyVersion:
Enabled: false

# I just don't like these ones.
Metrics/AbcSize:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false

# For Ruby 2.2 compatibility
Style/NumericPredicate:
Enabled: false

Expand Down
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ gem 'danger-rubocop'

group :development do
gem 'bacon'
gem 'bundler'
gem 'mocha'
gem 'mocha-on-bacon'
# `parallel` 2.x requires Ruby >= 3.3 — keep it on 1.x so the matrix
# can still install on Ruby 3.0–3.2.
gem 'parallel', '< 2'
Comment on lines +15 to +17

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, go one step forward and drop 3.0-3.2 given they are no longer supported...

Image

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be fine with dropping those versions. The only devs who would face an issue would be devs updating their CI, so, they'd be keeping up to date with Ruby too. (Or at least, I hope so!)

gem 'prettybacon'
gem 'rubocop', '~> 0.50.0', require: false
gem 'bundler'
gem 'rubocop', '~> 1.50', require: false
end
43 changes: 28 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GEM
specs:
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
ast (2.4.3)
bacon (1.2.0)
base64 (0.2.0)
claide (1.1.0)
Expand Down Expand Up @@ -68,10 +68,13 @@ GEM
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
json (2.19.5)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
listen (3.0.7)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9.7)
Expand All @@ -93,23 +96,25 @@ GEM
sawyer (~> 0.9)
open4 (1.3.4)
ostruct (0.6.3)
parallel (1.23.0)
parser (2.7.2.0)
parallel (1.28.0)
parser (3.3.11.1)
ast (~> 2.4.1)
powerpack (0.1.3)
racc
prettybacon (0.0.2)
bacon (~> 1.2)
prism (1.9.0)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.4)
rainbow (2.2.2)
rake
rake (13.1.0)
racc (1.8.1)
rainbow (3.1.1)
rake (13.4.2)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rchardet (1.8.0)
regexp_parser (2.12.0)
rexml (3.2.6)
rspec (3.12.0)
rspec-core (~> 3.12.0)
Expand All @@ -124,13 +129,20 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubocop (0.50.0)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 3.0)
rubocop (1.86.2)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (>= 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.49.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.49.1)
parser (>= 3.3.7.2)
prism (~> 1.7)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sawyer (0.9.2)
Expand All @@ -140,7 +152,7 @@ GEM
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
thor (1.4.0)
unicode-display_width (1.8.0)
unicode-display_width (2.6.0)

PLATFORMS
ruby
Expand All @@ -156,10 +168,11 @@ DEPENDENCIES
listen (= 3.0.7)
mocha
mocha-on-bacon
parallel (< 2)
prettybacon
pry
rspec (~> 3.4)
rubocop (~> 0.50.0)
rubocop (~> 1.50)

BUNDLED WITH
2.3.9
4 changes: 1 addition & 3 deletions bin/danger-swiftlint
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

if $PROGRAM_NAME == __FILE__
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
end
$LOAD_PATH.unshift File.expand_path('../lib', __dir__) if $PROGRAM_NAME == __FILE__
require 'thor'
require 'version'

Expand Down
4 changes: 2 additions & 2 deletions danger-swiftlint.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'version'

Expand All @@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.3'

spec.add_dependency 'danger'
spec.add_dependency 'thor', '~> 1.4'
spec.add_dependency 'rake', '> 10'
spec.add_dependency 'thor', '~> 1.4'

# General ruby development
spec.add_development_dependency 'bundler', '~> 1.3'
Expand Down
2 changes: 1 addition & 1 deletion ext/swiftlint/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace :swiftlint do
REPO = 'https://github.com/realm/SwiftLint'
VERSION = ENV['SWIFTLINT_VERSION'] || DangerSwiftlint::SWIFTLINT_VERSION
ASSET = 'portable_swiftlint.zip'
URL = "#{REPO}/releases/download/#{VERSION}/#{ASSET}"
URL = "#{REPO}/releases/download/#{VERSION}/#{ASSET}".freeze
DESTINATION = File.expand_path(File.join(File.dirname(__FILE__), 'bin'))
SCRIPT_PATH = File.expand_path(File.join(File.dirname(__FILE__)))
SWIFTLINT_MD5_HASH = DangerSwiftlint::SWIFTLINT_HASH
Expand Down
15 changes: 8 additions & 7 deletions ext/swiftlint/swiftlint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ def run(cmd = 'lint', additional_swiftlint_args = '', options = {}, env = nil)
begin
# run swiftlint with provided options
if pwd
Dir.chdir(pwd) do
Dir.chdir(pwd) do
`#{command}`
end
else
`#{command}`
end
ensure
# Remove any ENV variables we might have added
restore_env()
restore_env
end
end

Expand Down Expand Up @@ -77,6 +77,7 @@ def default_swiftlint_path
# @param env (Hash) hash containing environment variables to add
def update_env(env)
return if !env || env.empty?

# Keep the same @original_env if we've already set it, since that would mean
# that we're adding more variables, in which case, we want to make sure to
# keep the true original when we go to restore it.
Expand All @@ -87,10 +88,10 @@ def update_env(env)

# Restores shell environment to values in `@original_env`
# All environment variables not in `@original_env` will be removed
def restore_env()
if !@original_env.nil?
ENV.replace(@original_env)
@original_env = nil
end
def restore_env
return if @original_env.nil?

ENV.replace(@original_env)
@original_env = nil
end
end
Loading
Loading