👮 Crack down on style violations with rubocop-rspec 🚓

This commit is contained in:
Ryan Lue 2019-04-11 01:42:44 +08:00 committed by Thorsten Eckel
parent 6613b07143
commit cc33feee40
5 changed files with 477 additions and 85 deletions

View file

@ -1,9 +1,13 @@
# Default enabled cops
# https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml
require: rubocop-performance
require:
- rubocop-performance
- rubocop-rspec
inherit_from: .rubocop_todo.yml
inherit_from:
- .rubocop_todo.yml
- .rubocop_todo.rspec.yml
AllCops:
DisplayCopNames: true
@ -13,6 +17,10 @@ AllCops:
- 'bin/spring'
- 'db/schema.rb'
- 'vendor/**/*'
RSpec:
Patterns:
- '_spec.rb$'
- '_examples.rb$'
Rails:
Enabled: true

362
.rubocop_todo.rspec.yml Normal file
View file

@ -0,0 +1,362 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-04-12 17:16:30 +0800 using RuboCop version 0.67.2.
# 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: 36
# Cop supports --auto-correct.
# Configuration parameters: EnabledMethods.
Capybara/FeatureMethods:
Exclude:
- 'spec/system/basic/authentication_spec.rb'
- 'spec/system/basic/redirects_spec.rb'
- 'spec/system/basic/richtext_spec.rb'
- 'spec/system/js/q_unit_spec.rb'
- 'spec/system/setup/auto_wizard_spec.rb'
- 'spec/system/setup/mail_accounts_spec.rb'
- 'spec/system/setup/system_spec.rb'
- 'spec/system/ticket/create_spec.rb'
- 'spec/system/ticket/update_spec.rb'
# Offense count: 39
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Exclude:
- 'spec/factories/job.rb'
- 'spec/factories/postmaster_filter.rb'
- 'spec/factories/ticket.rb'
- 'spec/factories/ticket/article.rb'
- 'spec/lib/sequencer/unit/import/zendesk/sub_sequence/base_examples.rb'
- 'spec/models/calendar_spec.rb'
- 'spec/models/channel/email_parser_spec.rb'
- 'spec/models/cti/caller_id_spec.rb'
- 'spec/models/job_spec.rb'
- 'spec/models/recent_view_spec.rb'
- 'spec/models/role_spec.rb'
- 'spec/models/ticket_spec.rb'
- 'spec/models/trigger_spec.rb'
- 'spec/requests/ticket_spec.rb'
# Offense count: 43
Lint/UselessAssignment:
Enabled: false
# # Offense count: 17 (Competes with same override in .rubocop_todo.yml)
# Metrics/AbcSize:
# Max: 24
# Offense count: 664
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 1969
# Offense count: 16
RSpec/AnyInstance:
Exclude:
- 'spec/lib/import/otrs/article_spec.rb'
- 'spec/lib/import/otrs/customer_spec.rb'
- 'spec/lib/import/otrs/customer_user_spec.rb'
- 'spec/lib/import/otrs/priority_spec.rb'
- 'spec/lib/import/otrs/queue_spec.rb'
- 'spec/lib/import/otrs/state_spec.rb'
- 'spec/lib/import/otrs/ticket_spec.rb'
- 'spec/lib/import/otrs/user_spec.rb'
- 'spec/models/import_job_spec.rb'
# Offense count: 3
RSpec/BeforeAfterAll:
Exclude:
- 'spec/spec_helper.rb'
- 'spec/rails_helper.rb'
- 'spec/support/**/*.rb'
- 'spec/lib/sequencer/unit/import/zendesk/ticket/comment/attachment/request_spec.rb'
- 'spec/lib/sequencer/unit/import/zendesk/ticket/comment/source_based_spec.rb'
- 'spec/models/translation_spec.rb'
# Offense count: 523
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Enabled: false
# Offense count: 1
RSpec/DescribeClass:
Exclude:
- 'spec/scripts/websocket_server_spec.rb'
# Offense count: 207
# Cop supports --auto-correct.
# Configuration parameters: SkipBlocks, EnforcedStyle.
# SupportedStyles: described_class, explicit
RSpec/DescribedClass:
Enabled: false
# Offense count: 15
# Cop supports --auto-correct.
RSpec/EmptyLineAfterFinalLet:
Exclude:
- 'spec/db/migrate/issue_1905_exchange_login_from_remote_id_spec.rb'
- 'spec/db/migrate/issue_2541_fix_notification_email_without_body_spec.rb'
- 'spec/lib/import/zendesk/object_attribute/base_examples.rb'
- 'spec/models/cti/log_spec.rb'
- 'spec/models/object_manager/attribute/validation/future_past_spec.rb'
- 'spec/models/object_manager/attribute/validation/required_spec.rb'
- 'spec/models/ticket_spec.rb'
- 'spec/models/user_spec.rb'
- 'spec/requests/integration/twitter_webhook_spec.rb'
# Offense count: 25
# Cop supports --auto-correct.
RSpec/EmptyLineAfterHook:
Exclude:
- 'spec/lib/notification_factory/slack_spec.rb'
- 'spec/lib/notification_factory_spec.rb'
- 'spec/models/role_spec.rb'
- 'spec/models/ticket_spec.rb'
- 'spec/models/trigger_spec.rb'
- 'spec/models/user_spec.rb'
# Offense count: 34
# Cop supports --auto-correct.
RSpec/EmptyLineAfterSubject:
Enabled: false
# Offense count: 540
# Configuration parameters: Max.
RSpec/ExampleLength:
Enabled: false
# Offense count: 36
RSpec/ExpectActual:
Exclude:
- 'spec/routing/**/*'
- 'spec/requests/integration/monitoring_spec.rb'
- 'spec/requests/integration/object_manager_attributes_spec.rb'
- 'spec/requests/integration/twilio_sms_spec.rb'
- 'spec/requests/integration/user_device_spec.rb'
- 'spec/requests/organization_spec.rb'
- 'spec/requests/ticket/article_attachments_spec.rb'
- 'spec/requests/user/organization_spec.rb'
- 'spec/requests/user_spec.rb'
# Offense count: 99
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: method_call, block
RSpec/ExpectChange:
Enabled: false
# Offense count: 3
RSpec/ExpectInHook:
Exclude:
- 'spec/models/calendar_spec.rb'
- 'spec/models/concerns/has_search_index_backend_examples.rb'
- 'spec/models/ticket/article_spec.rb'
# Offense count: 12
# Configuration parameters: CustomTransform, IgnoreMethods.
RSpec/FilePath:
Exclude:
- 'spec/db/migrate/20171023000001_fixed_store_upgrade_ror_45_spec.rb'
- 'spec/db/migrate/issue_1219_zhtw_locale_typo_spec.rb'
- 'spec/db/migrate/issue_1660_fix_tree_select_configurations_spec.rb'
- 'spec/db/migrate/issue_1905_exchange_login_from_remote_id_spec.rb'
- 'spec/db/migrate/issue_1977_remove_invalid_user_foreign_keys_spec.rb'
- 'spec/db/migrate/issue_2019_fix_double_domain_links_in_trigger_emails_spec.rb'
- 'spec/db/migrate/issue_2140_reset_ldap_config_spec.rb'
- 'spec/db/migrate/issue_2333_object_country_already_exists_spec.rb'
- 'spec/db/migrate/issue_2345_es_attachment_max_size_in_mb_setting_lower_default_spec.rb'
- 'spec/db/migrate/issue_2368_add_indices_to_histories_and_tickets_spec.rb'
- 'spec/db/migrate/issue_2541_fix_notification_email_without_body_spec.rb'
- 'spec/lib/import/base_factory_spec.rb'
# Offense count: 30
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: implicit, each, example
RSpec/HookArgument:
Enabled: false
# Offense count: 4
# Cop supports --auto-correct.
RSpec/HooksBeforeExamples:
Exclude:
- 'spec/models/concerns/has_groups_examples.rb'
- 'spec/models/trigger_spec.rb'
# Offense count: 60
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Exclude:
- 'spec/lib/notification_factory/renderer_spec.rb'
- 'spec/models/import_job_spec.rb'
- 'spec/models/scheduler_spec.rb'
- 'spec/requests/api_auth_on_behalf_of_spec.rb'
- 'spec/requests/integration/monitoring_spec.rb'
- 'spec/requests/integration/sipgate_spec.rb'
- 'spec/requests/organization_spec.rb'
- 'spec/requests/report_spec.rb'
- 'spec/requests/text_module_spec.rb'
- 'spec/requests/ticket/article_attachments_spec.rb'
- 'spec/requests/user_spec.rb'
# Offense count: 2
RSpec/IteratedExpectation:
Exclude:
- 'spec/jobs/update_cti_logs_by_caller_job_spec.rb'
# Offense count: 10
# Cop supports --auto-correct.
RSpec/LeadingSubject:
Exclude:
- 'spec/lib/notification_factory/slack_spec.rb'
- 'spec/models/object_manager/attribute/validation/backend_spec.rb'
- 'spec/models/object_manager/attribute/validation/future_past_spec.rb'
- 'spec/models/object_manager/attribute/validation/required_spec.rb'
- 'spec/models/role_spec.rb'
- 'spec/models/ticket/article_spec.rb'
- 'spec/models/trigger_spec.rb'
- 'spec/models/user_spec.rb'
# Offense count: 15
# Cop supports --auto-correct.
RSpec/LetBeforeExamples:
Exclude:
- 'spec/lib/import/otrs/article/attachment_factory_spec.rb'
- 'spec/lib/import/otrs/dynamic_field_factory_spec.rb'
- 'spec/lib/import/otrs/dynamic_field_spec.rb'
- 'spec/lib/ldap/group_spec.rb'
- 'spec/lib/ldap/user_spec.rb'
- 'spec/lib/ldap_spec.rb'
- 'spec/models/user_spec.rb'
# Offense count: 34
RSpec/LetSetup:
Enabled: false
# Offense count: 242
# Configuration parameters: EnforcedStyle.
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
Enabled: false
# Offense count: 478
# Configuration parameters: AggregateFailuresByDefault.
RSpec/MultipleExpectations:
Max: 266
# Offense count: 83
# Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject:
Exclude:
- 'spec/db/migrate/issue_2019_fix_double_domain_links_in_trigger_emails_spec.rb'
- 'spec/db/migrate/issue_2541_fix_notification_email_without_body_spec.rb'
- 'spec/lib/core_ext/string_spec.rb'
- 'spec/lib/import/exchange/folder_spec.rb'
- 'spec/lib/ldap/user_spec.rb'
- 'spec/lib/sequencer/unit/import/ldap/user/attributes/role_ids/unassigned_spec.rb'
- 'spec/lib/sessions/backend/activity_stream_spec.rb'
- 'spec/lib/upload_cache_spec.rb'
- 'spec/models/channel/filter/match/email_regex_spec.rb'
- 'spec/models/http_log_spec.rb'
- 'spec/models/object_manager/attribute/validation/backend_spec.rb'
- 'spec/models/object_manager/attribute/validation/future_past_spec.rb'
- 'spec/models/object_manager/attribute/validation/required_spec.rb'
- 'spec/models/object_manager/attribute/validation_spec.rb'
- 'spec/models/object_manager/attribute_spec.rb'
# Offense count: 545
RSpec/NestedGroups:
Max: 7
# Offense count: 28
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: not_to, to_not
RSpec/NotToNot:
Exclude:
- 'spec/db/migrate/object_manager_attribute_date_remove_future_past_spec.rb'
- 'spec/lib/import/otrs/user_factory_spec.rb'
- 'spec/lib/migration_job/ldap_samaccountname_to_uid_spec.rb'
- 'spec/lib/report/ticket_generic_time_spec.rb'
- 'spec/lib/stats_spec.rb'
- 'spec/models/object_manager/attribute/validation_spec.rb'
- 'spec/models/object_manager/attribute_spec.rb'
- 'spec/requests/integration/idoit_spec.rb'
- 'spec/requests/integration/twilio_sms_spec.rb'
- 'spec/requests/integration/user_device_spec.rb'
- 'spec/requests/search_spec.rb'
- 'spec/requests/text_module_spec.rb'
- 'spec/requests/ticket/article_spec.rb'
# Offense count: 81
# Cop supports --auto-correct.
# Configuration parameters: Strict, EnforcedStyle.
# SupportedStyles: inflected, explicit
RSpec/PredicateMatcher:
Exclude:
- 'spec/lib/password_hash_spec.rb'
- 'spec/models/trigger/sms_spec.rb'
- 'spec/requests/api_auth_on_behalf_of_spec.rb'
- 'spec/requests/api_auth_spec.rb'
- 'spec/requests/integration/monitoring_spec.rb'
- 'spec/requests/organization_spec.rb'
- 'spec/requests/user_spec.rb'
# Offense count: 12
RSpec/RepeatedDescription:
Exclude:
- 'spec/models/translation_spec.rb'
- 'spec/requests/form_spec.rb'
- 'spec/requests/ticket_spec.rb'
# Offense count: 2
RSpec/RepeatedExample:
Exclude:
- 'spec/models/translation_spec.rb'
# Offense count: 3
RSpec/ScatteredLet:
Exclude:
- 'spec/models/job_spec.rb'
- 'spec/models/ticket_spec.rb'
- 'spec/requests/integration/twitter_webhook_spec.rb'
# Offense count: 11
RSpec/ScatteredSetup:
Exclude:
- 'spec/models/ticket_spec.rb'
- 'spec/models/user_spec.rb'
- 'spec/requests/upload_cache_spec.rb'
# Offense count: 8
RSpec/SubjectStub:
Exclude:
- 'spec/models/concerns/has_groups_examples.rb'
- 'spec/models/concerns/has_roles_examples.rb'
- 'spec/models/job_spec.rb'
- 'spec/models/object_manager/attribute/validation/future_past_spec.rb'
- 'spec/models/object_manager/attribute/validation/required_spec.rb'
# Offense count: 25
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Enabled: false
# Offense count: 2
RSpec/VoidExpect:
Exclude:
- 'spec/lib/ldap/group_spec.rb'
- 'spec/lib/ldap/user_spec.rb'
# Offense count: 741
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: numeric, symbolic
Rails/HttpStatus:
Enabled: false

View file

@ -1,88 +1,106 @@
# 10.0
Metrics/PerceivedComplexity:
Description: >-
A complexity metric geared towards measuring complexity for a
human reader.
Enabled: false
Metrics/AbcSize:
Description: >-
A calculated magnitude based on number of assignments,
branches, and conditions.
Enabled: false
Metrics/CyclomaticComplexity:
Description: >-
A complexity metric that is strongly correlated to the number
of test cases needed to validate a method.
Enabled: false
Metrics/BlockNesting:
Description: 'Avoid excessive block nesting'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count'
Enabled: false
Metrics/ModuleLength:
Description: 'Avoid modules longer than 100 lines of code.'
Enabled: false
Metrics/BlockLength:
Enabled: false
Style/RescueStandardError:
Description: 'Avoid rescuing without specifying an error class.'
Enabled: false
# TODO
Rails/ApplicationRecord:
Description: 'Check that models subclass ApplicationRecord.'
Enabled: false
# Browser-Tests inherit from TestCase < Test::Unit::TestCase
# which does not provide assert_not
Rails/AssertNot:
Description: 'Use `assert_not` instead of `assert !`.'
Enabled: true
Exclude:
- "test/browser/*"
Rails/CreateTableWithTimestamps:
Description: >-
Checks the migration for which timestamps are not included
when creating a new table.
Enabled: false
Rails/HasManyOrHasOneDependent:
Description: 'Define the dependent option to the has_many and has_one associations.'
StyleGuide: 'https://github.com/bbatsov/rails-style-guide#has_many-has_one-dependent-option'
Enabled: false
Style/DateTime:
Description: 'Use Date or Time over DateTime.'
StyleGuide: '#date--time'
Enabled: false
Style/Documentation:
Description: 'Document classes and non-namespace modules.'
Enabled: false
Lint/UselessAssignment:
Enabled: false
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-04-12 18:08:21 +0800 using RuboCop version 0.67.2.
# 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: 97
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Description: 'Do not use unnecessary spacing.'
Enabled: false
# Broken!!!! Generates broken code since "String".downcase == "strinG".downcase is not equals "String".casecmp("strinG") but "String".casecmp("strinG") == 0 !!!
Performance/Casecmp:
Description: 'Use `casecmp` rather than `downcase ==`.'
Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringcasecmp-vs-stringdowncase---code'
Enabled: false
# Can be removed after introduction of Sequencer for OTRS migration
# Offense count: 8
# Configuration parameters: MaximumRangeSize.
Lint/MissingCopEnableDirective:
Enabled: true
Exclude:
- "lib/import/**/*"
- 'lib/import/factory.rb'
- 'lib/import/helper.rb'
- 'lib/import/otrs/async.rb'
- 'lib/import/otrs/history.rb'
- 'lib/import/otrs/priority_factory.rb'
- 'lib/import/otrs/state_factory.rb'
- 'lib/import/otrs/user_factory.rb'
- 'lib/import/transaction_factory.rb'
# Offense count: 469
Metrics/AbcSize:
Max: 637
# Offense count: 28
# Configuration parameters: CountBlocks.
Metrics/BlockNesting:
Max: 5
# Offense count: 336
Metrics/CyclomaticComplexity:
Max: 97
# Offense count: 23
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 559
# Offense count: 272
Metrics/PerceivedComplexity:
Max: 115
# Offense count: 3
# Cop supports --auto-correct.
Performance/Casecmp:
Exclude:
- 'app/models/channel/email_parser.rb'
- 'app/models/channel/filter/database.rb'
- 'lib/tasks/zammad/setup/db_config.rake'
# Offense count: 3
# Cop supports --auto-correct.
Rails/ApplicationRecord:
Exclude:
- 'app/models/application_model.rb'
- 'app/models/notification.rb'
- 'app/models/token.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: Include.
# Include: **/test/**/*
Rails/AssertNot:
Exclude:
- 'test/browser/admin_permissions_granular_vs_full_test.rb'
# Offense count: 13
# Configuration parameters: Include.
# Include: db/migrate/*.rb
Rails/CreateTableWithTimestamps:
Exclude:
- 'db/migrate/20120101000001_create_base.rb'
- 'db/migrate/20120101000010_create_ticket.rb'
- 'db/migrate/20170419000002_overview_role_ids.rb'
- 'db/migrate/20170608151442_enhanced_permissions.rb'
# Offense count: 8
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/HasManyOrHasOneDependent:
Exclude:
- 'app/models/chat/session.rb'
- 'app/models/concerns/has_groups.rb'
- 'app/models/email_address.rb'
- 'app/models/organization.rb'
- 'app/models/signature.rb'
- 'app/models/ticket/state_type.rb'
- 'app/models/user.rb'
# Offense count: 759
Style/Documentation:
Enabled: false
# Offense count: 170
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: implicit, explicit
Style/RescueStandardError:
Enabled: false

View file

@ -165,6 +165,7 @@ group :development, :test do
gem 'pre-commit'
gem 'rubocop'
gem 'rubocop-performance'
gem 'rubocop-rspec'
# changelog generation
gem 'github_changelog_generator'

View file

@ -426,6 +426,8 @@ GEM
unicode-display_width (>= 1.4.0, < 1.6)
rubocop-performance (1.0.0)
rubocop (>= 0.58.0)
rubocop-rspec (1.32.0)
rubocop (>= 0.60.0)
ruby-progressbar (1.10.0)
ruby_dep (1.5.0)
rubyzip (1.2.2)
@ -595,6 +597,7 @@ DEPENDENCIES
rszr (= 0.4.0)
rubocop
rubocop-performance
rubocop-rspec
rubyntlm!
sassc-rails
selenium-webdriver
@ -625,4 +628,4 @@ RUBY VERSION
ruby 2.4.4p296
BUNDLED WITH
1.16.2
1.17.3