Skip to content

Commit

Permalink
Add rubocop support (#299)
Browse files Browse the repository at this point in the history
* Add rubocop support

* Add rubocop todo config

* Fix run on ruby 2.5

* Detect ruby version

* Fix rubocop `Gemspec/OrderedDependencies` cop

* Fix rubocop `Layout/ArgumentAlignmen` cop # Please enter the commit message for your changes. Lines starting

* Fix rubocop `Layout/ArrayAlignment` cop

* Fix rubocop `Layout/BlockAlignment` cop

* Fix rubocop `Layout/ClosingParenthesisIndentation` cop

* Fix rubocop `Layout/EmptyLineAfterGuardClause` cop

* Fix rubocop `Layout/EmptyLineAfterMagicComment` cop

* Fix rubocop `Layout/EmptyLines` cop

* Fix rubocop `Layout/EmptyLinesAroundBlockBody` cop

* Fix rubocop `Layout/EndAlignment` cop

* Move one option to config

* Add `Gemspec/RubyVersionGlobalsUsage` to disables

* Fix rubocop `Layout/ExtraSpacing` cop

* Fix rubocop `Layout/FirstArgumentIndentation` cop

* Fix rubocop `Layout/FirstHashElementIndentation` cop

* Fix rubocop `Layout/IndentationConsistency` cop

* Fix rubocop `Layout/IndentationWidth` cop

* Fix rubocop `Layout/MultilineMethodCallBraceLayout` cop

* Fix rubocop `Layout/MultilineMethodCallIndentation` cop

* Fix rubocop `Layout/SpaceAfterColon` cop

* Fix rubocop `Layout/SpaceAfterComma` cop

* Fix rubocop `Layout/SpaceAroundOperators` cop

* Fix rubocop `Layout/SpaceBeforeBlockBraces` cop

* Fix rubocop `Layout/SpaceInsideArrayLiteralBrackets` cop

* Fix rubocop `Layout/SpaceInsideBlockBraces` cop

* Fix rubocop `Layout/SpaceInsideHashLiteralBraces` cop

* Fix rubocop `Layout/SpaceInsideReferenceBrackets` cop

* Fix rubocop `Layout/TrailingEmptyLines` cop

* Fix rubocop `Layout/TrailingWhitespace` cop

* Fix all layout cops

* Fix rubocop `Lint/AmbiguousRegexpLiteral` cop

* Fix rubocop `Style/CaseLikeIf` cop

* Fix rubocop `Security/JSONLoad` cop

* Fix rubocop `Security/YAMLLoad` cop

* Fix rubocop `Rake/Desc` cop

* Fix rubocop `Performance/BlockGivenWithExplicitBlock` cop

* Fix rubocop `Performance/InefficientHashSearch` cop

* Fix rubocop `Performance/RedundantBlockCall` cop

* Fix rubocop `Performance/RegexpMatch` cop

* Fix rubocop `Style/ClassCheck` cop

* Fix rubocop `Style/Encoding` cop

* Fix rubocop `Style/ExpandPathArguments` cop

* Fix rubocop `Style/FetchEnvVar` cop

* Fix rubocop `Style/IfUnlessModifier` cop

* Fix rubocop `Style/MethodCallWithoutArgsParentheses` cop

* Fix rubocop `Style/MutableConstant` cop

* Fix rubocop `Lint/SymbolConversion` cop

* Fix rubocop `Lint/UselessAssignment` cop

* Fix rubocop `RSpec/EmptyLineAfterFinalLet` cop

* Fix rubocop `RSpec/ExampleWording` cop

* Fix rubocop `RSpec/ExpectChange` cop

* Fix rubocop `RSpec/LeadingSubject` cop

* Fix rubocop `RSpec/DescribedClass` cop

* Fix rubocop `RSpec/DescribedClass` cop

* Fix rubocop `RSpec/NotToNot` cop

* Fix rubocop `Style/ExplicitBlockArgument` cop

* Fix rubocop `Style/BlockDelimiters` cop

* Fix rubocop `Style/FrozenStringLiteralComment` cop

* Fix rubocop `Style/FloatDivision` cop

* Fix rubocop `Style/HashConversion` cop

* Fix rubocop `Style/NumericLiterals` cop

* Fix rubocop `Style/NumericPredicate` cop

* Fix rubocop `Style/HashSyntax` cop

* Fix rubocop `Style/PercentLiteralDelimiters` cop

* Fix rubocop `Style/RedundantFreeze` cop

* Fix rubocop `RSpec/BeEq` cop

* Fix rubocop `Style/PerlBackrefs` cop

* Fix rubocop `Style/RaiseArgs` cop

* Fix rubocop `Style/RedundantPercentQ` cop

* Fix rubocop `Style/RedundantRegexpEscape` cop

* Fix rubocop `Style/RedundantSelf` cop

* Fix rubocop `Style/RegexpLiteral` cop

* Fix rubocop `Style/SafeNavigation` cop

* Fix rubocop `Style/StringLiterals` cop

* Fix rubocop `Style/SymbolArray` cop

* Fix rubocop `Style/SymbolProc` cop

* Fix rubocop `Style/TrailingCommaInArguments` cop

* Fix rubocop `Style/TrailingCommaInArrayLiteral` cop

* Fix rubocop `Style/TrailingCommaInHashLiteral` cop

* Fix rubocop `Style/WordArray` cop

* Fix rubocop `Lint/NonDeterministicRequireOrder` cop

* Revert "Fix rubocop `Style/SymbolProc` cop"

This reverts commit 5dc2a90.
  • Loading branch information
ShockwaveNN authored Jun 29, 2022
1 parent 60a5b97 commit 7af5ac1
Show file tree
Hide file tree
Showing 125 changed files with 1,050 additions and 786 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: rubocop

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
bundler-cache: true
- name: Test
run: |
bundle exec rubocop
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.rbc
.bundle
.config
.idea
.yardoc
Gemfile.lock
InstalledFiles
Expand Down
22 changes: 22 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require:
- rubocop-packaging
- rubocop-performance
- rubocop-rake
- rubocop-rspec

inherit_from: .rubocop_todo.yml

AllCops:
NewCops: enable
# Should be the same as gem's `required_ruby_version`
TargetRubyVersion: 2.5


# Maintainers need to decide if they
# want to use to enable MFA for gem releases
Gemspec/RequireMFA:
Enabled: false

# Possible need to drop ruby-2.5 support
Gemspec/RubyVersionGlobalsUsage:
Enabled: false
182 changes: 182 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-06-23 17:10:56 UTC using RuboCop version 1.30.1.
# 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: 4
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Lint/ConstantDefinitionInBlock:
Exclude:
- 'lib/droplet_kit/mappings/kubernetes_options_mapping.rb'
- 'spec/lib/droplet_kit/client_spec.rb'

# Offense count: 3
# Configuration parameters: AllowComments, AllowEmptyLambdas.
Lint/EmptyBlock:
Exclude:
- 'spec/lib/droplet_kit/paginated_resource_spec.rb'
- 'spec/support/shared_examples/paginated_endpoint.rb'

# Offense count: 2
Lint/StructNewOverride:
Exclude:
- 'lib/droplet_kit/models/pagination_information.rb'
- 'spec/lib/droplet_kit/paginated_resource_spec.rb'

# Offense count: 1
Lint/ToEnumArguments:
Exclude:
- 'lib/droplet_kit/utils.rb'

# Offense count: 1
# Configuration parameters: AllowKeywordBlockArguments.
Lint/UnderscorePrefixedVariableName:
Exclude:
- 'spec/lib/droplet_kit/client_spec.rb'

# Offense count: 36
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Enabled: false

# Offense count: 2
# Configuration parameters: CheckForMethodsWithNoSideEffects.
Lint/Void:
Exclude:
- 'spec/lib/droplet_kit/paginated_resource_spec.rb'

# Offense count: 4
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 184

# Offense count: 16
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods, inherit_mode.
# IgnoredMethods: refine
Metrics/BlockLength:
Max: 127

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 133

# Offense count: 4
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 55

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ModuleLength:
Max: 164

# Offense count: 1
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
Naming/MemoizedInstanceVariableName:
Exclude:
- 'lib/droplet_kit/client.rb'

# Offense count: 14
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
Naming/VariableNumber:
Exclude:
- 'spec/lib/droplet_kit/resources/droplet_action_resource_spec.rb'
- 'spec/lib/droplet_kit/resources/firewall_resource_spec.rb'
- 'spec/lib/droplet_kit/resources/load_balancer_resource_spec.rb'

# Offense count: 33
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/lib/droplet_kit/client_spec.rb'
- 'spec/lib/droplet_kit/paginated_resource_spec.rb'
- 'spec/lib/droplet_kit/resources/certificate_resource_spec.rb'
- 'spec/lib/droplet_kit/resources/container_registry_resource_spec.rb'
- 'spec/lib/droplet_kit/resources/database_resource_spec.rb'
- 'spec/lib/droplet_kit/resources/droplet_resource_spec.rb'
- 'spec/lib/droplet_kit/resources/firewall_resource_spec.rb'
- 'spec/lib/droplet_kit/resources/floating_ip_resource_spec.rb'
- 'spec/lib/droplet_kit/resources/kubernetes_cluster_resource_spec.rb'
- 'spec/lib/droplet_kit/resources/load_balancer_resource_spec.rb'
- 'spec/lib/droplet_kit/resources/reserved_ip_resource_spec.rb'
- 'spec/lib/droplet_kit/resources/volume_resource_spec.rb'
- 'spec/lib/droplet_kit/resources/vpc_resource_spec.rb'
- 'spec/support/resource_context.rb'

# Offense count: 114
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 43

# Offense count: 36
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
# Include: **/*_spec*rb*, **/spec/**/*
RSpec/FilePath:
Enabled: false

# Offense count: 2
RSpec/IteratedExpectation:
Exclude:
- 'spec/lib/droplet_kit/resources/kubernetes_cluster_resource_spec.rb'

# Offense count: 2
RSpec/LeakyConstantDeclaration:
Exclude:
- 'spec/lib/droplet_kit/client_spec.rb'

# Offense count: 118
RSpec/MultipleExpectations:
Max: 30

# Offense count: 32
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 11

# Offense count: 3
RSpec/NestedGroups:
Max: 4

# Offense count: 58
# Configuration parameters: AllowedConstants.
Style/Documentation:
Enabled: false

# Offense count: 1
# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
Style/GuardClause:
Exclude:
- 'lib/droplet_kit/paginated_resource.rb'

# Offense count: 1
Style/MissingRespondToMissing:
Exclude:
- 'lib/droplet_kit/client.rb'

# Offense count: 5
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowMethodsWithArguments, IgnoredMethods, AllowComments.
# IgnoredMethods: respond_to, define_method
Style/SymbolProc:
Exclude:
- 'lib/droplet_kit/resources/container_registry_resource.rb'
- 'lib/droplet_kit/resources/droplet_action_resource.rb'
- 'lib/droplet_kit/resources/kubernetes_cluster_resource.rb'
- 'lib/tasks/resource_doc.rake'

# Offense count: 86
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 221
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## main

- #299 - @ShockwaveNN - Add `rubocop` support in CI and fix a lot of issues

## Version 3.17.0

- #296 - @andrewsomething - Add support for reserved IPs.
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'simplecov'
Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "bundler/gem_tasks"
# frozen_string_literal: true

require 'bundler/gem_tasks'

load './lib/tasks/resource_doc.rake'
49 changes: 31 additions & 18 deletions droplet_kit.gemspec
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
# frozen_string_literal: true

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

Gem::Specification.new do |spec|
spec.name = "droplet_kit"
spec.name = 'droplet_kit'
spec.version = DropletKit::VERSION
spec.authors = ["DigitalOcean API Engineering team"]
spec.email = ["[email protected]"]
spec.summary = %q{Droplet Kit is the official Ruby library for DigitalOcean's API}
spec.description = %q{Droplet Kit is the official Ruby library for DigitalOcean's API}
spec.homepage = "https://github.com/digitalocean/droplet_kit"
spec.license = "MIT"
spec.authors = ['DigitalOcean API Engineering team']
spec.email = ['[email protected]']
spec.summary = "Droplet Kit is the official Ruby library for DigitalOcean's API"
spec.description = "Droplet Kit is the official Ruby library for DigitalOcean's API"
spec.homepage = 'https://github.com/digitalocean/droplet_kit'
spec.license = 'MIT'

spec.files = %w{LICENSE.txt README.md} + Dir.glob("lib/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) }
spec.require_paths = ["lib"]
spec.files = %w[LICENSE.txt README.md] + Dir.glob('lib/**/*', File::FNM_DOTMATCH).reject { |f| File.directory?(f) }
spec.require_paths = ['lib']

spec.required_ruby_version = '>= 2.5.0'

spec.add_dependency 'faraday', '>= 0.15'
spec.add_dependency 'kartograph', '~> 0.2.8'
spec.add_dependency 'resource_kit', '~> 0.1.5'
spec.add_dependency 'virtus', '>= 1.0.3', '<= 3'
spec.add_dependency "resource_kit", '~> 0.1.5'
spec.add_dependency "kartograph", '~> 0.2.8'
spec.add_dependency "faraday", '>= 0.15'

spec.add_development_dependency "bundler", ">= 2.1.2"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 3.9.0"
spec.add_development_dependency "rb-readline"
spec.add_development_dependency 'bundler', '>= 2.1.2'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rb-readline'
spec.add_development_dependency 'rspec', '~> 3.9.0'
if RUBY_VERSION >= '2.6'
spec.add_development_dependency 'rubocop', '>= 1.30.0'
spec.add_development_dependency 'rubocop-performance', '>= 1.14.2'
spec.add_development_dependency 'rubocop-rspec', '>= 2.11.1'
else
# latest rubocop with ruby 2.5 support
spec.add_development_dependency 'rubocop', '1.28.2'
spec.add_development_dependency 'rubocop-performance', '1.13.3'
spec.add_development_dependency 'rubocop-rspec', '2.10.0'
end
spec.add_development_dependency 'rubocop-packaging', '>= 0.5.1'
spec.add_development_dependency 'rubocop-rake', '>= 0.6.0'

spec.add_development_dependency 'webmock', '~> 3.8.0'
end
4 changes: 2 additions & 2 deletions lib/droplet_kit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ class RateLimitReached < DropletKit::Error
attr_writer :limit, :remaining

def limit
@limit.to_i if @limit
@limit&.to_i
end

def remaining
@remaining.to_i if @remaining
@remaining&.to_i
end
end
end
2 changes: 1 addition & 1 deletion lib/droplet_kit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def self.resources
end

def method_missing(name, *args, &block)
if self.class.resources.keys.include?(name)
if self.class.resources.key?(name)
resources[name] ||= self.class.resources[name].new(connection: connection)
resources[name]
else
Expand Down
7 changes: 4 additions & 3 deletions lib/droplet_kit/error_handling_resourcable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ module ErrorHandlingResourcable
def self.included(base)
base.send(:resources) do
default_handler do |response|
if (200...299).include?(response.status)
case response.status
when 200...299
next
elsif response.status == 429
when 429
error = DropletKit::RateLimitReached.new("#{response.status}: #{response.body}")
error.limit = response.headers['RateLimit-Limit']
error.remaining = response.headers['RateLimit-Remaining']
error.reset_at = response.headers['RateLimit-Reset']
raise error
else
raise DropletKit::Error.new("#{response.status}: #{response.body}")
raise DropletKit::Error, "#{response.status}: #{response.body}"
end
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/droplet_kit/mappings/balance_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class BalanceMapping
property :account_balance, scopes: [:read]
property :month_to_date_usage, scopes: [:read]
property :generated_at, scopes: [:read]

end
end
end
2 changes: 1 addition & 1 deletion lib/droplet_kit/mappings/container_registry_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ContainerRegistryMapping
mapping ContainerRegistry
root_key singular: 'registry', scopes: [:read]

property :name, scopes: [:read, :create]
property :name, scopes: %i[read create]
end
end
end
Loading

0 comments on commit 7af5ac1

Please sign in to comment.