Skip to content

Commit 096c0ac

Browse files
committed
add rubocop
1 parent a841aa9 commit 096c0ac

18 files changed

+362
-175
lines changed

.github/workflows/test.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Test
2+
3+
on: [pull_request]
4+
5+
# permissions:
6+
# contents: read
7+
8+
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
# env:
12+
# BUNDLE_ONLY: rubocop
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Ruby 3.2.2
18+
uses: ruby/setup-ruby@v1
19+
with:
20+
ruby-version: 3.2.2
21+
bundler-cache: true
22+
23+
- name: Run Tests
24+
run: bundle exec rubocop --parallel
25+
# run: bundle exec rake

.gitignore

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
coverage
2-
pkg
3-
Gemfile.lock
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/
9+
Gemfile.lock

.rubocop-minitest.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
###########################################################
2+
#################### Rubocop Minitest #####################
3+
###########################################################
4+
5+
Minitest/AssertTruthy:
6+
Enabled: false
7+
8+
Minitest/RefuteFalse:
9+
Enabled: false
10+
11+
Minitest/MultipleAssertions:
12+
Max: 4

.rubocop.yml

+62-25
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,73 @@
1-
# inherit_gem:
2-
# rubocop-rails_config:
3-
# - config/rails.yml
1+
# see example at https://gist.github.com/jhass/a5ae80d87f18e53e7b56
42

5-
# require: rubocop-performance
3+
# <% unless ENV['BYPASS_RUBOCOP_TODO'] %>
4+
# inherit_from:
5+
# <% else %>
6+
# inherit_from:
7+
# - '.rubocop-todo.yml'
8+
# <% end %>
69

7-
# Performance:
8-
# Enabled: true
10+
inherit_from:
11+
- .rubocop_todo.yml
12+
- .rubocop-minitest.yml
913

10-
# Rails:
11-
# Enabled: true
14+
require:
15+
- rubocop-minitest
16+
- rubocop-rake
1217

13-
# Style/StringLiterals:
14-
# Enabled: true
15-
# EnforcedStyle: single_quotes
18+
AllCops:
19+
NewCops: enable
20+
# TargetRubyVersion: 2.7.8
21+
# TargetRailsVersion: 6.1.4
22+
# Exclude:
23+
# - 'Gemfile.lock'
1624

17-
# Style/FrozenStringLiteralComment:
18-
# Enabled: false
25+
Naming/VariableNumber:
26+
Enabled: false
1927

20-
# Layout/LineLength:
21-
# Max: 80
28+
Layout/SpaceInsideHashLiteralBraces:
29+
Enabled: false
2230

23-
# Layout/IndentationConsistency:
24-
# EnforcedStyle: normal
31+
Layout/EmptyLinesAroundModuleBody:
32+
EnforcedStyle: empty_lines_special
33+
Enabled: false
2534

26-
# Style/BlockDelimiters:
27-
# Enabled: true
35+
Layout/TrailingEmptyLines:
36+
Enabled: false
37+
EnforcedStyle: final_blank_line
2838

29-
# Rails/ApplicationRecord:
30-
# Enabled: false
39+
Layout/EmptyLinesAroundClassBody:
40+
Enabled: false
3141

32-
# Rails/BelongsTo:
33-
# Enabled: false
42+
Style/RaiseArgs:
43+
EnforcedStyle: compact
3444

35-
# Rails/ApplicationController:
36-
# Enabled: false
45+
Naming/MethodParameterName:
46+
Enabled: false
47+
48+
Naming/VariableName:
49+
Enabled: false
50+
51+
Layout/FirstHashElementIndentation:
52+
Enabled: false
53+
54+
Layout/CaseIndentation:
55+
EnforcedStyle: end
56+
57+
Metrics/ParameterLists:
58+
Enabled: false
59+
60+
Layout/MultilineMethodCallIndentation:
61+
EnforcedStyle: indented
62+
63+
Style/TrailingUnderscoreVariable:
64+
Enabled: false
65+
66+
Layout/IndentationWidth:
67+
Enabled: false
68+
69+
Layout/EndAlignment:
70+
Enabled: false
71+
72+
Layout/ElseAlignment:
73+
Enabled: false

.rubocop_todo.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2024-03-15 21:51:49 UTC using RuboCop version 1.62.1.
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: 4
10+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
11+
Metrics/AbcSize:
12+
Max: 59
13+
14+
# Offense count: 4
15+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
16+
# AllowedMethods: refine
17+
Metrics/BlockLength:
18+
Max: 34
19+
20+
# Offense count: 1
21+
# Configuration parameters: CountComments, CountAsOne.
22+
Metrics/ClassLength:
23+
Max: 119
24+
25+
# Offense count: 4
26+
# Configuration parameters: AllowedMethods, AllowedPatterns.
27+
Metrics/CyclomaticComplexity:
28+
Max: 15
29+
30+
# Offense count: 6
31+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
32+
Metrics/MethodLength:
33+
Max: 36
34+
35+
# Offense count: 4
36+
# Configuration parameters: AllowedMethods, AllowedPatterns.
37+
Metrics/PerceivedComplexity:
38+
Max: 16
39+
40+
# Offense count: 7
41+
# Configuration parameters: AllowedConstants.
42+
Style/Documentation:
43+
Exclude:
44+
- 'spec/**/*'
45+
- 'test/**/*'
46+
- 'lib/rails_jsonapi.rb'
47+
- 'lib/rails_jsonapi/controller.rb'
48+
- 'lib/rails_jsonapi/deep_deserializer.rb'
49+
- 'lib/rails_jsonapi/railtie.rb'

Gemfile

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1-
source "https://rubygems.org"
1+
# frozen_string_literal: true
22

3-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3+
source 'https://rubygems.org'
4+
5+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6+
7+
# Specify your gem's dependencies in json_schema_form.gemspec
8+
gemspec
49

510
gem 'jsonapi-deserializable', '~> 0', git: 'https://github.com/prysmex/jsonapi-deserializable.git'
6-
gem 'jsonapi-serializer', '~> 2.2'
711
gem 'jsonapi-rspec', git: 'https://github.com/jsonapi-rb/jsonapi-rspec.git'
12+
gem 'jsonapi-serializer', '~> 2.2'
813

9-
# Specify your gem's dependencies in json_schema_form.gemspec
10-
gemspec
14+
# gem 'bundler', '2.4.22'
15+
gem 'debug', '>= 1.0.0'
16+
# gem 'minitest', '~> 5.14'
17+
# gem 'minitest-reporters', '~> 1.6'
18+
gem 'rails', ENV.fetch('RAILS_VERSION', nil)
19+
gem 'rake', '~> 13.1'
20+
21+
# rubocop
22+
gem 'rubocop', '~> 1.62'
23+
# gem 'rubocop-minitest', '~> 0.35'
24+
gem 'rubocop-performance', '~> 1.20'
25+
gem 'rubocop-rake', '~> 0.6'

Rakefile

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'bundler/gem_tasks'
24
require 'rspec/core/rake_task'
35
require 'rubocop/rake_task'

bin/console

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require 'bundler/setup'
5+
require 'rails_jsonapi'
6+
7+
# You can add fixtures and/or initialization code here to make experimenting
8+
# with your gem easier. You can also use a different console, if you like.
9+
10+
# (If you use this, don't forget to add pry to your Gemfile!)
11+
# require "pry"
12+
# Pry.start
13+
14+
require 'irb'
15+
IRB.start(__FILE__)

bin/setup

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

jsonapi.rb.gemspec

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
lib = File.expand_path('../lib', __FILE__)
2-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
1+
# frozen_string_literal: true
32

4-
require 'rails_jsonapi/version'
3+
require_relative 'lib/rails_jsonapi/version'
54

65
Gem::Specification.new do |spec|
76
spec.name = 'rails_jsonapi'
@@ -15,22 +14,26 @@ Gem::Specification.new do |spec|
1514
)
1615
spec.homepage = 'https://github.com/prysmex/jsonapi.rb'
1716
spec.license = 'MIT'
17+
spec.required_ruby_version = '>= 3.1.0'
1818

19-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
19+
# spec.metadata["homepage_uri"] = spec.homepage
20+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
21+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22+
spec.metadata['rubygems_mfa_required'] = 'true'
23+
24+
# Specify which files should be added to the gem when it is released.
25+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26+
spec.files = Dir.chdir(__dir__) do
27+
`git ls-files -z`.split("\x0").reject do |f|
28+
(File.expand_path(f) == __FILE__) ||
29+
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
30+
end
2131
end
32+
spec.bindir = 'exe'
33+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
2234
spec.require_paths = ['lib']
2335

2436
spec.add_dependency 'jsonapi-deserializable', '~> 0'
2537
spec.add_dependency 'jsonapi-serializer', '~> 2.2'
2638
spec.add_dependency 'rack'
27-
28-
spec.add_development_dependency 'bundler'
29-
spec.add_development_dependency 'rails', ENV['RAILS_VERSION']
30-
spec.add_development_dependency 'rspec', '~> 3.0'
31-
# spec.add_development_dependency 'rspec-rails'
32-
# spec.add_development_dependency 'jsonapi-rspec'
33-
# spec.add_development_dependency 'rubocop'
34-
# spec.add_development_dependency 'rubocop-rails_config'
35-
# spec.add_development_dependency 'rubocop-performance'
3639
end

lib/rails_jsonapi.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'rails_jsonapi/error_serializer/base'
24
require 'rails_jsonapi/error_serializer/active_model'
35
require 'rails_jsonapi/controller'
@@ -8,12 +10,12 @@
810

911
module RailsJSONAPI
1012
# JSONAPI media type.
11-
MEDIA_TYPE = 'application/vnd.api+json'.freeze
13+
MEDIA_TYPE = 'application/vnd.api+json'
1214

13-
@class_to_serializer_proc = ->(klass){ "#{klass.name}Serializer".constantize }
15+
@class_to_serializer_proc = ->(klass) { "#{klass.name}Serializer".constantize }
1416

1517
# deserializer must return [Hash{Symbol => *}]
16-
@type_to_deserializer_proc = ->(type){ "#{type.underscore.classify}Deserializer".constantize }
18+
@type_to_deserializer_proc = ->(type) { "#{type.underscore.classify}Deserializer".constantize }
1719

1820
class << self
1921

0 commit comments

Comments
 (0)