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 9 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
4 changes: 4 additions & 0 deletions .github/workflows/octokit.yml
Expand Up @@ -56,3 +56,7 @@ jobs:
GITHUB_CI: 1
RUBYOPT: --enable-frozen-string-literal
run: bundle exec rspec -w
- 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
4 changes: 2 additions & 2 deletions Gemfile
Expand Up @@ -33,13 +33,13 @@ group :test do
end

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

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
20 changes: 14 additions & 6 deletions lib/octokit.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'octokit/default'
require 'octokit/client'
require 'octokit/enterprise_admin_client'
Expand All @@ -13,31 +15,38 @@ class << self
# @return [Octokit::Client] API wrapper
def client
return @client if defined?(@client) && @client.same_options?(options)

@client = Octokit::Client.new(options)
end

# EnterpriseAdminClient client based on configured options {Configurable}
#
# @return [Octokit::EnterpriseAdminClient] API wrapper
def enterprise_admin_client
return @enterprise_admin_client if defined?(@enterprise_admin_client) && @enterprise_admin_client.same_options?(options)
if defined?(@enterprise_admin_client) && @enterprise_admin_client.same_options?(options)
return @enterprise_admin_client
end

@enterprise_admin_client = Octokit::EnterpriseAdminClient.new(options)
end

# EnterpriseManagementConsoleClient client based on configured options {Configurable}
#
# @return [Octokit::EnterpriseManagementConsoleClient] API wrapper
def enterprise_management_console_client
return @enterprise_management_console_client if defined?(@enterprise_management_console_client) && @enterprise_management_console_client.same_options?(options)
if defined?(@enterprise_management_console_client) && @enterprise_management_console_client.same_options?(options)
return @enterprise_management_console_client
end

@enterprise_management_console_client = Octokit::EnterpriseManagementConsoleClient.new(options)
end

private

def respond_to_missing?(method_name, include_private=false)
def respond_to_missing?(method_name, include_private = false)
client.respond_to?(method_name, include_private) ||
enterprise_admin_client.respond_to?(method_name, include_private) ||
enterprise_management_console_client.respond_to?(method_name, include_private)
enterprise_admin_client.respond_to?(method_name, include_private) ||
enterprise_management_console_client.respond_to?(method_name, include_private)
end

def method_missing(method_name, *args, &block)
Expand All @@ -51,7 +60,6 @@ def method_missing(method_name, *args, &block)

super
end

end
end

Expand Down