Update rubocop configuration

This commit is contained in:
Sebastian Serth
2021-05-14 10:51:09 +02:00
parent 48904a19fd
commit fe4000916c
11 changed files with 407 additions and 33 deletions

View File

@ -1,28 +1,24 @@
require:
- rubocop-performance
- rubocop-rails
- rubocop-rspec
inherit_from:
- .rubocop/layout.yml
- .rubocop/lint.yml
- .rubocop/metrics.yml
- .rubocop/performance.yml
- .rubocop/rails.yml
- .rubocop/rspec.yml
- .rubocop/style.yml
- .rubocop_todo.yml
AllCops: AllCops:
TargetRubyVersion: 2.7 TargetRubyVersion: 2.7
TargetRailsVersion: 6.1
UseCache: True
NewCops: enable NewCops: enable
Exclude: Exclude:
- bin/* - 'bin/*'
- config/application.rb - 'db/schema.rb'
- config/initializers/sorcery.rb - 'vendor/**/*'
- db/seeds/**/*
- db/schema.rb
- public/uploads/**/*
- tmp/**/*
- vendor/**/*
- node_modules/**/*
Layout/LineLength:
Enabled: false
require:
- rubocop-rspec
- rubocop-rails
Style/Documentation:
Enabled: false
Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space
RSpec/MultipleExpectations:
Max: 2
Metrics/BlockLength:
Exclude:
- 'spec/**/*.rb'
- 'config/environments/*.rb'

42
.rubocop/layout.yml Normal file
View File

@ -0,0 +1,42 @@
# layout cop settings
Layout/ArgumentAlignment:
EnforcedStyle: with_fixed_indentation
Layout/CaseIndentation:
EnforcedStyle: end
SupportedStyles:
- case
- end
IndentOneStep: true
Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent
Layout/FirstHashElementIndentation:
EnforcedStyle: consistent
#
# There are good reasons for key as well as table style.
#
Layout/HashAlignment:
Enabled: false
Layout/LineLength:
Exclude:
- "api/**/*"
- "config/**/*"
- "db/**/*"
- "spec/**/*"
Max: 120
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented
Layout/SpaceInsideBlockBraces:
EnforcedStyle: space
EnforcedStyleForEmptyBraces: no_space
SpaceBeforeBlockParameters: false
Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space

20
.rubocop/lint.yml Normal file
View File

@ -0,0 +1,20 @@
# lint cop settings
#
# False positives:
# * expect { something }.to change { something } often triggers this
#
Lint/AmbiguousBlockAssociation:
Exclude:
- "spec/**/*_spec.rb"
#Lint/ShadowingOuterLocalVariable:
# Exclude:
# - "spec/**/*_spec.rb"
#
##
## Assume we know what we do when resucing exception, as we do it much less often
## than we actually should.
##
#Lint/SuppressedException:
# Enabled: false

39
.rubocop/metrics.yml Normal file
View File

@ -0,0 +1,39 @@
# metric cop settings
#
# Method calls add to this metric, but they are everywhere in Ruby, so this
# metric caused lots of what we would consider false positives.
#
Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Exclude:
# Common files with e.g. block based DSLs
- "db/**/*"
- "spec/**/*"
- "config/**/*"
- "**/*.rake"
- "api/**/*"
- "Rakefile"
- "Guardfile"
- "**/*/Rakefile"
Max: 50
Metrics/ClassLength:
Max: 200
#
# Often used as a proxy for complexity in a method, but causes many false
# positives, e.g. when generating large, but simple, hashes.
# We want to rely on CyclomaticComplexity instead.
#
Metrics/MethodLength:
Enabled: false
#
# This seems to be the cop that is closest to what we're interested in, which
# is the kind of complexity that usually surfaces in deep nesting.
#
Metrics/CyclomaticComplexity:
Enabled: true

7
.rubocop/performance.yml Normal file
View File

@ -0,0 +1,7 @@
# performance cop settings
# The policy specs should be easy to read
#
Performance/CollectionLiteralInLoop:
Exclude:
- 'spec/policies/**'

19
.rubocop/rails.yml Normal file
View File

@ -0,0 +1,19 @@
# rails cop settings
Rails:
Enabled: true
#
# False positives:
# * On embedded models in migrations.
#
Rails/ApplicationRecord:
Exclude:
- "db/**/*"
Rails/UnknownEnv:
Environments:
- development
- staging
- production
- test

42
.rubocop/rspec.yml Normal file
View File

@ -0,0 +1,42 @@
# rspec cop settings
RSpec:
Include:
- "spec/**/*_spec.rb"
- "spec/spec_helper.rb"
- "spec/rails_helper.rb"
#
# Too stupid. There are also views, templates, request specs etc.
#
RSpec/DescribeClass:
Enabled: false
Exclude:
- "spec/views/**/*_spec.rb"
RSpec/ExampleLength:
Enabled: false
RSpec/MessageSpies:
Enabled: false
RSpec/MultipleExpectations:
Enabled: false
RSpec/NestedGroups:
Max: 7
# Some of the small example helpers are not recognized correctly
#
RSpec/EmptyExampleGroup:
Enabled: false
# The Policies need to repeat examples and descriptions and might not be performant
#
RSpec/RepeatedExample:
Exclude:
- 'spec/policies/**'
RSpec/RepeatedDescription:
Exclude:
- 'spec/policies/**'

133
.rubocop/style.yml Normal file
View File

@ -0,0 +1,133 @@
# style cop settings
#
# Nein. Period. Try to keep it English, but there *will* references using
# unicode characters.
#
Style/AsciiComments:
Enabled: false
#
# Both styles or mixtures are reasonable
#
Style/ClassAndModuleChildren:
EnforcedStyle: compact
Enabled: false
#
# Maybe a bit uncommon for new devs and often results in heavily indented code
# blocks.
#
Style/ConditionalAssignment:
Enabled: false
#
# Would be better but unlikely...
#
Style/Documentation:
Enabled: false
#
# Okay for conditions, but false positive in return statements (e.g. APIs)
#
Style/DoubleNegation:
Enabled: false
#
# Our default string token has the '%{value}' format
#
Style/FormatStringToken:
EnforcedStyle: template
#
# Far to often easy to read without.
#
Style/GuardClause:
Enabled: false
#
# IfUnlessModifier has no own line length but we do not want it to force 120
# chars long modifiers just because we allow a few long lines.
#
Style/IfUnlessModifier:
Enabled: false
##
## Scripts might include on top-level
##
#Style/MixinUsage:
# Exclude:
# - "scripts/**/*"
# - "services/*/scripts/**/*"
#
# Well, we do this. To often to disable them. Studid.
#
Style/MultilineBlockChain:
Enabled: false
#Style/NumericPredicate:
# Enabled: false
Style/RaiseArgs:
EnforcedStyle: compact
##
## Quick single line rescues in specs
##
#Style/RescueModifier:
# Exclude:
# - "spec/**/*_spec.rb"
#
##
## Quick single line rescues in specs
##
#Style/RescueStandardError:
# Enabled: false
##
## Often used pattern in chaining subjects in specs
##
#Style/Semicolon:
# Exclude:
# - "services/*/spec/**/*_spec.rb"
# - "spec/**/*_spec.rb"
Style/SignalException:
EnforcedStyle: only_raise
#
# Rails callbacks and all methods action on the arity of the given block will
# behave differently if passed a symbol proc.
#
# See here for more details:
# https://github.com/rubocop-hq/rubocop/issues/3071#issuecomment-214550737
#
# Ignore all known Rails callback methods.
#
Style/SymbolProc:
IgnoredMethods:
- after_commit
- after_create
- after_destroy
- after_rollback
- after_save
- after_update
- after_validation
- around_create
- around_destroy
- around_save
- around_update
- before_create
- before_destroy
- before_save
- before_update
- before_validation
# Migrations look better with blocks
- create_table
Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma
Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma

66
.rubocop_todo.yml Normal file
View File

@ -0,0 +1,66 @@
# TODOs
# The API seems to use huge amounts of {...} blocks for it's API design.
#
Style/BlockDelimiters:
Exclude:
- api/**/*.rb
# Lots of line are too long too.
#
Layout/LineLength:
Max: 325
Metrics/BlockLength:
Max: 110
Metrics/ClassLength:
Max: 550
Metrics/ModuleLength:
Max: 220
# It's a very complicated application...
#
Metrics/CyclomaticComplexity:
Max: 20
Metrics/PerceivedComplexity:
Max: 22
# We don't want to change previous migrations...
#
Rails/CreateTableWithTimestamps:
Enabled: false
Rails/BulkChangeTable:
Enabled: false
Rails/ReversibleMigration:
Enabled: false
Rails/NotNullColumn:
Enabled: false
# The models need to be fixed anyway
#
Rails/UniqueValidationWithoutIndex:
Enabled: false
Rails/HasManyOrHasOneDependent:
Enabled: false
Rails/HasAndBelongsToMany:
Enabled: false
Rails/InverseOf:
Enabled: false
# We have too many specs with too many lets
#
RSpec/MultipleMemoizedHelpers:
Enabled: false
RSpec/AnyInstance:
Enabled: false

View File

@ -20,7 +20,7 @@ gem 'mimemagic'
gem 'nokogiri' gem 'nokogiri'
gem 'pagedown-bootstrap-rails' gem 'pagedown-bootstrap-rails'
gem 'pg' gem 'pg'
gem 'proforma', git: 'https://github.com/openHPI/proforma.git', tag: 'v0.5.1' gem 'proforma', github: 'openHPI/proforma', tag: 'v0.5.1'
gem 'prometheus_exporter' gem 'prometheus_exporter'
gem 'pry-byebug' gem 'pry-byebug'
gem 'puma' gem 'puma'
@ -31,13 +31,13 @@ gem 'rails-i18n'
gem 'rails-timeago' gem 'rails-timeago'
gem 'ransack' gem 'ransack'
gem 'rest-client' gem 'rest-client'
gem 'rubytree' gem 'rubytree', github: 'evolve75/RubyTree'
gem 'rubyzip' gem 'rubyzip'
gem 'sass-rails' gem 'sass-rails'
gem 'slim-rails' gem 'slim-rails'
gem 'sorcery' # Causes a deprecation warning in Rails 6.0+, see: https://github.com/Sorcery/sorcery/pull/255 gem 'sorcery' # Causes a deprecation warning in Rails 6.0+, see: https://github.com/Sorcery/sorcery/pull/255
gem 'telegraf' gem 'telegraf'
gem 'tubesock', git: 'https://github.com/gosukiwi/tubesock', branch: 'patch-1' # Switch to a fork which is compatible with Rails 5 gem 'tubesock', github: 'gosukiwi/tubesock', branch: 'patch-1' # Switch to a fork which is compatible with Rails 5
gem 'turbolinks' gem 'turbolinks'
gem 'webpacker' gem 'webpacker'
gem 'whenever', require: false gem 'whenever', require: false
@ -57,6 +57,7 @@ group :development, :staging do
gem 'pry-rails' gem 'pry-rails'
gem 'rack-mini-profiler' gem 'rack-mini-profiler'
gem 'rubocop', require: false gem 'rubocop', require: false
gem 'rubocop-performance'
gem 'rubocop-rails', require: false gem 'rubocop-rails', require: false
gem 'rubocop-rspec' gem 'rubocop-rspec'
gem 'web-console' gem 'web-console'

View File

@ -1,5 +1,13 @@
GIT GIT
remote: https://github.com/gosukiwi/tubesock remote: https://github.com/evolve75/RubyTree.git
revision: eb045068f73529c66d9d84f0553fdf85fc98bc4f
specs:
rubytree (1.0.2)
json (~> 2.3.1)
structured_warnings (~> 0.4.0)
GIT
remote: https://github.com/gosukiwi/tubesock.git
revision: 86a5ca4f7d3c3a7b9a727ad91df3b9b4912eda39 revision: 86a5ca4f7d3c3a7b9a727ad91df3b9b4912eda39
branch: patch-1 branch: patch-1
specs: specs:
@ -198,7 +206,7 @@ GEM
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
jquery-ui-rails (6.0.1) jquery-ui-rails (6.0.1)
railties (>= 3.2.16) railties (>= 3.2.16)
json (2.5.1) json (2.3.1)
jwt (2.2.3) jwt (2.2.3)
kaminari (1.2.1) kaminari (1.2.1)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
@ -396,6 +404,9 @@ GEM
unicode-display_width (>= 1.4.0, < 3.0) unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.5.0) rubocop-ast (1.5.0)
parser (>= 3.0.1.1) parser (>= 3.0.1.1)
rubocop-performance (1.11.3)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.10.1) rubocop-rails (2.10.1)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
rack (>= 1.1) rack (>= 1.1)
@ -407,9 +418,6 @@ GEM
ruby-vips (2.1.2) ruby-vips (2.1.2)
ffi (~> 1.12) ffi (~> 1.12)
ruby2_keywords (0.0.4) ruby2_keywords (0.0.4)
rubytree (1.0.0)
json (~> 2.1)
structured_warnings (~> 0.3)
rubyzip (2.3.0) rubyzip (2.3.0)
sass-rails (6.0.0) sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1) sassc-rails (~> 2.1, >= 2.1.1)
@ -557,9 +565,10 @@ DEPENDENCIES
rspec-collection_matchers rspec-collection_matchers
rspec-rails rspec-rails
rubocop rubocop
rubocop-performance
rubocop-rails rubocop-rails
rubocop-rspec rubocop-rspec
rubytree rubytree!
rubyzip rubyzip
sass-rails sass-rails
selenium-webdriver selenium-webdriver