Browse Source

Applied changes for Rubocop 0.51.

Thorsten Eckel 7 years ago
parent
commit
705487154c

+ 49 - 12
.rubocop.yml

@@ -45,29 +45,29 @@ Style/TrailingCommaInArguments:
   StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
   Enabled: false
 
-Style/SpaceInsideParens:
+Layout/SpaceInsideParens:
   Description: 'No spaces after ( or before ).'
   StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces'
   Enabled: false
 
-Style/SpaceAfterMethodName:
+Layout/SpaceAfterMethodName:
   Description: >-
                  Do not put a space between a method name and the opening
                  parenthesis in a method definition.
   StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces'
   Enabled: false
 
-Style/LeadingCommentSpace:
+Layout/LeadingCommentSpace:
   Description: 'Comments should start with a space.'
   StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-space'
   Enabled: false
 
-Style/MethodCallParentheses:
+Style/MethodCallWithoutArgsParentheses:
   Description: 'Do not use parentheses for method calls with no arguments.'
   StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens'
   Enabled: false
 
-Style/SpaceInsideBrackets:
+Layout/SpaceInsideBrackets:
   Description: 'No spaces after [ or before ].'
   StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces'
   Enabled: false
@@ -83,19 +83,19 @@ Style/MethodDefParentheses:
   StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens'
   Enabled: false
 
-Style/EmptyLinesAroundClassBody:
+Layout/EmptyLinesAroundClassBody:
   Description: "Keeps track of empty lines around class bodies."
   Enabled: false
 
-Style/EmptyLinesAroundMethodBody:
+Layout/EmptyLinesAroundMethodBody:
   Description: "Keeps track of empty lines around method bodies."
   Enabled: false
 
-Style/EmptyLinesAroundBlockBody:
+Layout/EmptyLinesAroundBlockBody:
   Description: "Keeps track of empty lines around block bodies."
   Enabled: false
 
-Style/EmptyLinesAroundModuleBody:
+Layout/EmptyLinesAroundModuleBody:
   Description: "Keeps track of empty lines around module bodies."
   Enabled: false
 
@@ -143,17 +143,29 @@ Rails/HasAndBelongsToMany:
 #  StyleGuide: 'https://github.com/bbatsov/rails-style-guide#has-many-through'
   Enabled: false
 
+Rails/SkipsModelValidations:
+  Description: >-
+                 Use methods that skips model validations with caution.
+                 See reference for more information.
+  Reference: 'http://guides.rubyonrails.org/active_record_validations.html#skipping-validations'
+  Enabled: true
+  Exclude:
+    - test/**/*
+
 Style/ClassAndModuleChildren:
   Description: 'Checks style of children classes and modules.'
   Enabled: false
 
-Style/FileName:
+Naming/FileName:
   Description: 'Use snake_case for source file names.'
   StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-files'
   Enabled: true
   Exclude:
     - 'script/websocket-server.rb'
 
+Naming/VariableNumber:
+  Description: 'Use the configured style when numbering variables.'
+  Enabled: false
 
 # 2.0
 
@@ -184,8 +196,23 @@ Metrics/ModuleLength:
   Description: 'Avoid modules longer than 100 lines of code.'
   Enabled: false
 
+Metrics/BlockLength:
+  Enabled: false
+
+Lint/RescueWithoutErrorClass:
+  Enabled: false
+
+Rails/ApplicationRecord:
+  Enabled: false
+
 # TODO
 
+Rails/HasManyOrHasOneDependent:
+  Enabled: false
+
+Style/DateTime:
+  Enabled: false
+
 Style/Documentation:
   Description: 'Document classes and non-namespace modules.'
   Enabled: false
@@ -193,7 +220,7 @@ Style/Documentation:
 Lint/UselessAssignment:
   Enabled: false
 
-Style/ExtraSpacing:
+Layout/ExtraSpacing:
   Description: 'Do not use unnecessary spacing.'
   Enabled: false
 
@@ -215,4 +242,14 @@ Style/NumericPredicate:
   AutoCorrect: false
   Enabled: true
   Exclude:
-    - "**/*_spec.rb"
+    - "**/*_spec.rb"
+
+Lint/AmbiguousBlockAssociation:
+  Description: >-
+                 Checks for ambiguous block association with method when param passed without
+                 parentheses.
+  StyleGuide: '#syntax'
+  Enabled: true
+  Exclude:
+    - "**/*_spec.rb"
+    - "**/*_examples.rb"

+ 69 - 53
Gemfile

@@ -1,112 +1,131 @@
 source 'https://rubygems.org'
 
+# core - base
 ruby '2.4.1'
-
 gem 'rails', '5.1.4'
-gem 'rails-observers'
-gem 'activerecord-session_store'
-
-# Bundle edge Rails instead:
-#gem 'rails',     :git => 'git://github.com/rails/rails.git'
 
+# core - rails additions
+gem 'activerecord-session_store'
+gem 'composite_primary_keys'
 gem 'json'
+gem 'rails-observers'
+
+# core - application servers
+gem 'puma', group: :puma
+gem 'unicorn', group: :unicorn
 
-# Supported DBs
+# core - supported ORMs
 gem 'activerecord-nulldb-adapter', group: :nulldb
 gem 'mysql2', group: :mysql
 gem 'pg', group: :postgres
 
+# core - asynchrous task execution
+gem 'daemons'
+gem 'delayed_job_active_record'
+
+# core - websocket
+gem 'em-websocket'
+gem 'eventmachine'
+
+# core - password security
+gem 'argon2'
+
+# performance - Memcached
+gem 'dalli'
+
+# asset handling
 group :assets do
-  gem 'sass-rails' #, github: 'rails/sass-rails'
+  # asset handling - coffee-script
   gem 'coffee-rails'
   gem 'coffee-script-source'
 
-  gem 'sprockets'
+  # asset handling - frontend templating
+  gem 'eco'
+
+  # asset handling - SASS
+  gem 'sass-rails'
 
+  # asset handling - pipeline
+  gem 'sprockets'
   gem 'uglifier'
-  gem 'eco'
 end
 
 gem 'autoprefixer-rails'
 
+# asset handling - javascript execution for e.g. linux
+gem 'execjs'
+gem 'libv8'
+gem 'therubyracer'
+
+# authentication - provider
 gem 'doorkeeper'
 gem 'oauth2'
 
+# authentication - third party
 gem 'omniauth'
-gem 'omniauth-oauth2'
 gem 'omniauth-facebook'
 gem 'omniauth-github'
 gem 'omniauth-gitlab'
 gem 'omniauth-google-oauth2'
 gem 'omniauth-linkedin-oauth2'
-gem 'omniauth-twitter'
 gem 'omniauth-microsoft-office365'
+gem 'omniauth-oauth2'
+gem 'omniauth-twitter'
 gem 'omniauth-weibo-oauth2'
 
-gem 'twitter'
-gem 'telegramAPI'
+# channels
 gem 'koala'
-gem 'mail'
-gem 'valid_email2'
-gem 'htmlentities'
+gem 'telegramAPI'
+gem 'twitter'
 
+# channels - email additions
+gem 'htmlentities'
+gem 'mail', '2.6.6'
 gem 'mime-types'
+gem 'valid_email2'
 
+# feature - business hours
 gem 'biz'
 
-gem 'composite_primary_keys'
-gem 'delayed_job_active_record'
-gem 'daemons'
-
-gem 'simple-rss'
-
-# e. g. on linux we need a javascript execution
-gem 'libv8'
-gem 'execjs'
-gem 'therubyracer'
-
-require 'erb'
-require 'yaml'
+# feature - signature diffing
+gem 'diffy'
 
-gem 'net-ldap'
+# feature - excel output
+gem 'writeexcel'
 
-# password security
-gem 'argon2'
+# feature - device logging
+gem 'browser'
 
-gem 'writeexcel'
+# feature - iCal export
 gem 'icalendar'
 gem 'icalendar-recurrence'
-gem 'browser'
 
 # integrations
-gem 'slack-notifier'
 gem 'clearbit'
+gem 'net-ldap'
+gem 'slack-notifier'
 gem 'zendesk_api'
-gem 'viewpoint'
-gem 'rubyntlm', git: 'https://github.com/wimm/rubyntlm.git'
-gem 'autodiscover', git: 'https://github.com/thorsteneckel/autodiscover.git'
 
-# event machine
-gem 'eventmachine'
-gem 'em-websocket'
-
-gem 'diffy'
-gem 'dalli'
+# integrations - exchange
+gem 'autodiscover', git: 'https://github.com/thorsteneckel/autodiscover.git'
+gem 'rubyntlm', git: 'https://github.com/wimm/rubyntlm.git'
+gem 'viewpoint'
 
 # Gems used only for develop/test and not required
 # in production environments by default.
 group :development, :test do
 
+  # test frameworks
   gem 'rspec-rails'
   gem 'test-unit'
-  gem 'spring'
-  gem 'spring-commands-rspec'
+
+  # test DB
   gem 'sqlite3'
 
   # code coverage
+  gem 'coveralls', require: false
   gem 'simplecov'
   gem 'simplecov-rcov'
-  gem 'coveralls',         require: false
 
   # UI tests w/ Selenium
   gem 'selenium-webdriver', '2.53.4'
@@ -121,9 +140,9 @@ group :development, :test do
   gem 'guard-symlink', require: false
 
   # code QA
+  gem 'coffeelint'
   gem 'pre-commit'
   gem 'rubocop'
-  gem 'coffeelint'
 
   # changelog generation
   gem 'github_changelog_generator'
@@ -138,10 +157,7 @@ group :development, :test do
   gem 'webmock'
 end
 
-gem 'puma', group: :puma
-gem 'unicorn', group: :unicorn
-
-# load onw gem's
+# load onw gems for development and testing purposes
 local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local')
 if File.exist?(local_gemfile)
   eval_gemfile local_gemfile

+ 3 - 12
Gemfile.lock

@@ -217,13 +217,12 @@ GEM
       crass (~> 1.0.2)
       nokogiri (>= 1.5.9)
     lumberjack (1.0.12)
-    mail (2.7.0)
-      mini_mime (>= 0.1.1)
+    mail (2.6.6)
+      mime-types (>= 1.16, < 4)
     memoizable (0.4.2)
       thread_safe (~> 0.3, >= 0.3.1)
     method_source (0.9.0)
     mime-types (2.99.3)
-    mini_mime (1.0.0)
     mini_portile2 (2.3.0)
     minitest (5.10.3)
     multi_json (1.12.2)
@@ -389,7 +388,6 @@ GEM
       rubyzip (~> 1.0)
       websocket (~> 1.0)
     shellany (0.0.1)
-    simple-rss (1.3.1)
     simple_oauth (0.3.1)
     simplecov (0.15.1)
       docile (~> 1.1.0)
@@ -399,10 +397,6 @@ GEM
     simplecov-rcov (0.2.3)
       simplecov (>= 0.4.1)
     slack-notifier (2.3.1)
-    spring (2.0.2)
-      activesupport (>= 4.2)
-    spring-commands-rspec (1.0.4)
-      spring (>= 0.9.1)
     sprockets (3.7.1)
       concurrent-ruby (~> 1.0)
       rack (> 1, < 3)
@@ -508,7 +502,7 @@ DEPENDENCIES
   json
   koala
   libv8
-  mail
+  mail (= 2.6.6)
   mime-types
   mysql2
   net-ldap
@@ -535,12 +529,9 @@ DEPENDENCIES
   rubyntlm!
   sass-rails
   selenium-webdriver (= 2.53.4)
-  simple-rss
   simplecov
   simplecov-rcov
   slack-notifier
-  spring
-  spring-commands-rspec
   sprockets
   sqlite3
   telegramAPI

+ 1 - 1
Rakefile

@@ -18,7 +18,7 @@ module ApplicationController::Authenticates
       raise Exceptions::NotAuthorized, 'Not authorized (token)!'
     end
 
-    return false if current_user && current_user.permissions?(key)
+    return false if current_user&.permissions?(key)
     raise Exceptions::NotAuthorized, 'Not authorized (user)!'
   end
 

+ 1 - 2
app/controllers/application_controller/handles_devices.rb

@@ -26,8 +26,7 @@ module ApplicationController::HandlesDevices
     if user_device_updated_at
       # check if entry exists / only if write action
       diff = Time.zone.now - 10.minutes
-      method = request.method
-      if method == 'GET' || method == 'OPTIONS' || method == 'HEAD'
+      if %w[GET OPTIONS HEAD].include?(request.method)
         diff = Time.zone.now - 30.minutes
       end
 

+ 1 - 1
app/controllers/application_controller/handles_errors.rb

@@ -72,7 +72,7 @@ module ApplicationController::HandlesErrors
       data[:error_human] = data[:error]
     end
 
-    if Rails.env.production? && !data[:error_human].empty?
+    if Rails.env.production? && data[:error_human].present?
       data[:error] = data.delete(:error_human)
     end
     data

+ 1 - 1
app/controllers/application_controller/renders_models.rb

@@ -146,7 +146,7 @@ module ApplicationController::RendersModels
   def model_references_check(object, params)
     generic_object = object.find(params[:id])
     result = Models.references(object, generic_object.id)
-    return false if result.empty?
+    return false if result.blank?
     raise Exceptions::UnprocessableEntity, 'Can\'t delete, object has references.'
   rescue => e
     raise Exceptions::UnprocessableEntity, e

+ 1 - 1
app/controllers/channels_email_controller.rb

@@ -226,7 +226,7 @@ class ChannelsEmailController < ApplicationController
 
       Channel.where(area: 'Email::Notification').each do |channel|
         active = false
-        if adapter =~ /^#{channel.options[:outbound][:adapter]}$/i
+        if adapter.match?(/^#{channel.options[:outbound][:adapter]}$/i)
           active = true
           channel.options = {
             outbound: {

+ 11 - 14
app/controllers/form_controller.rb

@@ -44,7 +44,7 @@ class FormController < ApplicationController
       errors['email'] = 'required'
     elsif params[:email] !~ /@/
       errors['email'] = 'invalid'
-    elsif params[:email] =~ /(>|<|\||\!|"|§|'|\$|%|&|\(|\)|\?|\s|\.\.)/
+    elsif params[:email].match?(/(>|<|\||\!|"|§|'|\$|%|&|\(|\)|\?|\s|\.\.)/)
       errors['email'] = 'invalid'
     end
     if params[:title].blank?
@@ -126,19 +126,16 @@ class FormController < ApplicationController
       internal: false,
     )
 
-    if params[:file]
-
-      params[:file].each do |file|
-        Store.add(
-          object: 'Ticket::Article',
-          o_id: article.id,
-          data: file.read,
-          filename: file.original_filename,
-          preferences: {
-            'Mime-Type' => file.content_type,
-          }
-        )
-      end
+    params[:file]&.each do |file|
+      Store.add(
+        object: 'Ticket::Article',
+        o_id: article.id,
+        data: file.read,
+        filename: file.original_filename,
+        preferences: {
+          'Mime-Type' => file.content_type,
+        }
+      )
     end
 
     UserInfo.current_user_id = 1

+ 3 - 3
app/controllers/getting_started_controller.rb

@@ -66,7 +66,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
 
     # verify auto wizard file
     auto_wizard_data = AutoWizard.data
-    if !auto_wizard_data || auto_wizard_data.empty?
+    if auto_wizard_data.blank?
       render json: {
         auto_wizard: true,
         auto_wizard_success: false,
@@ -132,7 +132,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
     end
 
     # validate organization
-    if !params[:organization] || params[:organization].empty?
+    if params[:organization].blank?
       messages[:organization] = 'Invalid!'
     else
       settings[:organization] = params[:organization]
@@ -146,7 +146,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
       end
     end
 
-    if !messages.empty?
+    if messages.present?
       render json: {
         result: 'invalid',
         messages: messages,

Some files were not shown because too many files changed in this diff