Fix a bunch of rubocop offenses

This commit is contained in:
Lars Henrik Mai 2020-03-09 14:55:53 +01:00
parent 106c6800a4
commit 4e1e8b798a
17 changed files with 57 additions and 222 deletions

View file

@ -1 +1,25 @@
inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: 2.5
Exclude:
- 'bin/**/*'
- 'db/schema.rb'
- 'vendor/**/*'
Style/Documentation:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: true
Exclude:
- 'config.ru'
- 'Gemfile'
- 'Rakefile'
- 'app/views/**/*'
- 'config/**/*'
- 'db/**/*'
- 'lib/tasks/**/*'
Style/IfUnlessModifier:
Enabled: false

View file

@ -1,73 +1,11 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-03-09 13:28:58 +0100 using RuboCop version 0.80.1.
# on 2020-03-09 14:56:53 +0100 using RuboCop version 0.80.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: 1
# Cop supports --auto-correct.
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'lib/parseable_date_validator.rb'
# Offense count: 1
# Cop supports --auto-correct.
Layout/EmptyLines:
Exclude:
- 'config/application.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
Exclude:
- 'config/environments/development.rb'
- 'db/schema.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only
Layout/EmptyLinesAroundClassBody:
Exclude:
- 'config/application.rb'
- 'lib/parseable_date_validator.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity.
# SupportedStylesAlignWith: keyword, variable, start_of_line
Layout/EndAlignment:
Exclude:
- 'app/views/search/index.rss.builder'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Exclude:
- 'bin/rails'
- 'config.ru'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment.
Layout/LeadingCommentSpace:
Exclude:
- 'config/application.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: final_newline, final_blank_line
Layout/TrailingEmptyLines:
Exclude:
- 'config/initializers/assets.rb'
- 'config/initializers/cookies_serializer.rb'
# Offense count: 1
Lint/InterpolationCheck:
Exclude:
@ -79,32 +17,11 @@ Lint/SendWithMixinArgument:
Exclude:
- 'config/initializers/kaminari_config.rb'
# Offense count: 3
# Configuration parameters: AllowComments.
Lint/SuppressedException:
Exclude:
- 'bin/rails'
- 'bin/rake'
- 'bin/rspec'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
Lint/UnusedMethodArgument:
Exclude:
- 'lib/parseable_date_validator.rb'
# Offense count: 2
Lint/UselessAssignment:
Exclude:
- 'lib/parseable_date_validator.rb'
- 'spec/features/basic_search_spec.rb'
# Offense count: 4
Metrics/AbcSize:
Max: 58
# Offense count: 9
# Offense count: 8
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
@ -137,124 +54,18 @@ Naming/VariableNumber:
Exclude:
- 'spec/features/search_filters_spec.rb'
# Offense count: 15
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'app/controllers/application_controller.rb'
- 'app/controllers/geo_controller.rb'
- 'app/controllers/import_controller.rb'
- 'app/controllers/search_controller.rb'
- 'app/helpers/search_helper.rb'
- 'app/models/importer.rb'
- 'app/models/paper.rb'
- 'app/models/paper_search.rb'
- 'app/models/user.rb'
- 'config/application.rb'
- 'db/migrate/20141117201926_create_users.rb'
- 'db/migrate/20150413193656_create_papers.rb'
- 'db/migrate/20150517152218_create_importers.rb'
- 'db/migrate/20151010070158_create_paper_searches.rb'
- 'lib/parseable_date_validator.rb'
# Offense count: 1
Style/DoubleNegation:
Exclude:
- 'app/controllers/application_controller.rb'
# Offense count: 9
# Cop supports --auto-correct.
Style/ExpandPathArguments:
Exclude:
- 'Rakefile'
- 'bin/bundle'
- 'bin/rails'
- 'bin/rake'
- 'bin/rspec'
- 'config/application.rb'
- 'config/boot.rb'
- 'config/environment.rb'
# Offense count: 34
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Style/HashSyntax:
Exclude:
- 'config/routes.rb'
# Offense count: 7
# Cop supports --auto-correct.
Style/IfUnlessModifier:
Exclude:
- 'app/models/paper_search.rb'
- 'app/views/search/index.rss.builder'
- 'spec/rails_helper.rb'
# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: .
# SupportedStyles: call, braces
Style/LambdaCall:
EnforcedStyle: braces
# Offense count: 2
Style/MultilineTernaryOperator:
Exclude:
- 'app/controllers/search_controller.rb'
- 'spec/features/basic_search_spec.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: Strict.
Style/NumericLiterals:
MinDigits: 15
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: PreferredDelimiters.
Style/PercentLiteralDelimiters:
Exclude:
- 'Guardfile'
# Offense count: 45
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Exclude:
- 'Guardfile'
- 'bin/rails'
- 'bin/rake'
- 'bin/rspec'
- 'db/schema.rb'
- 'lib/parseable_date_validator.rb'
- 'lib/tasks/import_papers.rake'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: MinSize.
# SupportedStyles: percent, brackets
Style/SymbolArray:
EnforcedStyle: brackets
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: WordRegex.
# SupportedStyles: percent, brackets
Style/WordArray:
EnforcedStyle: percent
MinSize: 3
# Offense count: 63
# Offense count: 57
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
@ -24,8 +26,8 @@
# * zeus: 'zeus rspec' (requires the server to be started separately)
# * 'just' rspec: 'rspec'
guard :rspec, cmd: "bin/rspec" do
require "guard/rspec/dsl"
guard :rspec, cmd: 'bin/rspec' do
require 'guard/rspec/dsl'
dsl = Guard::RSpec::Dsl.new(self)
# Feel free to open issues for suggestions and improvements
@ -41,15 +43,15 @@ guard :rspec, cmd: "bin/rspec" do
dsl.watch_spec_files_for(ruby.lib_files)
# Rails files
rails = dsl.rails(view_extensions: %w(erb haml slim))
rails = dsl.rails(view_extensions: %w[erb haml slim])
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)
watch(rails.controllers) do |m|
[
rspec.spec.("routing/#{m[1]}_routing"),
rspec.spec.("controllers/#{m[1]}_controller"),
rspec.spec.("acceptance/#{m[1]}")
rspec.spec.call("routing/#{m[1]}_routing"),
rspec.spec.call("controllers/#{m[1]}_controller"),
rspec.spec.call("acceptance/#{m[1]}")
]
end
@ -59,12 +61,12 @@ guard :rspec, cmd: "bin/rspec" do
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
end
end

View file

@ -1,6 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
require File.expand_path('config/application', __dir__)
Rails.application.load_tasks

View file

@ -1,4 +1,4 @@
require File.expand_path('../boot', __FILE__)
require File.expand_path('boot', __dir__)
require 'rails/all'
@ -20,9 +20,7 @@ module LorisWeb
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
config.i18n.default_locale = :de
# https://stackoverflow.com/a/28008145
#config.active_record.raise_in_transactional_callbacks = true
# config.active_record.raise_in_transactional_callbacks = true
end
end

View file

@ -1,4 +1,4 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])

View file

@ -1,5 +1,5 @@
# Load the Rails application.
require File.expand_path('../application', __FILE__)
require File.expand_path('application', __dir__)
# Initialize the Rails application.
Rails.application.initialize!

View file

@ -37,5 +37,4 @@ Rails.application.configure do
# flush stdout in order to get logs in realtime
$stdout.sync = true
end

View file

@ -1,5 +1,5 @@
Rails.application.routes.draw do
root :to => 'search#index', as: :search
root to: 'search#index', as: :search
post '/import' => 'import#new_papers_callback'
get '/map' => 'geo#index', as: :geo
get '/glossary' => 'application#glossary', as: :glossary

View file

@ -19,6 +19,6 @@ class CreatePapers < ActiveRecord::Migration[4.2]
add_index(:papers, :reference)
add_index(:papers, :originator)
add_index(:papers, :body)
add_index(:papers, [:reference, :body], unique: true)
add_index(:papers, %i[reference body], unique: true)
end
end

View file

@ -1,12 +1,13 @@
class ParseableDateValidator < ActiveModel::EachValidator
# frozen_string_literal: true
def validate_each(record, attribute, value)
class ParseableDateValidator < ActiveModel::EachValidator
def validate_each(record, attribute, _value)
raw_value = record.read_attribute_before_type_cast(attribute)
return nil if raw_value.nil?
Date.parse(raw_value.to_json)
nil
rescue ArgumentError => e
record.errors[attribute] << (options[:message] || I18n.t("errors.messages.unparseable_date"))
rescue ArgumentError
record.errors[attribute] << (options[:message] || I18n.t('errors.messages.unparseable_date'))
end
end

View file

@ -2,7 +2,7 @@ desc 'Import Paper records from setup importers'
task import_papers: :environment do
require 'open-uri'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
api_key = Rails.application.config_for(:morph)["key"]
api_key = Rails.application.config_for(:morph)['key']
uri = URI.parse("https://api.morph.io/jrlover/city_council_leipzig_recent_papers/data.json?key=#{api_key}&query=select%20*%20from%20%27data%27")
Paper.import_from_json(uri.read)
end

View file

@ -209,7 +209,7 @@ RSpec.feature 'Basic search', type: :feature, elasticsearch: true do
end
scenario "Finds no 'Fahrrad' with search 'Rad'" do
paper = FactoryBot.create(:paper, name: 'Fahrrad')
FactoryBot.create(:paper, name: 'Fahrrad')
Paper.__elasticsearch__.refresh_index!
visit search_path body: 'leipzig', paper_search: { query: 'Rad' }
expect(page).to have_content('0 Dokumente in der Datenbank')