From fe4000916c2d9eefecc97b4dc4a8a49df29db204 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Fri, 14 May 2021 10:51:09 +0200 Subject: [PATCH] Update rubocop configuration --- .rubocop.yml | 44 ++++++------- .rubocop/layout.yml | 42 +++++++++++++ .rubocop/lint.yml | 20 ++++++ .rubocop/metrics.yml | 39 ++++++++++++ .rubocop/performance.yml | 7 +++ .rubocop/rails.yml | 19 ++++++ .rubocop/rspec.yml | 42 +++++++++++++ .rubocop/style.yml | 133 +++++++++++++++++++++++++++++++++++++++ .rubocop_todo.yml | 66 +++++++++++++++++++ Gemfile | 7 ++- Gemfile.lock | 21 +++++-- 11 files changed, 407 insertions(+), 33 deletions(-) create mode 100644 .rubocop/layout.yml create mode 100644 .rubocop/lint.yml create mode 100644 .rubocop/metrics.yml create mode 100644 .rubocop/performance.yml create mode 100644 .rubocop/rails.yml create mode 100644 .rubocop/rspec.yml create mode 100644 .rubocop/style.yml create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index 727ed6a6..17bffd55 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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: TargetRubyVersion: 2.7 + TargetRailsVersion: 6.1 + UseCache: True NewCops: enable Exclude: - - bin/* - - config/application.rb - - config/initializers/sorcery.rb - - 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' + - 'bin/*' + - 'db/schema.rb' + - 'vendor/**/*' diff --git a/.rubocop/layout.yml b/.rubocop/layout.yml new file mode 100644 index 00000000..5ada29a1 --- /dev/null +++ b/.rubocop/layout.yml @@ -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 diff --git a/.rubocop/lint.yml b/.rubocop/lint.yml new file mode 100644 index 00000000..98fdac2d --- /dev/null +++ b/.rubocop/lint.yml @@ -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 diff --git a/.rubocop/metrics.yml b/.rubocop/metrics.yml new file mode 100644 index 00000000..bfb4e313 --- /dev/null +++ b/.rubocop/metrics.yml @@ -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 diff --git a/.rubocop/performance.yml b/.rubocop/performance.yml new file mode 100644 index 00000000..ac5ff55d --- /dev/null +++ b/.rubocop/performance.yml @@ -0,0 +1,7 @@ +# performance cop settings + +# The policy specs should be easy to read +# +Performance/CollectionLiteralInLoop: + Exclude: + - 'spec/policies/**' diff --git a/.rubocop/rails.yml b/.rubocop/rails.yml new file mode 100644 index 00000000..84029b1f --- /dev/null +++ b/.rubocop/rails.yml @@ -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 diff --git a/.rubocop/rspec.yml b/.rubocop/rspec.yml new file mode 100644 index 00000000..8ace4bdf --- /dev/null +++ b/.rubocop/rspec.yml @@ -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/**' diff --git a/.rubocop/style.yml b/.rubocop/style.yml new file mode 100644 index 00000000..1156b04c --- /dev/null +++ b/.rubocop/style.yml @@ -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 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..fbbc4122 --- /dev/null +++ b/.rubocop_todo.yml @@ -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 diff --git a/Gemfile b/Gemfile index 0cabf18e..4e1cd9d6 100644 --- a/Gemfile +++ b/Gemfile @@ -20,7 +20,7 @@ gem 'mimemagic' gem 'nokogiri' gem 'pagedown-bootstrap-rails' 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 'pry-byebug' gem 'puma' @@ -31,13 +31,13 @@ gem 'rails-i18n' gem 'rails-timeago' gem 'ransack' gem 'rest-client' -gem 'rubytree' +gem 'rubytree', github: 'evolve75/RubyTree' gem 'rubyzip' gem 'sass-rails' gem 'slim-rails' gem 'sorcery' # Causes a deprecation warning in Rails 6.0+, see: https://github.com/Sorcery/sorcery/pull/255 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 'webpacker' gem 'whenever', require: false @@ -57,6 +57,7 @@ group :development, :staging do gem 'pry-rails' gem 'rack-mini-profiler' gem 'rubocop', require: false + gem 'rubocop-performance' gem 'rubocop-rails', require: false gem 'rubocop-rspec' gem 'web-console' diff --git a/Gemfile.lock b/Gemfile.lock index c4424c3f..20a705d0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,13 @@ 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 branch: patch-1 specs: @@ -198,7 +206,7 @@ GEM thor (>= 0.14, < 2.0) jquery-ui-rails (6.0.1) railties (>= 3.2.16) - json (2.5.1) + json (2.3.1) jwt (2.2.3) kaminari (1.2.1) activesupport (>= 4.1.0) @@ -396,6 +404,9 @@ GEM unicode-display_width (>= 1.4.0, < 3.0) rubocop-ast (1.5.0) 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) activesupport (>= 4.2.0) rack (>= 1.1) @@ -407,9 +418,6 @@ GEM ruby-vips (2.1.2) ffi (~> 1.12) ruby2_keywords (0.0.4) - rubytree (1.0.0) - json (~> 2.1) - structured_warnings (~> 0.3) rubyzip (2.3.0) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) @@ -557,9 +565,10 @@ DEPENDENCIES rspec-collection_matchers rspec-rails rubocop + rubocop-performance rubocop-rails rubocop-rspec - rubytree + rubytree! rubyzip sass-rails selenium-webdriver