Skip to content

Commit 5e97978

Browse files
Merge pull request #7 from jamesstonehill/add-rubocop
Add Rubocop
2 parents 793523e + f3ad954 commit 5e97978

24 files changed

+202
-20
lines changed

.rubocop.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
inherit_from: .rubocop_todo.yml
2+
3+
AllCops:
4+
TargetRubyVersion: 2.3
5+
Exclude:
6+
- 'vendor/**/*'
7+
- 'rails_*/**/*'
8+
9+
Style/StringLiterals:
10+
EnforcedStyle: double_quotes
11+
12+
Metrics/LineLength:
13+
Max: 100
14+
15+
Style/MethodCallWithoutArgsParentheses:
16+
Enabled: false
17+
18+
Style/TrailingCommaInArrayLiteral:
19+
EnforcedStyleForMultiline: comma
20+
21+
Style/TrailingCommaInHashLiteral:
22+
EnforcedStyleForMultiline: comma
23+
24+
Metrics/BlockLength:
25+
Exclude:
26+
- 'spec/**/*.rb'
27+
- 'api_error_handler.gemspec'
28+
29+
Style/Documentation:
30+
Enabled: false

.rubocop_todo.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 100`
3+
# on 2019-08-25 13:23:25 +0100 using RuboCop version 0.74.0.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 1
10+
# Cop supports --auto-correct.
11+
# Configuration parameters: TreatCommentsAsGroupSeparators, Include.
12+
# Include: **/*.gemspec
13+
Gemspec/OrderedDependencies:
14+
Exclude:
15+
- 'api_error_handler.gemspec'
16+
17+
# Offense count: 1
18+
# Cop supports --auto-correct.
19+
Layout/ClosingParenthesisIndentation:
20+
Exclude:
21+
- 'spec/api_error_handler/serializers/xml_spec.rb'
22+
23+
# Offense count: 2
24+
# Configuration parameters: Max.
25+
Metrics/AbcSize:
26+
Exclude:
27+
- 'lib/api_error_handler.rb'
28+
- 'lib/api_error_handler/error_reporter.rb'
29+
30+
# Offense count: 1
31+
# Configuration parameters: Max.
32+
Metrics/CyclomaticComplexity:
33+
Exclude:
34+
- 'lib/api_error_handler/error_reporter.rb'
35+
36+
# Offense count: 3
37+
# Configuration parameters: CountComments, Max, ExcludedMethods.
38+
Metrics/MethodLength:
39+
Exclude:
40+
- 'lib/api_error_handler.rb'
41+
- 'lib/api_error_handler/error_reporter.rb'
42+
- 'lib/api_error_handler/error_id_generator.rb'
43+
- 'lib/api_error_handler/serializers/json_api.rb'
44+
45+
# Offense count: 1
46+
# Configuration parameters: Max.
47+
Metrics/PerceivedComplexity:
48+
Exclude:
49+
- 'lib/api_error_handler/error_reporter.rb'
50+
51+
# Offense count: 2
52+
# Cop supports --auto-correct.
53+
Style/ExpandPathArguments:
54+
Exclude:
55+
- 'api_error_handler.gemspec'
56+
57+
# Offense count: 4
58+
# Cop supports --auto-correct.
59+
# Configuration parameters: EnforcedStyle.
60+
# SupportedStyles: implicit, explicit
61+
Style/RescueStandardError:
62+
Exclude:
63+
- 'lib/api_error_handler.rb'
64+
- 'spec/api_error_handler/serializers/json_api_spec.rb'
65+
- 'spec/api_error_handler/serializers/json_spec.rb'
66+
- 'spec/api_error_handler/serializers/xml_spec.rb'
67+
68+
# Offense count: 2
69+
# Cop supports --auto-correct.
70+
# Configuration parameters: EnforcedStyleForMultiline.
71+
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
72+
Style/TrailingCommaInArrayLiteral:
73+
Exclude:
74+
- 'lib/api_error_handler/serializers/json_api.rb'
75+
- 'spec/api_error_handler/serializers/json_api_spec.rb'
76+
77+
# Offense count: 3
78+
# Cop supports --auto-correct.
79+
# Configuration parameters: EnforcedStyleForMultiline.
80+
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
81+
Style/TrailingCommaInHashLiteral:
82+
Exclude:
83+
- 'lib/api_error_handler.rb'
84+
- 'lib/api_error_handler/serializers/json.rb'
85+
- 'lib/api_error_handler/serializers/json_api.rb'

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ matrix:
1919
- rvm: 2.5.1
2020
gemfile: ./rails_6_test_app/Gemfile
2121
script: cd rails_6_test_app && bundle exec rspec
22+
- rvm: 2.3.8
23+
gemfile: Gemfile
24+
script: bundle exec rubocop
2225
- rvm: 2.3.8
2326
gemfile: Gemfile
2427
script: bundle exec rspec

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
source "https://rubygems.org"
24

35
# Specify your gem's dependencies in api_error_handler.gemspec

Rakefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# frozen_string_literal: true
2+
13
require "bundler/gem_tasks"
24
require "rspec/core/rake_task"
35

46
RSpec::Core::RakeTask.new(:spec)
57

6-
task :default => :spec
8+
task default: :spec

api_error_handler.gemspec

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen_string_literal: true
12

23
lib = File.expand_path("../lib", __FILE__)
34
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -8,16 +9,26 @@ Gem::Specification.new do |spec|
89
spec.version = ApiErrorHandler::VERSION
910
spec.authors = ["James Stonehill"]
1011
spec.email = ["james.stonehill@gmail.com"]
11-
spec.required_ruby_version = '~> 2.3'
12+
spec.required_ruby_version = "~> 2.3"
13+
14+
spec.summary = <<~SUMMARY
15+
A gem that helps you easily handle exceptions in your Rails API and return
16+
informative responses to the client.
17+
SUMMARY
18+
19+
spec.description = <<~DESCRIPTION
20+
A gem that helps you easily handle exceptions in your Ruby on Rails API and
21+
return informative responses to the client by serializing exceptions into JSON
22+
and other popular API formats and returning a response with a status code that
23+
makes sense based on the exception.
24+
DESCRIPTION
1225

13-
spec.summary = %q{A gem that helps you easily handle exceptions in your Rails API and return informative responses to the client.}
14-
spec.description = %q{A gem that helps you easily handle exceptions in your Ruby on Rails API and return informative responses to the client by serializing exceptions into JSON and other popular API formats and returning a response with a status code that makes sense based on the exception.}
1526
spec.homepage = "https://github.com/jamesstonehill/api_error_handler"
1627
spec.license = "MIT"
1728

1829
# Specify which files should be added to the gem when it is released.
1930
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
2132
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|rails_.+)/}) }
2233
end
2334
spec.bindir = "exe"
@@ -31,4 +42,5 @@ Gem::Specification.new do |spec|
3142
spec.add_development_dependency "bundler", "~> 2.0"
3243
spec.add_development_dependency "rake", "~> 10.0"
3344
spec.add_development_dependency "rspec-rails", "~> 3.0"
45+
spec.add_development_dependency "rubocop", "~> 0.74.0"
3446
end

bin/console

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
23

34
require "bundler/setup"
45
require "api_error_handler"

lib/api_error_handler.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
# frozen_string_literal: true
2+
13
require_relative "./api_error_handler/version"
24
require_relative "./api_error_handler/action_controller"
35
require_relative "./api_error_handler/error_id_generator"
46
require_relative "./api_error_handler/error_reporter"
5-
Dir[File.join(__dir__, 'api_error_handler', 'serializers', "*.rb")].each { |file| require file }
7+
Dir[File.join(__dir__, "api_error_handler", "serializers", "*.rb")].each do |file|
8+
require file
9+
end
610

711
module ApiErrorHandler
812
SERIALIZERS_BY_FORMAT = {

lib/api_error_handler/action_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
require 'active_support/lazy_load_hooks'
2-
require 'action_controller'
1+
# frozen_string_literal: true
2+
3+
require "active_support/lazy_load_hooks"
4+
require "action_controller"
35

46
ActiveSupport.on_load :action_controller do
57
::ActionController::Base.send :extend, ApiErrorHandler

lib/api_error_handler/error_id_generator.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require "securerandom"
24
require_relative "./errors"
35

@@ -11,7 +13,10 @@ def self.run(error_id_option)
1113
elsif error_id_option.nil?
1214
nil
1315
else
14-
raise(InvalidOptionError, "Unable to handle `#{error_id_option}` as argument for the `:error_id` option.")
16+
raise(
17+
InvalidOptionError,
18+
"Unable to handle `#{error_id_option}` as argument for the `:error_id` option."
19+
)
1520
end
1621
end
1722
end

0 commit comments

Comments
 (0)