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

Enable Rubocop - the sequel #1441

Merged
merged 13 commits into from Jun 8, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 21 additions & 4 deletions .github/workflows/octokit.yml
Expand Up @@ -20,11 +20,18 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu ]
ruby: [ 2.5, 2.6, 2.7, '3.0', '3.1', head ]
ruby: [ 2.3, 2.4, 2.5, 2.6, 2.7, '3.0', '3.1', head ]
faraday: [ '~> 1.0', '~> 2.0' ]
exclude:
# Faraday 2.x only works with Ruby versions 2.6 onwards.
# Fortunately, the gem supports Faraday 1.x, so we can just
# test against that.
- ruby: 2.5
faraday: '~> 2.0'
- ruby: 2.4
faraday: '~> 2.0'
- ruby: 2.3
faraday: '~> 2.0'
env:
FARADAY_VERSION: ${{ matrix.faraday }}

Expand All @@ -43,16 +50,26 @@ jobs:
ruby-version: ${{ matrix.ruby }}
- name: Setup .netrc
run: chmod 600 spec/fixtures/.netrc
- name: Ruby 2.5 needs a newer RubyGems to support frozen-string-literal
if: ${{ matrix.ruby == '2.5' }}
- name: Ruby 2.5 and earlier need a newer RubyGems to support frozen-string-literal
if: ${{ matrix.ruby == '2.5' || matrix.ruby == '2.4' || matrix.ruby == '2.3' }}
run: gem update --system 2.7.11
- name: Install dependencies
run: |
bundle config set path .bundle/gems
bundle config set without development
bundle install --jobs 4 --retry 3
- name: Test with RSpec
- name: Test with RSpec with frozen string literals enabled
env:
GITHUB_CI: 1
RUBYOPT: --enable-frozen-string-literal
run: bundle exec rspec -w
if: ${{ matrix.ruby != '2.3' }}
- name: Test with RSpec without frozen string literals enabled
env:
GITHUB_CI: 1
run: bundle exec rspec -w
if: ${{ matrix.ruby == '2.3' }}
- name: Lint with Rubocop
env:
GITHUB_CI: 1
run: bundle exec rubocop
21 changes: 20 additions & 1 deletion .rubocop.yml
@@ -1,3 +1,22 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.3
Metrics/BlockLength:
Exclude:
spec/**/*_spec.rb
- spec/**/*_spec.rb
Layout/BlockAlignment:
Exclude:
# This file is causing Rubocop to error - see <https://github.com/octokit/octokit.rb/runs/6779545664>
# for an example
- Guardfile
Lint/RaiseException:
Enabled: true
Lint/StructNewOverride:
Enabled: true
Style/HashEachMethods:
Enabled: true
Style/HashTransformKeys:
Enabled: true
Style/HashTransformValues:
Enabled: true
239 changes: 239 additions & 0 deletions .rubocop_todo.yml
@@ -0,0 +1,239 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-06-07 18:42:36 +0100 using RuboCop version 0.81.0.
# 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: Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'octokit.gemspec'

# Offense count: 4
Lint/AmbiguousOperator:
Exclude:
- 'lib/octokit/client.rb'
- 'lib/octokit/client/pub_sub_hubbub.rb'
- 'lib/octokit/connection.rb'

# Offense count: 13
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Exclude:
- 'lib/octokit/client/contents.rb'
- 'lib/octokit/client/feeds.rb'
- 'lib/octokit/client/gists.rb'
- 'lib/octokit/client/organizations.rb'
- 'lib/octokit/client/releases.rb'
- 'lib/octokit/client/stats.rb'
- 'lib/octokit/connection.rb'
- 'lib/octokit/error.rb'
- 'lib/octokit/response/raise_error.rb'

# Offense count: 20
# Configuration parameters: AllowComments.
Lint/SuppressedException:
Exclude:
- 'Rakefile'
- 'spec/helper.rb'
- 'spec/octokit/client/actions_secrets_spec.rb'
- 'spec/octokit/client/commits_spec.rb'
- 'spec/octokit/client/deployments_spec.rb'
- 'spec/octokit/client/hooks_spec.rb'
- 'spec/octokit/client/issues_spec.rb'
- 'spec/octokit/client/reactions_spec.rb'
- 'spec/octokit/client/refs_spec.rb'
- 'spec/octokit/client/repositories_spec.rb'
- 'spec/octokit/client/repository_invitations_spec.rb'
- 'spec/octokit/client/source_import_spec.rb'

# Offense count: 31
Lint/UselessAssignment:
Exclude:
- 'spec/octokit/client/actions_secrets_spec.rb'
- 'spec/octokit/client/actions_workflow_runs_spec.rb'
- 'spec/octokit/client/apps_spec.rb'
- 'spec/octokit/client/hooks_spec.rb'
- 'spec/octokit/client/organizations_spec.rb'
- 'spec/octokit/client/rate_limit_spec.rb'
- 'spec/octokit/client/releases_spec.rb'
- 'spec/octokit/client/repositories_spec.rb'
- 'spec/octokit/client/stats_spec.rb'
- 'spec/octokit/client_spec.rb'
- 'spec/octokit/enterprise_admin_client/search_indexing_spec.rb'
- 'spec/octokit/enterprise_admin_client/users_spec.rb'
- 'spec/octokit/enterprise_management_console_client/management_console_spec.rb'

# Offense count: 1
# Configuration parameters: CheckForMethodsWithNoSideEffects.
Lint/Void:
Exclude:
- 'lib/octokit/repo_arguments.rb'

# Offense count: 16
# Configuration parameters: IgnoredMethods.
Metrics/AbcSize:
Max: 33

# Offense count: 1
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 102

# Offense count: 1
# Configuration parameters: CountBlocks.
Metrics/BlockNesting:
Max: 4

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 160

# Offense count: 7
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 18

# Offense count: 29
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 26

# Offense count: 4
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 217

# Offense count: 4
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 9

# Offense count: 6
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 13

# Offense count: 1
Naming/AccessorMethodName:
Exclude:
- 'lib/octokit/enterprise_management_console_client/management_console.rb'

# Offense count: 1
# Configuration parameters: ForbiddenDelimiters.
# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
Naming/HeredocDelimiterNaming:
Exclude:
- 'lib/octokit/preview.rb'

# Offense count: 1
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp
Naming/MethodParameterName:
Exclude:
- 'lib/octokit/client/legacy_search.rb'

# Offense count: 9
# Configuration parameters: AllowedChars.
Style/AsciiComments:
Exclude:
- 'lib/octokit/client/contents.rb'
- 'lib/octokit/client/gists.rb'
- 'lib/octokit/client/licenses.rb'
- 'lib/octokit/client/organizations.rb'
- 'lib/octokit/client/repositories.rb'
- 'lib/octokit/client/stats.rb'
- 'lib/octokit/client/users.rb'
- 'lib/octokit/middleware/follow_redirects.rb'

# Offense count: 484
Style/CommentedKeyword:
Enabled: false

# Offense count: 3
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/octokit/client/actions_workflow_runs.rb'
- 'lib/octokit/client/users.rb'
- 'lib/octokit/enterprise_management_console_client/management_console.rb'

# Offense count: 7
Style/DoubleNegation:
Exclude:
- 'lib/octokit/authentication.rb'
- 'lib/octokit/client/repositories.rb'
- 'lib/octokit/configurable.rb'
- 'spec/helper.rb'

# Offense count: 7
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/octokit.rb'
- 'lib/octokit/client/feeds.rb'
- 'lib/octokit/error.rb'
- 'lib/octokit/repository.rb'
- 'lib/octokit/response/feed_parser.rb'
- 'lib/octokit/response/raise_error.rb'

# Offense count: 1
# Configuration parameters: AllowIfModifier.
Style/IfInsideElse:
Exclude:
- 'lib/octokit/connection.rb'

# Offense count: 22
# Cop supports --auto-correct.
Style/IfUnlessModifier:
Exclude:
- 'lib/octokit.rb'
- 'lib/octokit/client.rb'
- 'lib/octokit/client/authorizations.rb'
- 'lib/octokit/client/commits.rb'
- 'lib/octokit/client/organizations.rb'
- 'lib/octokit/client/repositories.rb'
- 'lib/octokit/default.rb'
- 'lib/octokit/enterprise_management_console_client/management_console.rb'
- 'lib/octokit/error.rb'
- 'lib/octokit/repository.rb'
- 'spec/helper.rb'

# Offense count: 1
Style/MultilineTernaryOperator:
Exclude:
- 'lib/octokit/client/contents.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Exclude:
- 'spec/**/*'
- 'lib/octokit/connection.rb'

# Offense count: 1
Style/StructInheritance:
Exclude:
- 'lib/octokit/rate_limit.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/WhileUntilModifier:
Exclude:
- 'spec/octokit/client/source_import_spec.rb'

# Offense count: 1290
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 517
13 changes: 9 additions & 4 deletions Gemfile
Expand Up @@ -32,14 +32,19 @@ group :test do
gem 'webmock', '~> 3.8', '>= 3.8.2'
end

gem 'faraday', ENV.fetch('FARADAY_VERSION', '~> 2.0')
gem 'faraday-retry'
gem 'faraday-multipart'
faraday_version = ENV.fetch('FARADAY_VERSION', '~> 2.0')

gem 'faraday', faraday_version

if faraday_version.start_with?('~> 2')
gem 'faraday-multipart'
gem 'faraday-retry'
end

group :test, :development do
gem 'pry-byebug'
gem 'redcarpet'
gem 'rubocop'
gem 'rubocop', '0.81'
end

gemspec
8 changes: 5 additions & 3 deletions Guardfile
@@ -1,5 +1,7 @@
guard "rspec", :cmd => "bundle exec rspec" do
# frozen_string_literal: true

guard 'rspec', cmd: 'bundle exec rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch("spec/helper.rb") { "spec" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/helper.rb') { 'spec' }
end
8 changes: 5 additions & 3 deletions Rakefile
@@ -1,11 +1,13 @@
# frozen_string_literal: true

require 'bundler'
Bundler::GemHelper.install_tasks

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

task :test => :spec
task :default => :spec
task test: :spec
task default: :spec

namespace :doc do
begin
Expand All @@ -14,7 +16,7 @@ namespace :doc do
task.files = ['README.md', 'LICENSE.md', 'lib/**/*.rb']
task.options = [
'--output-dir', 'doc/yard',
'--markup', 'markdown',
'--markup', 'markdown'
]
end
rescue LoadError
Expand Down
6 changes: 4 additions & 2 deletions lib/ext/sawyer/relation.rb
@@ -1,9 +1,11 @@
# frozen_string_literal: true

require 'sawyer'

patch = Module.new do
def href(options=nil)
def href(options = nil)
# Temporary workaround for: https://github.com/octokit/octokit.rb/issues/727
name.to_s == "ssh" ? @href : super
name.to_s == 'ssh' ? @href : super
end
end

Expand Down