mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Add Style enforcer (via Rubocop)
It will fail the build, but as it is currently, most of the cops are 'todos'. Great for new contributors.. :)
This commit is contained in:
parent
6784866a2d
commit
09c97de90d
49
.rubocop.yml
Normal file
49
.rubocop.yml
Normal file
@ -0,0 +1,49 @@
|
||||
inherit_from: .rubocop_todo.yml
|
||||
|
||||
AllCops:
|
||||
Exclude:
|
||||
- config/initializers/forbidden_yaml.rb
|
||||
- !ruby/regexp /(vendor|bundle|bin|db)\/.*/
|
||||
RunRailsCops: true
|
||||
DisplayCopNames: true
|
||||
DisplayStyleGuide: true
|
||||
|
||||
Lint/NestedMethodDefinition:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- test/action_controller/serialization_test.rb
|
||||
|
||||
Style/StringLiterals:
|
||||
EnforcedStyle: single_quotes
|
||||
|
||||
Metrics/AbcSize:
|
||||
Max: 35 # TODO: Lower to 15
|
||||
|
||||
Metrics/ClassLength:
|
||||
Max: 261 # TODO: Lower to 100
|
||||
Exclude:
|
||||
- test/**/*.rb
|
||||
|
||||
Metrics/CyclomaticComplexity:
|
||||
Max: 7 # TODO: Lower to 6
|
||||
|
||||
Metrics/LineLength:
|
||||
Max: 251 # TODO: Lower to 80
|
||||
|
||||
Metrics/MethodLength:
|
||||
Max: 106 # TODO: Lower to 10
|
||||
|
||||
Metrics/PerceivedComplexity:
|
||||
Max: 9 # TODO: Lower to 7
|
||||
|
||||
Style/AlignParameters:
|
||||
EnforcedStyle: with_fixed_indentation
|
||||
|
||||
Style/ClassAndModuleChildren:
|
||||
EnforcedStyle: compact
|
||||
|
||||
Style/Documentation:
|
||||
Enabled: false
|
||||
|
||||
Style/MultilineOperationIndentation:
|
||||
EnforcedStyle: indented
|
||||
347
.rubocop_todo.yml
Normal file
347
.rubocop_todo.yml
Normal file
@ -0,0 +1,347 @@
|
||||
# This configuration was generated by `rubocop --auto-gen-config`
|
||||
# on 2015-08-30 23:03:50 -0500 using RuboCop version 0.31.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: AllowSafeAssignment.
|
||||
Lint/AssignmentInCondition:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
Lint/EmptyEnsure:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
Lint/HandleExceptions:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
Lint/UnusedBlockArgument:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 9
|
||||
# Cop supports --auto-correct.
|
||||
Lint/UnusedMethodArgument:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
Lint/UselessAccessModifier:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 3
|
||||
Lint/UselessAssignment:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Rails/Date:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 8
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Rails/TimeZone:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/AccessModifierIndentation:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 16
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
|
||||
Style/AlignHash:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 6
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/AlignParameters:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/AndOr:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 6
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
|
||||
Style/BlockDelimiters:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 46
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/BracesAroundHashParameters:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 167
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/ClassAndModuleChildren:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Style/CommentIndentation:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
Style/DoubleNegation:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
Style/EachWithObject:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 4
|
||||
# Cop supports --auto-correct.
|
||||
Style/EmptyLines:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
Style/EmptyLinesAroundAccessModifier:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/EmptyLinesAroundBlockBody:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 16
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/EmptyLinesAroundClassBody:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 9
|
||||
# Cop supports --auto-correct.
|
||||
Style/EmptyLinesAroundMethodBody:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/EmptyLinesAroundModuleBody:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 3
|
||||
# Configuration parameters: MinBodyLength.
|
||||
Style/GuardClause:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 12
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
|
||||
Style/HashSyntax:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 9
|
||||
# Cop supports --auto-correct.
|
||||
Style/IndentArray:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 8
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/IndentHash:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/IndentationConsistency:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: Width.
|
||||
Style/IndentationWidth:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Style/Lambda:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
Style/MethodCallParentheses:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/MethodDefParentheses:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/MultilineOperationIndentation:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Style/NegatedIf:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
|
||||
Style/Next:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Style/NumericLiterals:
|
||||
MinDigits: 7
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: PreferredDelimiters.
|
||||
Style/PercentLiteralDelimiters:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
Style/PerlBackrefs:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 6
|
||||
# Configuration parameters: NamePrefix, NamePrefixBlacklist.
|
||||
Style/PredicateName:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 7
|
||||
# Cop supports --auto-correct.
|
||||
Style/RedundantSelf:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowAsExpressionSeparator.
|
||||
Style/Semicolon:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 6
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/SignalException:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowIfMethodIsEmpty.
|
||||
Style/SingleLineMethods:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 26
|
||||
# Cop supports --auto-correct.
|
||||
Style/SpaceAfterColon:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 7
|
||||
# Cop supports --auto-correct.
|
||||
Style/SpaceAfterComma:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Style/SpaceAfterNot:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 5
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/SpaceAroundEqualsInParameterDefault:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 39
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: MultiSpaceAllowedForOperators.
|
||||
Style/SpaceAroundOperators:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/SpaceBeforeBlockBraces:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 8
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
||||
Style/SpaceInsideBlockBraces:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 20
|
||||
# Cop supports --auto-correct.
|
||||
Style/SpaceInsideBrackets:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 179
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
|
||||
Style/SpaceInsideHashLiteralBraces:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Style/SpaceInsideParens:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/StringLiteralsInInterpolation:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
Style/StructInheritance:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: IgnoredMethods.
|
||||
Style/SymbolProc:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 9
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/TrailingBlankLines:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 6
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
|
||||
Style/TrailingComma:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
Style/TrailingWhitespace:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
Style/UnlessElse:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
Style/UnneededPercentQ:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 4
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: WordRegex.
|
||||
Style/WordArray:
|
||||
MinSize: 2
|
||||
@ -2,6 +2,9 @@ language: ruby
|
||||
|
||||
sudo: false
|
||||
|
||||
cache:
|
||||
bundler: true
|
||||
|
||||
rvm:
|
||||
- 1.9.3
|
||||
- 2.0.0
|
||||
@ -14,6 +17,10 @@ rvm:
|
||||
install:
|
||||
- bundle install --retry=3
|
||||
|
||||
script:
|
||||
- bundle exec rake
|
||||
- bundle exec rake rubocop
|
||||
|
||||
env:
|
||||
- "RAILS_VERSION=4.0"
|
||||
- "RAILS_VERSION=4.1"
|
||||
@ -24,3 +31,4 @@ matrix:
|
||||
allow_failures:
|
||||
- rvm: ruby-head
|
||||
- env: "RAILS_VERSION=master"
|
||||
fast_finish: true
|
||||
|
||||
4
Gemfile
4
Gemfile
@ -33,3 +33,7 @@ end
|
||||
|
||||
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
||||
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
||||
|
||||
group :development, :test do
|
||||
gem 'rubocop', '~> 0.33.0', require: false
|
||||
end
|
||||
|
||||
17
Rakefile
17
Rakefile
@ -1,9 +1,22 @@
|
||||
require "bundler/gem_tasks"
|
||||
require 'bundler/gem_tasks'
|
||||
|
||||
begin
|
||||
require 'rubocop'
|
||||
require 'rubocop/rake_task'
|
||||
rescue LoadError
|
||||
else
|
||||
Rake::Task[:rubocop].clear if Rake::Task.task_defined?(:rubocop)
|
||||
desc 'Execute rubocop'
|
||||
RuboCop::RakeTask.new(:rubocop) do |task|
|
||||
task.options = ['--rails', '--display-cop-names', '--display-style-guide']
|
||||
task.fail_on_error = true
|
||||
end
|
||||
end
|
||||
|
||||
require 'rake/testtask'
|
||||
|
||||
Rake::TestTask.new do |t|
|
||||
t.libs << "test"
|
||||
t.libs << 'test'
|
||||
t.test_files = FileList['test/**/*_test.rb']
|
||||
t.ruby_opts = ['-r./test/test_helper.rb']
|
||||
t.verbose = true
|
||||
|
||||
@ -9,7 +9,7 @@ module Rails
|
||||
class_option :parent, :type => :string, :desc => "The parent class for the generated serializer"
|
||||
|
||||
def create_serializer_file
|
||||
template 'serializer.rb', File.join('app/serializers', class_path, "#{file_name}_serializer.rb")
|
||||
template 'serializer.rb.erb', File.join('app/serializers', class_path, "#{file_name}_serializer.rb")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
0
lib/tasks/rubocop.rake
Normal file
0
lib/tasks/rubocop.rake
Normal file
@ -1,4 +1,3 @@
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
module ActionController
|
||||
@ -189,7 +188,7 @@ module ActionController
|
||||
def test_render_array_using_custom_root
|
||||
get :render_array_using_custom_root
|
||||
|
||||
expected = {custom_roots: [{name: "Name 1", description: "Description 1"}]}
|
||||
expected = {custom_roots: [{name: "Name 1", description: "Description 1"}]}
|
||||
assert_equal 'application/json', @response.content_type
|
||||
assert_equal expected.to_json, @response.body
|
||||
end
|
||||
@ -197,7 +196,7 @@ module ActionController
|
||||
def test_render_array_that_is_empty_using_custom_root
|
||||
get :render_array_that_is_empty_using_custom_root
|
||||
|
||||
expected = {custom_roots: []}
|
||||
expected = {custom_roots: []}
|
||||
assert_equal 'application/json', @response.content_type
|
||||
assert_equal expected.to_json, @response.body
|
||||
end
|
||||
@ -205,7 +204,7 @@ module ActionController
|
||||
def test_render_object_using_custom_root
|
||||
get :render_object_using_custom_root
|
||||
|
||||
expected = {custom_root: {name: "Name 1", description: "Description 1"}}
|
||||
expected = {custom_root: {name: 'Name 1', description: 'Description 1'}}
|
||||
assert_equal 'application/json', @response.content_type
|
||||
assert_equal expected.to_json, @response.body
|
||||
end
|
||||
|
||||
2
test/fixtures/poro.rb
vendored
2
test/fixtures/poro.rb
vendored
@ -83,7 +83,7 @@ Location = Class.new(Model)
|
||||
Place = Class.new(Model)
|
||||
Tag = Class.new(Model)
|
||||
VirtualValue = Class.new(Model)
|
||||
Comment = Class.new(Model) do
|
||||
Comment = Class.new(Model) do
|
||||
# Uses a custom non-time-based cache key
|
||||
def cache_key
|
||||
"#{self.class.name.downcase}/#{self.id}"
|
||||
|
||||
@ -26,7 +26,7 @@ module ActiveModel
|
||||
end
|
||||
end
|
||||
|
||||
class SerializerTest < Minitest::Test
|
||||
class SerializerTest < Minitest::Test
|
||||
class MyProfile < Profile
|
||||
end
|
||||
class CustomProfile
|
||||
|
||||
@ -29,7 +29,7 @@ rescue LoadError
|
||||
def capture(stream)
|
||||
stream = stream.to_s
|
||||
captured_stream = Tempfile.new(stream)
|
||||
stream_io = eval("$#{stream}")
|
||||
stream_io = eval("$#{stream}") # rubocop:disable Lint/Eval
|
||||
origin_stream = stream_io.dup
|
||||
stream_io.reopen(captured_stream)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user