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

add rubocop #2

Merged
merged 1 commit into from
Mar 15, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test

on: [pull_request]

# permissions:
# contents: read

jobs:
lint:
runs-on: ubuntu-latest
# env:
# BUNDLE_ONLY: rubocop

steps:
- uses: actions/checkout@v4

- name: Set up Ruby 3.2.2
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2.2
bundler-cache: true

- name: Run Tests
run: bundle exec rubocop --parallel
# run: bundle exec rake
12 changes: 9 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
coverage
pkg
Gemfile.lock
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
Gemfile.lock
85 changes: 60 additions & 25 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,71 @@
# inherit_gem:
# rubocop-rails_config:
# - config/rails.yml
# see example at https://gist.github.com/jhass/a5ae80d87f18e53e7b56

# require: rubocop-performance
# <% unless ENV['BYPASS_RUBOCOP_TODO'] %>
# inherit_from:
# <% else %>
# inherit_from:
# - '.rubocop-todo.yml'
# <% end %>

# Performance:
# Enabled: true
inherit_from:
- .rubocop_todo.yml

# Rails:
# Enabled: true
require:
- rubocop-rake

# Style/StringLiterals:
# Enabled: true
# EnforcedStyle: single_quotes
AllCops:
NewCops: enable
# TargetRubyVersion: 2.7.8
# TargetRailsVersion: 6.1.4
# Exclude:
# - 'Gemfile.lock'

# Style/FrozenStringLiteralComment:
# Enabled: false
Naming/VariableNumber:
Enabled: false

# Layout/LineLength:
# Max: 80
Layout/SpaceInsideHashLiteralBraces:
Enabled: false

# Layout/IndentationConsistency:
# EnforcedStyle: normal
Layout/EmptyLinesAroundModuleBody:
EnforcedStyle: empty_lines_special
Enabled: false

# Style/BlockDelimiters:
# Enabled: true
Layout/TrailingEmptyLines:
Enabled: false
EnforcedStyle: final_blank_line

# Rails/ApplicationRecord:
# Enabled: false
Layout/EmptyLinesAroundClassBody:
Enabled: false

# Rails/BelongsTo:
# Enabled: false
Style/RaiseArgs:
EnforcedStyle: compact

# Rails/ApplicationController:
# Enabled: false
Naming/MethodParameterName:
Enabled: false

Naming/VariableName:
Enabled: false

Layout/FirstHashElementIndentation:
Enabled: false

Layout/CaseIndentation:
EnforcedStyle: end

Metrics/ParameterLists:
Enabled: false

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

Style/TrailingUnderscoreVariable:
Enabled: false

Layout/IndentationWidth:
Enabled: false

Layout/EndAlignment:
Enabled: false

Layout/ElseAlignment:
Enabled: false
49 changes: 49 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-03-15 21:51:49 UTC using RuboCop version 1.62.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, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 59

# Offense count: 4
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 34

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

# Offense count: 4
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 15

# Offense count: 6
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 36

# Offense count: 4
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 16

# Offense count: 7
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/rails_jsonapi.rb'
- 'lib/rails_jsonapi/controller.rb'
- 'lib/rails_jsonapi/deep_deserializer.rb'
- 'lib/rails_jsonapi/railtie.rb'
25 changes: 20 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
source "https://rubygems.org"
# frozen_string_literal: true

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
source 'https://rubygems.org'

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in json_schema_form.gemspec
gemspec

gem 'jsonapi-deserializable', '~> 0', git: 'https://github.com/prysmex/jsonapi-deserializable.git'
gem 'jsonapi-serializer', '~> 2.2'
gem 'jsonapi-rspec', git: 'https://github.com/jsonapi-rb/jsonapi-rspec.git'
gem 'jsonapi-serializer', '~> 2.2'

# Specify your gem's dependencies in json_schema_form.gemspec
gemspec
# gem 'bundler', '2.4.22'
gem 'debug', '>= 1.0.0'
# gem 'minitest', '~> 5.14'
# gem 'minitest-reporters', '~> 1.6'
gem 'rails', ENV.fetch('RAILS_VERSION', nil)
gem 'rake', '~> 13.1'

# rubocop
gem 'rubocop', '~> 1.62'
# gem 'rubocop-minitest', '~> 0.35'
gem 'rubocop-performance', '~> 1.20'
gem 'rubocop-rake', '~> 0.6'
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
Expand Down
15 changes: 15 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'rails_jsonapi'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

require 'irb'
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
31 changes: 17 additions & 14 deletions jsonapi.rb.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
# frozen_string_literal: true

require 'rails_jsonapi/version'
require_relative 'lib/rails_jsonapi/version'

Gem::Specification.new do |spec|
spec.name = 'rails_jsonapi'
Expand All @@ -15,22 +14,26 @@ Gem::Specification.new do |spec|
)
spec.homepage = 'https://github.com/prysmex/jsonapi.rb'
spec.license = 'MIT'
spec.required_ruby_version = '>= 3.1.0'

spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
# spec.metadata["homepage_uri"] = spec.homepage
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
spec.metadata['rubygems_mfa_required'] = 'true'

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(__dir__) do
`git ls-files -z`.split("\x0").reject do |f|
(File.expand_path(f) == __FILE__) ||
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
end
end
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'jsonapi-deserializable', '~> 0'
spec.add_dependency 'jsonapi-serializer', '~> 2.2'
spec.add_dependency 'rack'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rails', ENV['RAILS_VERSION']
spec.add_development_dependency 'rspec', '~> 3.0'
# spec.add_development_dependency 'rspec-rails'
# spec.add_development_dependency 'jsonapi-rspec'
# spec.add_development_dependency 'rubocop'
# spec.add_development_dependency 'rubocop-rails_config'
# spec.add_development_dependency 'rubocop-performance'
end
8 changes: 5 additions & 3 deletions lib/rails_jsonapi.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rails_jsonapi/error_serializer/base'
require 'rails_jsonapi/error_serializer/active_model'
require 'rails_jsonapi/controller'
Expand All @@ -8,12 +10,12 @@

module RailsJSONAPI
# JSONAPI media type.
MEDIA_TYPE = 'application/vnd.api+json'.freeze
MEDIA_TYPE = 'application/vnd.api+json'

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

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

class << self

Expand Down
Loading