Use gitlab-styles
Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
299e04e318
commit
a2d39b8010
70 changed files with 765 additions and 2539 deletions
|
@ -16,6 +16,7 @@ engines:
|
|||
enabled: true
|
||||
rubocop:
|
||||
enabled: true
|
||||
channel: "gitlab-rubocop-0-52"
|
||||
ratings:
|
||||
paths:
|
||||
- Gemfile.lock
|
||||
|
|
|
@ -594,7 +594,7 @@ codequality:
|
|||
script:
|
||||
- cp .rubocop.yml .rubocop.yml.bak
|
||||
- grep -v "rubocop-gitlab-security" .rubocop.yml.bak > .rubocop.yml
|
||||
- docker run --env CODECLIMATE_CODE="$PWD" --volume "$PWD":/code --volume /var/run/docker.sock:/var/run/docker.sock --volume /tmp/cc:/tmp/cc codeclimate/codeclimate analyze -f json > raw_codeclimate.json
|
||||
- docker run --env CODECLIMATE_CODE="$PWD" --volume "$PWD":/code --volume /var/run/docker.sock:/var/run/docker.sock --volume /tmp/cc:/tmp/cc dev.gitlab.org:5005/gitlab/gitlab-build-images:gitlab-codeclimate-v2 analyze -f json > raw_codeclimate.json
|
||||
- cat raw_codeclimate.json | docker run -i stedolan/jq -c 'map({check_name,fingerprint,location})' > codeclimate.json
|
||||
- mv .rubocop.yml.bak .rubocop.yml
|
||||
artifacts:
|
||||
|
|
1216
.rubocop.yml
1216
.rubocop.yml
File diff suppressed because it is too large
Load diff
|
@ -1,53 +1,111 @@
|
|||
# This configuration was generated by
|
||||
# `rubocop --auto-gen-config --exclude-limit 0`
|
||||
# on 2017-07-10 01:48:30 +0900 using RuboCop version 0.49.1.
|
||||
# `rubocop --auto-gen-config`
|
||||
# on 2017-12-14 12:04:26 +0100 using RuboCop version 0.52.0.
|
||||
# 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: 181
|
||||
# Offense count: 174
|
||||
Capybara/CurrentPathExpectation:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 951
|
||||
Capybara/FeatureMethods:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 24
|
||||
FactoryBot/DynamicAttributeDefinedStatically:
|
||||
Exclude:
|
||||
- 'spec/factories/broadcast_messages.rb'
|
||||
- 'spec/factories/ci/builds.rb'
|
||||
- 'spec/factories/ci/runners.rb'
|
||||
- 'spec/factories/clusters/applications/helm.rb'
|
||||
- 'spec/factories/clusters/applications/ingress.rb'
|
||||
- 'spec/factories/clusters/platforms/kubernetes.rb'
|
||||
- 'spec/factories/emails.rb'
|
||||
- 'spec/factories/gpg_keys.rb'
|
||||
- 'spec/factories/group_members.rb'
|
||||
- 'spec/factories/merge_requests.rb'
|
||||
- 'spec/factories/notes.rb'
|
||||
- 'spec/factories/oauth_access_grants.rb'
|
||||
- 'spec/factories/project_members.rb'
|
||||
- 'spec/factories/todos.rb'
|
||||
- 'spec/factories/uploads.rb'
|
||||
|
||||
# Offense count: 65
|
||||
# Cop supports --auto-correct.
|
||||
Layout/EmptyLinesAroundArguments:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 249
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
|
||||
Layout/ExtraSpacing:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 119
|
||||
# Offense count: 82
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
|
||||
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
||||
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
|
||||
Layout/IndentArray:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 208
|
||||
# Offense count: 239
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
|
||||
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
||||
# SupportedStyles: special_inside_parentheses, consistent, align_braces
|
||||
Layout/IndentHash:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 8
|
||||
# Offense count: 15
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: .
|
||||
# SupportedStyles: space, no_space
|
||||
# SupportedStylesForEmptyBraces: space, no_space
|
||||
Layout/SpaceBeforeBlockBraces:
|
||||
EnforcedStyle: space
|
||||
EnforcedStyleForEmptyBraces: space
|
||||
|
||||
# Offense count: 11
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowForAlignment.
|
||||
Layout/SpaceBeforeFirstArg:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'config/routes/project.rb'
|
||||
- 'db/migrate/20170506185517_add_foreign_key_pipeline_schedules_and_pipelines.rb'
|
||||
- 'features/steps/project/source/browse_files.rb'
|
||||
- 'features/steps/project/source/markdown_render.rb'
|
||||
- 'lib/api/runners.rb'
|
||||
- 'spec/features/search/user_uses_search_filters_spec.rb'
|
||||
- 'spec/routing/project_routing_spec.rb'
|
||||
- 'spec/services/system_note_service_spec.rb'
|
||||
|
||||
# Offense count: 64
|
||||
# Offense count: 93
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: require_no_space, require_space
|
||||
Layout/SpaceInLambdaLiteral:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 256
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters.
|
||||
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
|
||||
# SupportedStyles: space, no_space, compact
|
||||
# SupportedStylesForEmptyBrackets: space, no_space
|
||||
Layout/SpaceInsideArrayLiteralBrackets:
|
||||
Exclude:
|
||||
- 'spec/lib/gitlab/import_export/relation_factory_spec.rb'
|
||||
|
||||
# Offense count: 323
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
||||
# SupportedStyles: space, no_space
|
||||
# SupportedStylesForEmptyBraces: space, no_space
|
||||
Layout/SpaceInsideBlockBraces:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 135
|
||||
# Offense count: 146
|
||||
# Cop supports --auto-correct.
|
||||
Layout/SpaceInsideParens:
|
||||
Enabled: false
|
||||
|
@ -55,178 +113,535 @@ Layout/SpaceInsideParens:
|
|||
# Offense count: 14
|
||||
# Cop supports --auto-correct.
|
||||
Layout/SpaceInsidePercentLiteralDelimiters:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/gitlab/git_access.rb'
|
||||
- 'lib/gitlab/health_checks/fs_shards_check.rb'
|
||||
- 'spec/lib/gitlab/health_checks/fs_shards_check_spec.rb'
|
||||
|
||||
# Offense count: 272
|
||||
RSpec/EmptyLineAfterFinalLet:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 181
|
||||
RSpec/EmptyLineAfterSubject:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 9
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
# SupportedStyles: it_behaves_like, it_should_behave_like
|
||||
RSpec/ItBehavesLike:
|
||||
Enabled: false
|
||||
# Offense count: 25
|
||||
Lint/DuplicateMethods:
|
||||
Exclude:
|
||||
- 'app/models/application_setting.rb'
|
||||
- 'app/models/commit.rb'
|
||||
- 'app/models/note.rb'
|
||||
- 'app/services/merge_requests/merge_service.rb'
|
||||
- 'lib/bitbucket/representation/repo.rb'
|
||||
- 'lib/declarative_policy/base.rb'
|
||||
- 'lib/gitlab/ci/build/artifacts/metadata/entry.rb'
|
||||
- 'lib/gitlab/cycle_analytics/base_event_fetcher.rb'
|
||||
- 'lib/gitlab/diff/formatters/base_formatter.rb'
|
||||
- 'lib/gitlab/git/blob.rb'
|
||||
- 'lib/gitlab/git/repository.rb'
|
||||
- 'lib/gitlab/git/tree.rb'
|
||||
- 'lib/gitlab/git/wiki_page.rb'
|
||||
- 'lib/gitlab/ldap/person.rb'
|
||||
- 'lib/gitlab/o_auth/user.rb'
|
||||
|
||||
# Offense count: 4
|
||||
RSpec/IteratedExpectation:
|
||||
Lint/InterpolationCheck:
|
||||
Exclude:
|
||||
- 'spec/features/issues/filtered_search/filter_issues_spec.rb'
|
||||
- 'spec/features/users_spec.rb'
|
||||
- 'spec/services/quick_actions/interpret_service_spec.rb'
|
||||
|
||||
# Offense count: 198
|
||||
# Configuration parameters: MaximumRangeSize.
|
||||
Lint/MissingCopEnableDirective:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
RSpec/OverwritingSetup:
|
||||
Lint/NestedPercentLiteral:
|
||||
Exclude:
|
||||
- 'lib/gitlab/git/repository.rb'
|
||||
- 'spec/support/email_format_shared_examples.rb'
|
||||
|
||||
# Offense count: 1
|
||||
Lint/ReturnInVoidContext:
|
||||
Exclude:
|
||||
- 'app/models/project.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Configuration parameters: IgnoreImplicitReferences.
|
||||
Lint/ShadowedArgument:
|
||||
Exclude:
|
||||
- 'lib/gitlab/database/sha_attribute.rb'
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
Lint/UnneededRequireStatement:
|
||||
Exclude:
|
||||
- 'db/post_migrate/20161221153951_rename_reserved_project_names.rb'
|
||||
- 'db/post_migrate/20170313133418_rename_more_reserved_project_names.rb'
|
||||
- 'lib/declarative_policy.rb'
|
||||
|
||||
# Offense count: 9
|
||||
Lint/UriEscapeUnescape:
|
||||
Exclude:
|
||||
- 'app/controllers/application_controller.rb'
|
||||
- 'app/models/project_services/drone_ci_service.rb'
|
||||
- 'spec/lib/google_api/auth_spec.rb'
|
||||
- 'spec/requests/api/files_spec.rb'
|
||||
- 'spec/requests/api/internal_spec.rb'
|
||||
- 'spec/requests/api/issues_spec.rb'
|
||||
- 'spec/requests/api/v3/issues_spec.rb'
|
||||
|
||||
# Offense count: 2
|
||||
Naming/ConstantName:
|
||||
Exclude:
|
||||
- 'lib/gitlab/import_sources.rb'
|
||||
- 'lib/gitlab/ssh_public_key.rb'
|
||||
|
||||
# Offense count: 11
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: lowercase, uppercase
|
||||
Naming/HeredocDelimiterCase:
|
||||
Exclude:
|
||||
- 'spec/lib/gitlab/diff/parser_spec.rb'
|
||||
- 'spec/lib/json_web_token/rsa_token_spec.rb'
|
||||
- 'spec/models/commit_spec.rb'
|
||||
- 'spec/support/repo_helpers.rb'
|
||||
- 'spec/support/seed_repo.rb'
|
||||
|
||||
# Offense count: 101
|
||||
# Configuration parameters: Blacklist.
|
||||
# Blacklist: END, (?-mix:EO[A-Z]{1})
|
||||
Naming/HeredocDelimiterNaming:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 36
|
||||
RSpec/RepeatedExample:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 86
|
||||
RSpec/ScatteredLet:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 20
|
||||
RSpec/ScatteredSetup:
|
||||
# Offense count: 28
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AutoCorrect.
|
||||
Performance/HashEachMethods:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1
|
||||
RSpec/SharedContext:
|
||||
Performance/UnfreezeString:
|
||||
Exclude:
|
||||
- 'features/steps/project/commits/commits.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Performance/UriDefaultParser:
|
||||
Exclude:
|
||||
- 'lib/gitlab/url_sanitizer.rb'
|
||||
|
||||
# Offense count: 3745
|
||||
# Configuration parameters: Prefixes.
|
||||
# Prefixes: when, with, without
|
||||
RSpec/ContextWording:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 115
|
||||
# Offense count: 291
|
||||
RSpec/EmptyLineAfterFinalLet:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 180
|
||||
RSpec/EmptyLineAfterSubject:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 220
|
||||
RSpec/ExpectInHook:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 7
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: implicit, each, example
|
||||
RSpec/HookArgument:
|
||||
Exclude:
|
||||
- 'spec/spec_helper.rb'
|
||||
- 'spec/support/carrierwave.rb'
|
||||
- 'spec/support/db_cleaner.rb'
|
||||
- 'spec/support/gitaly.rb'
|
||||
- 'spec/support/setup_builds_storage.rb'
|
||||
|
||||
# Offense count: 19
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: it_behaves_like, it_should_behave_like
|
||||
RSpec/ItBehavesLike:
|
||||
Exclude:
|
||||
- 'spec/lib/gitlab/git/commit_spec.rb'
|
||||
- 'spec/lib/gitlab/git/repository_spec.rb'
|
||||
- 'spec/lib/gitlab/shell_spec.rb'
|
||||
- 'spec/services/notification_service_spec.rb'
|
||||
- 'spec/workers/git_garbage_collect_worker_spec.rb'
|
||||
|
||||
# Offense count: 5
|
||||
RSpec/IteratedExpectation:
|
||||
Exclude:
|
||||
- 'spec/features/admin/admin_settings_spec.rb'
|
||||
- 'spec/features/merge_requests/diff_notes_resolve_spec.rb'
|
||||
- 'spec/features/projects/awards/user_interacts_with_awards_in_issue_spec.rb'
|
||||
- 'spec/lib/gitlab/gitlab_import/client_spec.rb'
|
||||
- 'spec/lib/gitlab/legacy_github_import/client_spec.rb'
|
||||
|
||||
# Offense count: 75
|
||||
RSpec/LetBeforeExamples:
|
||||
Exclude:
|
||||
- 'spec/controllers/projects/commit_controller_spec.rb'
|
||||
- 'spec/lib/banzai/filter/issue_reference_filter_spec.rb'
|
||||
- 'spec/lib/banzai/filter/user_reference_filter_spec.rb'
|
||||
- 'spec/lib/gitlab/email/handler/create_issue_handler_spec.rb'
|
||||
- 'spec/lib/gitlab/email/handler/create_merge_request_handler_spec.rb'
|
||||
- 'spec/lib/gitlab/email/handler/create_note_handler_spec.rb'
|
||||
- 'spec/models/commit_range_spec.rb'
|
||||
- 'spec/models/milestone_spec.rb'
|
||||
- 'spec/models/project_services/packagist_service_spec.rb'
|
||||
- 'spec/models/repository_spec.rb'
|
||||
- 'spec/rubocop/cop/migration/update_column_in_batches_spec.rb'
|
||||
- 'spec/serializers/pipeline_details_entity_spec.rb'
|
||||
- 'spec/views/ci/lints/show.html.haml_spec.rb'
|
||||
|
||||
# Offense count: 1
|
||||
RSpec/MultipleSubjects:
|
||||
Exclude:
|
||||
- 'spec/services/merge_requests/create_from_issue_service_spec.rb'
|
||||
|
||||
# Offense count: 4
|
||||
RSpec/OverwritingSetup:
|
||||
Exclude:
|
||||
- 'spec/lib/gitlab/background_migration/migrate_events_to_push_event_payloads_spec.rb'
|
||||
- 'spec/models/email_spec.rb'
|
||||
- 'spec/services/merge_requests/add_todo_when_build_fails_service_spec.rb'
|
||||
- 'spec/services/notes/quick_actions_service_spec.rb'
|
||||
|
||||
# Offense count: 917
|
||||
# Configuration parameters: Strict, EnforcedStyle.
|
||||
# SupportedStyles: inflected, explicit
|
||||
RSpec/PredicateMatcher:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 35
|
||||
RSpec/RepeatedExample:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 132
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: and_return, block
|
||||
RSpec/ReturnFromStub:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 105
|
||||
RSpec/ScatteredLet:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 22
|
||||
RSpec/ScatteredSetup:
|
||||
Exclude:
|
||||
- 'spec/controllers/projects/templates_controller_spec.rb'
|
||||
- 'spec/lib/gitlab/bitbucket_import/importer_spec.rb'
|
||||
- 'spec/lib/gitlab/git/env_spec.rb'
|
||||
- 'spec/requests/api/jobs_spec.rb'
|
||||
- 'spec/requests/api/v3/builds_spec.rb'
|
||||
- 'spec/requests/api/v3/projects_spec.rb'
|
||||
- 'spec/services/projects/create_service_spec.rb'
|
||||
|
||||
# Offense count: 1
|
||||
RSpec/SharedContext:
|
||||
Exclude:
|
||||
- 'spec/features/admin/admin_groups_spec.rb'
|
||||
|
||||
# Offense count: 90
|
||||
RSpec/SingleLineHook:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 5
|
||||
RSpec/VoidExpect:
|
||||
Exclude:
|
||||
- 'spec/features/projects/artifacts/download_spec.rb'
|
||||
- 'spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb'
|
||||
- 'spec/models/ci/group_spec.rb'
|
||||
- 'spec/models/ci/runner_spec.rb'
|
||||
- 'spec/services/users/destroy_service_spec.rb'
|
||||
|
||||
# Offense count: 40
|
||||
# Configuration parameters: Include.
|
||||
# Include: db/migrate/*.rb
|
||||
Rails/CreateTableWithTimestamps:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 149
|
||||
Rails/FilePath:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 119
|
||||
# Configuration parameters: Include.
|
||||
# Include: app/models/**/*.rb
|
||||
Rails/HasManyOrHasOneDependent:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 113
|
||||
# Configuration parameters: Include.
|
||||
# Include: app/models/**/*.rb
|
||||
Rails/InverseOf:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 48
|
||||
# Configuration parameters: Include.
|
||||
# Include: app/controllers/**/*.rb
|
||||
Rails/LexicallyScopedActionFilter:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 14
|
||||
# Cop supports --auto-correct.
|
||||
Rails/Presence:
|
||||
Exclude:
|
||||
- 'app/controllers/projects/blob_controller.rb'
|
||||
- 'app/models/ci/pipeline.rb'
|
||||
- 'app/models/clusters/platforms/kubernetes.rb'
|
||||
- 'app/models/concerns/mentionable.rb'
|
||||
- 'app/models/concerns/token_authenticatable.rb'
|
||||
- 'app/models/project_services/hipchat_service.rb'
|
||||
- 'app/models/project_services/irker_service.rb'
|
||||
- 'app/models/project_services/jira_service.rb'
|
||||
- 'app/models/project_services/kubernetes_service.rb'
|
||||
- 'app/models/project_services/packagist_service.rb'
|
||||
- 'app/models/wiki_page.rb'
|
||||
- 'lib/gitlab/git/hook.rb'
|
||||
- 'lib/gitlab/github_import/importer/releases_importer.rb'
|
||||
|
||||
# Offense count: 14
|
||||
# Cop supports --auto-correct.
|
||||
Rails/RedundantReceiverInWithOptions:
|
||||
Exclude:
|
||||
- 'config/initializers/doorkeeper_openid_connect.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Configuration parameters: Include.
|
||||
# Include: db/migrate/*.rb
|
||||
Rails/ReversibleMigration:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'db/migrate/20160824103857_drop_unused_ci_tables.rb'
|
||||
|
||||
# Offense count: 336
|
||||
# Offense count: 430
|
||||
# Configuration parameters: Blacklist.
|
||||
# Blacklist: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters
|
||||
Rails/SkipsModelValidations:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 11
|
||||
# Offense count: 1
|
||||
# Configuration parameters: Environments.
|
||||
# Environments: development, test, production
|
||||
Rails/UnknownEnv:
|
||||
Exclude:
|
||||
- 'db/migrate/20171124125748_populate_missing_merge_request_statuses.rb'
|
||||
|
||||
# Offense count: 13
|
||||
# Cop supports --auto-correct.
|
||||
Security/YAMLLoad:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'config/initializers/carrierwave.rb'
|
||||
- 'lib/gitlab/background_migration/deserialize_merge_request_diffs_and_commits.rb'
|
||||
- 'lib/gitlab/redis/wrapper.rb'
|
||||
- 'lib/system_check/incoming_email/imap_authentication_check.rb'
|
||||
- 'spec/config/mail_room_spec.rb'
|
||||
- 'spec/initializers/secret_token_spec.rb'
|
||||
- 'spec/lib/gitlab/prometheus/additional_metrics_parser_spec.rb'
|
||||
- 'spec/models/clusters/platforms/kubernetes_spec.rb'
|
||||
- 'spec/models/project_services/kubernetes_service_spec.rb'
|
||||
|
||||
# Offense count: 58
|
||||
# Offense count: 63
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: percent_q, bare_percent
|
||||
Style/BarePercentLiterals:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 6
|
||||
# Cop supports --auto-correct.
|
||||
Style/EachWithObject:
|
||||
# Offense count: 5
|
||||
Style/CommentedKeyword:
|
||||
Exclude:
|
||||
- 'lib/tasks/gitlab/backup.rake'
|
||||
- 'spec/tasks/gitlab/backup_rake_spec.rb'
|
||||
|
||||
# Offense count: 30
|
||||
Style/DateTime:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 31
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/Dir:
|
||||
Exclude:
|
||||
- 'qa/qa.rb'
|
||||
|
||||
# Offense count: 9
|
||||
# Cop supports --auto-correct.
|
||||
Style/EachWithObject:
|
||||
Exclude:
|
||||
- 'config/initializers/gollum.rb'
|
||||
- 'lib/expand_variables.rb'
|
||||
- 'lib/gitlab/ci/ansi2html.rb'
|
||||
- 'lib/gitlab/ee_compat_check.rb'
|
||||
- 'lib/gitlab/hook_data/issuable_builder.rb'
|
||||
- 'lib/gitlab/i18n/po_linter.rb'
|
||||
- 'lib/gitlab/import_export/members_mapper.rb'
|
||||
- 'lib/gitlab/import_export/relation_factory.rb'
|
||||
- 'scripts/static-analysis'
|
||||
|
||||
# Offense count: 24
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: empty, nil, both
|
||||
Style/EmptyElse:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 9
|
||||
# Offense count: 14
|
||||
# Cop supports --auto-correct.
|
||||
Style/EmptyLambdaParameter:
|
||||
Exclude:
|
||||
- 'app/models/ci/build.rb'
|
||||
- 'app/models/ci/runner.rb'
|
||||
|
||||
# Offense count: 12
|
||||
# Cop supports --auto-correct.
|
||||
Style/EmptyLiteral:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'features/steps/project/commits/commits.rb'
|
||||
- 'lib/gitlab/fogbugz_import/importer.rb'
|
||||
- 'lib/gitlab/git/diff_collection.rb'
|
||||
- 'lib/gitlab/gitaly_client.rb'
|
||||
- 'scripts/trigger-build-omnibus'
|
||||
- 'spec/features/merge_requests/versions_spec.rb'
|
||||
- 'spec/helpers/merge_requests_helper_spec.rb'
|
||||
- 'spec/lib/gitlab/request_context_spec.rb'
|
||||
- 'spec/lib/gitlab/workhorse_spec.rb'
|
||||
- 'spec/requests/api/jobs_spec.rb'
|
||||
- 'spec/support/chat_slash_commands_shared_examples.rb'
|
||||
|
||||
# Offense count: 78
|
||||
# Offense count: 98
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: compact, expanded
|
||||
Style/EmptyMethod:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 23
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/Encoding:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
Style/EvalWithLocation:
|
||||
Exclude:
|
||||
- 'app/models/service.rb'
|
||||
|
||||
# Offense count: 52
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: Autocorrect, EnforcedStyle.
|
||||
# SupportedStyles: module_function, extend_self
|
||||
Style/ExtendSelf:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 34
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: format, sprintf, percent
|
||||
Style/FormatString:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 301
|
||||
# Offense count: 371
|
||||
# Configuration parameters: MinBodyLength.
|
||||
Style/GuardClause:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 18
|
||||
# Offense count: 21
|
||||
Style/IfInsideElse:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 182
|
||||
# Offense count: 781
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: MaxLineLength.
|
||||
Style/IfUnlessModifier:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 52
|
||||
# Offense count: 71
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: line_count_dependent, lambda, literal
|
||||
Style/Lambda:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 6
|
||||
# Offense count: 11
|
||||
# Cop supports --auto-correct.
|
||||
Style/LineEndConcatenation:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'app/helpers/tree_helper.rb'
|
||||
- 'spec/features/issuables/markdown_references_spec.rb'
|
||||
- 'spec/lib/gitlab/checks/project_moved_spec.rb'
|
||||
- 'spec/lib/gitlab/gfm/reference_rewriter_spec.rb'
|
||||
- 'spec/lib/gitlab/incoming_email_spec.rb'
|
||||
|
||||
# Offense count: 40
|
||||
# Offense count: 39
|
||||
# Cop supports --auto-correct.
|
||||
Style/MethodCallWithoutArgsParentheses:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 13
|
||||
# Offense count: 17
|
||||
Style/MethodMissing:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 7
|
||||
Style/MixinUsage:
|
||||
Exclude:
|
||||
- 'features/support/env.rb'
|
||||
- 'spec/factories/ci/builds.rb'
|
||||
- 'spec/factories/ci/job_artifacts.rb'
|
||||
- 'spec/factories/lfs_objects.rb'
|
||||
- 'spec/factories/notes.rb'
|
||||
- 'spec/lib/gitlab/import_export/project_tree_restorer_spec.rb'
|
||||
- 'spec/lib/gitlab/import_export/version_checker_spec.rb'
|
||||
|
||||
# Offense count: 6
|
||||
# Cop supports --auto-correct.
|
||||
Style/MultilineIfModifier:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'app/helpers/snippets_helper.rb'
|
||||
- 'app/models/project_wiki.rb'
|
||||
- 'app/services/ci/process_pipeline_service.rb'
|
||||
- 'app/services/create_deployment_service.rb'
|
||||
- 'lib/api/commit_statuses.rb'
|
||||
- 'lib/gitlab/ci/trace.rb'
|
||||
|
||||
# Offense count: 26
|
||||
# Offense count: 23
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: Whitelist.
|
||||
# Whitelist: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with
|
||||
Style/NestedParenthesizedCalls:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 20
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
|
||||
# Configuration parameters: EnforcedStyle, MinBodyLength.
|
||||
# SupportedStyles: skip_modifier_ifs, always
|
||||
Style/Next:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 45
|
||||
# Offense count: 58
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedOctalStyle, SupportedOctalStyles.
|
||||
# Configuration parameters: EnforcedOctalStyle.
|
||||
# SupportedOctalStyles: zero_with_o, zero_only
|
||||
Style/NumericLiteralPrefix:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 98
|
||||
# Offense count: 112
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AutoCorrect, EnforcedStyle, SupportedStyles.
|
||||
# Configuration parameters: AutoCorrect, EnforcedStyle.
|
||||
# SupportedStyles: predicate, comparison
|
||||
Style/NumericPredicate:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 42
|
||||
# Offense count: 4
|
||||
# Cop supports --auto-correct.
|
||||
Style/OrAssignment:
|
||||
Exclude:
|
||||
- 'app/models/concerns/token_authenticatable.rb'
|
||||
- 'lib/api/commit_statuses.rb'
|
||||
- 'lib/api/v3/members.rb'
|
||||
- 'lib/gitlab/project_transfer.rb'
|
||||
|
||||
# Offense count: 50
|
||||
# Cop supports --auto-correct.
|
||||
Style/ParallelAssignment:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 800
|
||||
# Offense count: 891
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: PreferredDelimiters.
|
||||
Style/PercentLiteralDelimiters:
|
||||
|
@ -235,106 +650,194 @@ Style/PercentLiteralDelimiters:
|
|||
# Offense count: 15
|
||||
# Cop supports --auto-correct.
|
||||
Style/PerlBackrefs:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'app/controllers/projects/application_controller.rb'
|
||||
- 'app/helpers/submodule_helper.rb'
|
||||
- 'lib/backup/manager.rb'
|
||||
- 'lib/banzai/filter/abstract_reference_filter.rb'
|
||||
- 'lib/banzai/filter/autolink_filter.rb'
|
||||
- 'lib/banzai/filter/emoji_filter.rb'
|
||||
- 'lib/banzai/filter/gollum_tags_filter.rb'
|
||||
- 'lib/expand_variables.rb'
|
||||
- 'lib/gitlab/diff/highlight.rb'
|
||||
- 'lib/gitlab/search_results.rb'
|
||||
- 'lib/gitlab/sherlock/query.rb'
|
||||
|
||||
# Offense count: 58
|
||||
# Offense count: 82
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: compact, exploded
|
||||
Style/RaiseArgs:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 6
|
||||
# Offense count: 8
|
||||
# Cop supports --auto-correct.
|
||||
Style/RedundantBegin:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'app/controllers/projects/clusters/gcp_controller.rb'
|
||||
- 'app/models/merge_request.rb'
|
||||
- 'app/services/projects/import_service.rb'
|
||||
- 'lib/api/branches.rb'
|
||||
- 'lib/gitlab/current_settings.rb'
|
||||
- 'lib/gitlab/git/commit.rb'
|
||||
- 'lib/gitlab/health_checks/base_abstract_check.rb'
|
||||
- 'lib/tasks/gitlab/task_helpers.rb'
|
||||
|
||||
# Offense count: 37
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Style/RedundantConditional:
|
||||
Exclude:
|
||||
- 'lib/system_check/helpers.rb'
|
||||
|
||||
# Offense count: 58
|
||||
# Cop supports --auto-correct.
|
||||
Style/RedundantFreeze:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 14
|
||||
# Offense count: 15
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowMultipleReturnValues.
|
||||
Style/RedundantReturn:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'app/controllers/application_controller.rb'
|
||||
- 'app/controllers/concerns/issuable_actions.rb'
|
||||
- 'app/controllers/groups/application_controller.rb'
|
||||
- 'app/controllers/omniauth_callbacks_controller.rb'
|
||||
- 'app/controllers/profiles/keys_controller.rb'
|
||||
- 'app/controllers/projects/application_controller.rb'
|
||||
- 'app/services/access_token_validation_service.rb'
|
||||
- 'lib/gitlab/utils.rb'
|
||||
- 'lib/google_api/auth.rb'
|
||||
|
||||
# Offense count: 406
|
||||
# Offense count: 454
|
||||
# Cop supports --auto-correct.
|
||||
Style/RedundantSelf:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 115
|
||||
# Offense count: 140
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
|
||||
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
|
||||
# SupportedStyles: slashes, percent_r, mixed
|
||||
Style/RegexpLiteral:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 29
|
||||
# Offense count: 35
|
||||
# Cop supports --auto-correct.
|
||||
Style/RescueModifier:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 105
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: implicit, explicit
|
||||
Style/RescueStandardError:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 91
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: ConvertCodeThatCanStartToReturnNil.
|
||||
Style/SafeNavigation:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 8
|
||||
# Cop supports --auto-correct.
|
||||
Style/SelfAssignment:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'app/models/concerns/bulk_member_access_load.rb'
|
||||
- 'app/serializers/base_serializer.rb'
|
||||
- 'app/services/notification_service.rb'
|
||||
- 'lib/api/runners.rb'
|
||||
- 'spec/features/merge_requests/diff_notes_resolve_spec.rb'
|
||||
- 'spec/features/projects/clusters/interchangeability_spec.rb'
|
||||
- 'spec/support/import_export/configuration_helper.rb'
|
||||
|
||||
# Offense count: 50
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowIfMethodIsEmpty.
|
||||
Style/SingleLineMethods:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/gitlab/ci/ansi2html.rb'
|
||||
|
||||
# Offense count: 64
|
||||
# Offense count: 66
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: SupportedStyles.
|
||||
# Configuration parameters: .
|
||||
# SupportedStyles: use_perl_names, use_english_names
|
||||
Style/SpecialGlobalVars:
|
||||
EnforcedStyle: use_perl_names
|
||||
|
||||
# Offense count: 44
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/StderrPuts:
|
||||
Exclude:
|
||||
- 'config/initializers/rspec_profiling.rb'
|
||||
|
||||
# Offense count: 45
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: single_quotes, double_quotes
|
||||
Style/StringLiteralsInInterpolation:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 84
|
||||
# Offense count: 99
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: IgnoredMethods.
|
||||
# IgnoredMethods: respond_to, define_method
|
||||
Style/SymbolProc:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 8
|
||||
# Offense count: 9
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowSafeAssignment.
|
||||
# Configuration parameters: EnforcedStyle, AllowSafeAssignment.
|
||||
# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
|
||||
Style/TernaryParentheses:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'app/finders/projects_finder.rb'
|
||||
- 'app/helpers/namespaces_helper.rb'
|
||||
- 'features/support/capybara.rb'
|
||||
- 'lib/api/v3/projects.rb'
|
||||
- 'lib/gitlab/ci/build/artifacts/metadata/entry.rb'
|
||||
- 'spec/requests/api/pipeline_schedules_spec.rb'
|
||||
- 'spec/support/capybara.rb'
|
||||
|
||||
# Offense count: 17
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowNamedUnderscoreVariables.
|
||||
Style/TrailingUnderscoreVariable:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'app/controllers/admin/background_jobs_controller.rb'
|
||||
- 'app/controllers/invites_controller.rb'
|
||||
- 'app/helpers/tab_helper.rb'
|
||||
- 'lib/backup/manager.rb'
|
||||
- 'lib/gitlab/logger.rb'
|
||||
- 'lib/gitlab/upgrader.rb'
|
||||
- 'lib/system_check/app/migrations_are_up_check.rb'
|
||||
- 'lib/system_check/incoming_email/mail_room_running_check.rb'
|
||||
- 'lib/tasks/gitlab/check.rake'
|
||||
- 'lib/tasks/gitlab/task_helpers.rb'
|
||||
- 'spec/lib/gitlab/etag_caching/middleware_spec.rb'
|
||||
- 'spec/services/quick_actions/interpret_service_spec.rb'
|
||||
|
||||
# Offense count: 4
|
||||
# Offense count: 5
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist.
|
||||
# Whitelist: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym
|
||||
Style/TrivialAccessors:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'app/models/external_issue.rb'
|
||||
- 'app/serializers/base_serializer.rb'
|
||||
- 'lib/gitlab/ldap/person.rb'
|
||||
- 'lib/system_check/base_check.rb'
|
||||
|
||||
# Offense count: 5
|
||||
# Offense count: 4
|
||||
# Cop supports --auto-correct.
|
||||
Style/UnlessElse:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'lib/backup/manager.rb'
|
||||
- 'lib/gitlab/project_search_results.rb'
|
||||
- 'lib/tasks/gitlab/check.rake'
|
||||
- 'spec/features/issues/award_emoji_spec.rb'
|
||||
|
||||
# Offense count: 28
|
||||
# Offense count: 30
|
||||
# Cop supports --auto-correct.
|
||||
Style/UnneededInterpolation:
|
||||
Enabled: false
|
||||
|
@ -342,4 +845,19 @@ Style/UnneededInterpolation:
|
|||
# Offense count: 11
|
||||
# Cop supports --auto-correct.
|
||||
Style/ZeroLengthPredicate:
|
||||
Enabled: false
|
||||
Exclude:
|
||||
- 'app/models/deploy_key.rb'
|
||||
- 'app/models/network/commit.rb'
|
||||
- 'app/models/network/graph.rb'
|
||||
- 'app/models/project_services/asana_service.rb'
|
||||
- 'app/services/boards/create_service.rb'
|
||||
- 'app/services/merge_requests/conflicts/list_service.rb'
|
||||
- 'lib/declarative_policy/dsl.rb'
|
||||
- 'lib/extracts_path.rb'
|
||||
- 'lib/gitlab/git/repository.rb'
|
||||
|
||||
# Offense count: 22050
|
||||
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
||||
# URISchemes: http, https
|
||||
Metrics/LineLength:
|
||||
Max: 1310
|
||||
|
|
8
Gemfile
8
Gemfile
|
@ -334,9 +334,11 @@ group :development, :test do
|
|||
gem 'spring-commands-rspec', '~> 1.0.4'
|
||||
gem 'spring-commands-spinach', '~> 1.1.0'
|
||||
|
||||
gem 'rubocop', '~> 0.49.1', require: false
|
||||
gem 'rubocop-rspec', '~> 1.15.1', require: false
|
||||
gem 'rubocop-gitlab-security', '~> 0.1.0', require: false
|
||||
gem 'gitlab-styles', '~> 2.2.0', require: false
|
||||
# Pin these dependencies, otherwise a new rule could break the CI pipelines
|
||||
gem 'rubocop', '~> 0.52.0'
|
||||
gem 'rubocop-rspec', '~> 1.20.1'
|
||||
|
||||
gem 'scss_lint', '~> 0.54.0', require: false
|
||||
gem 'haml_lint', '~> 0.26.0', require: false
|
||||
gem 'simplecov', '~> 0.14.0', require: false
|
||||
|
|
26
Gemfile.lock
26
Gemfile.lock
|
@ -303,6 +303,10 @@ GEM
|
|||
mime-types (>= 1.16)
|
||||
posix-spawn (~> 0.3)
|
||||
gitlab-markup (1.6.3)
|
||||
gitlab-styles (2.2.0)
|
||||
rubocop (~> 0.51)
|
||||
rubocop-gitlab-security (~> 0.1.0)
|
||||
rubocop-rspec (~> 1.19)
|
||||
gitlab_omniauth-ldap (2.0.4)
|
||||
net-ldap (~> 0.16)
|
||||
omniauth (~> 1.3)
|
||||
|
@ -777,21 +781,21 @@ GEM
|
|||
pg
|
||||
rails
|
||||
sqlite3
|
||||
rubocop (0.49.1)
|
||||
rubocop (0.52.0)
|
||||
parallel (~> 1.10)
|
||||
parser (>= 2.3.3.1, < 3.0)
|
||||
parser (>= 2.4.0.2, < 3.0)
|
||||
powerpack (~> 0.1)
|
||||
rainbow (>= 1.99.1, < 3.0)
|
||||
rainbow (>= 2.2.2, < 4.0)
|
||||
ruby-progressbar (~> 1.7)
|
||||
unicode-display_width (~> 1.0, >= 1.0.1)
|
||||
rubocop-gitlab-security (0.1.0)
|
||||
rubocop (>= 0.47.1)
|
||||
rubocop-rspec (1.15.1)
|
||||
rubocop (>= 0.42.0)
|
||||
rubocop-gitlab-security (0.1.1)
|
||||
rubocop (>= 0.51)
|
||||
rubocop-rspec (1.20.1)
|
||||
rubocop (>= 0.51.0)
|
||||
ruby-fogbugz (0.2.1)
|
||||
crack (~> 0.4)
|
||||
ruby-prof (0.16.2)
|
||||
ruby-progressbar (1.8.1)
|
||||
ruby-progressbar (1.9.0)
|
||||
ruby-saml (1.4.1)
|
||||
nokogiri (>= 1.5.10)
|
||||
ruby_parser (3.9.0)
|
||||
|
@ -1046,6 +1050,7 @@ DEPENDENCIES
|
|||
github-linguist (~> 4.7.0)
|
||||
gitlab-flowdock-git-hook (~> 1.0.1)
|
||||
gitlab-markup (~> 1.6.2)
|
||||
gitlab-styles (~> 2.2.0)
|
||||
gitlab_omniauth-ldap (~> 2.0.4)
|
||||
gollum-lib (~> 4.2)
|
||||
gollum-rugged_adapter (~> 0.4.4)
|
||||
|
@ -1148,9 +1153,8 @@ DEPENDENCIES
|
|||
rspec-retry (~> 0.4.5)
|
||||
rspec-set (~> 0.1.3)
|
||||
rspec_profiling (~> 0.0.5)
|
||||
rubocop (~> 0.49.1)
|
||||
rubocop-gitlab-security (~> 0.1.0)
|
||||
rubocop-rspec (~> 1.15.1)
|
||||
rubocop (~> 0.52.0)
|
||||
rubocop-rspec (~> 1.20.1)
|
||||
ruby-fogbugz (~> 0.2.1)
|
||||
ruby-prof (~> 0.16.2)
|
||||
ruby_parser (~> 3.8)
|
||||
|
|
|
@ -18,7 +18,7 @@ Peek.into Peek::Views::Rblineprof
|
|||
Peek.into Peek::Views::GC
|
||||
Peek.into Peek::Views::Gitaly
|
||||
|
||||
# rubocop:disable Style/ClassAndModuleCamelCase
|
||||
# rubocop:disable Naming/ClassAndModuleCamelCase
|
||||
class PEEK_DB_CLIENT
|
||||
class << self
|
||||
attr_accessor :query_details
|
||||
|
|
|
@ -93,9 +93,7 @@ module Gitlab
|
|||
|
||||
private
|
||||
|
||||
def entries
|
||||
@entries
|
||||
end
|
||||
attr_reader :entries
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -56,11 +56,12 @@ module Gitlab
|
|||
|
||||
# Do nothing if hooks already exist
|
||||
unless real_local_hooks_path == File.realpath(global_hooks_path)
|
||||
# Move the existing hooks somewhere safe
|
||||
FileUtils.mv(
|
||||
local_hooks_path,
|
||||
"#{local_hooks_path}.old.#{Time.now.to_i}"
|
||||
) if File.exist?(local_hooks_path)
|
||||
if File.exist?(local_hooks_path)
|
||||
# Move the existing hooks somewhere safe
|
||||
FileUtils.mv(
|
||||
local_hooks_path,
|
||||
"#{local_hooks_path}.old.#{Time.now.to_i}")
|
||||
end
|
||||
|
||||
# Create the hooks symlink
|
||||
FileUtils.ln_sf(global_hooks_path, local_hooks_path)
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
require_relative '../model_helpers'
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
# Cop that prevents the use of `dependent: ...` in ActiveRecord models.
|
||||
class ActiveRecordDependent < RuboCop::Cop::Cop
|
||||
include ModelHelpers
|
||||
|
||||
MSG = 'Do not use `dependent: to remove associated data, ' \
|
||||
'use foreign keys with cascading deletes instead'.freeze
|
||||
|
||||
METHOD_NAMES = [:has_many, :has_one, :belongs_to].freeze
|
||||
|
||||
def on_send(node)
|
||||
return unless in_model?(node)
|
||||
return unless METHOD_NAMES.include?(node.children[1])
|
||||
|
||||
node.children.last.each_node(:pair) do |pair|
|
||||
key_name = pair.children[0].children[0]
|
||||
|
||||
add_offense(pair, :expression) if key_name == :dependent
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,18 +0,0 @@
|
|||
require_relative '../model_helpers'
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
# Cop that prevents the use of `serialize` in ActiveRecord models.
|
||||
class ActiveRecordSerialize < RuboCop::Cop::Cop
|
||||
include ModelHelpers
|
||||
|
||||
MSG = 'Do not store serialized data in the database, use separate columns and/or tables instead'.freeze
|
||||
|
||||
def on_send(node)
|
||||
return unless in_model?(node)
|
||||
|
||||
add_offense(node, :selector) if node.children[1] == :serialize
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,64 +0,0 @@
|
|||
module RuboCop
|
||||
module Cop
|
||||
# This cop makes sure that custom error classes, when empty, are declared
|
||||
# with Class.new.
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
# class FooError < StandardError
|
||||
# end
|
||||
#
|
||||
# # okish
|
||||
# class FooError < StandardError; end
|
||||
#
|
||||
# # good
|
||||
# FooError = Class.new(StandardError)
|
||||
class CustomErrorClass < RuboCop::Cop::Cop
|
||||
MSG = 'Use `Class.new(SuperClass)` to define an empty custom error class.'.freeze
|
||||
|
||||
def on_class(node)
|
||||
_klass, parent, body = node.children
|
||||
|
||||
return if body
|
||||
|
||||
parent_klass = class_name_from_node(parent)
|
||||
|
||||
return unless parent_klass && parent_klass.to_s.end_with?('Error')
|
||||
|
||||
add_offense(node, :expression)
|
||||
end
|
||||
|
||||
def autocorrect(node)
|
||||
klass, parent, _body = node.children
|
||||
replacement = "#{class_name_from_node(klass)} = Class.new(#{class_name_from_node(parent)})"
|
||||
|
||||
lambda do |corrector|
|
||||
corrector.replace(node.source_range, replacement)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# The nested constant `Foo::Bar::Baz` looks like:
|
||||
#
|
||||
# s(:const,
|
||||
# s(:const,
|
||||
# s(:const, nil, :Foo), :Bar), :Baz)
|
||||
#
|
||||
# So recurse through that to get the name as written in the source.
|
||||
#
|
||||
def class_name_from_node(node, suffix = nil)
|
||||
return unless node&.type == :const
|
||||
|
||||
name = node.children[1].to_s
|
||||
name = "#{name}::#{suffix}" if suffix
|
||||
|
||||
if node.children[0]
|
||||
class_name_from_node(node.children[0], name)
|
||||
else
|
||||
name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,37 +0,0 @@
|
|||
module RuboCop
|
||||
module Cop
|
||||
# This cop prevents usage of the `git` and `github` arguments to `gem` in a
|
||||
# `Gemfile` in order to avoid additional points of failure beyond
|
||||
# rubygems.org.
|
||||
class GemFetcher < RuboCop::Cop::Cop
|
||||
MSG = 'Do not use gems from git repositories, only use gems from RubyGems.'.freeze
|
||||
|
||||
GIT_KEYS = [:git, :github].freeze
|
||||
|
||||
def on_send(node)
|
||||
return unless gemfile?(node)
|
||||
|
||||
func_name = node.children[1]
|
||||
return unless func_name == :gem
|
||||
|
||||
node.children.last.each_node(:pair) do |pair|
|
||||
key_name = pair.children[0].children[0].to_sym
|
||||
if GIT_KEYS.include?(key_name)
|
||||
add_offense(node, pair.source_range, MSG)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def gemfile?(node)
|
||||
node
|
||||
.location
|
||||
.expression
|
||||
.source_buffer
|
||||
.name
|
||||
.end_with?("Gemfile")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -30,12 +30,12 @@ module RuboCop
|
|||
if only_ivar_or_assignment?(definition)
|
||||
# We don't allow if any other ivar is used
|
||||
definition.each_descendant(:ivar) do |offense|
|
||||
add_offense(offense, :expression)
|
||||
add_offense(offense, location: :expression)
|
||||
end
|
||||
# We allow initialize method and single ivar
|
||||
elsif !initialize_method?(definition) && !single_ivar?(definition)
|
||||
definition.each_descendant(:ivar, :ivasgn) do |offense|
|
||||
add_offense(offense, :expression)
|
||||
add_offense(offense, location: :expression)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
require_relative '../model_helpers'
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
# Cop that prevents the use of `in_batches`
|
||||
class InBatches < RuboCop::Cop::Cop
|
||||
MSG = 'Do not use `in_batches`, use `each_batch` from the EachBatch module instead'.freeze
|
||||
|
||||
def on_send(node)
|
||||
return unless node.children[1] == :in_batches
|
||||
|
||||
add_offense(node, :selector)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,14 +9,14 @@ module RuboCop
|
|||
MSG = 'Include `ApplicationWorker`, not `Sidekiq::Worker`.'.freeze
|
||||
|
||||
def_node_matcher :includes_sidekiq_worker?, <<~PATTERN
|
||||
(send nil :include (const (const nil :Sidekiq) :Worker))
|
||||
(send nil? :include (const (const nil? :Sidekiq) :Worker))
|
||||
PATTERN
|
||||
|
||||
def on_send(node)
|
||||
return if in_spec?(node)
|
||||
return unless includes_sidekiq_worker?(node)
|
||||
|
||||
add_offense(node.arguments.first, :expression)
|
||||
add_offense(node.arguments.first, location: :expression)
|
||||
end
|
||||
|
||||
def autocorrect(node)
|
||||
|
|
|
@ -1,100 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
# Ensures a line break after guard clauses.
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
# return unless condition
|
||||
# do_stuff
|
||||
#
|
||||
# # good
|
||||
# return unless condition
|
||||
#
|
||||
# do_stuff
|
||||
#
|
||||
# # bad
|
||||
# raise if condition
|
||||
# do_stuff
|
||||
#
|
||||
# # good
|
||||
# raise if condition
|
||||
#
|
||||
# do_stuff
|
||||
#
|
||||
# Multiple guard clauses are allowed without
|
||||
# line break.
|
||||
#
|
||||
# # good
|
||||
# return unless condition_a
|
||||
# return unless condition_b
|
||||
#
|
||||
# do_stuff
|
||||
#
|
||||
# Guard clauses in case statement are allowed without
|
||||
# line break.
|
||||
#
|
||||
# # good
|
||||
# case model
|
||||
# when condition_a
|
||||
# return true unless condition_b
|
||||
# when
|
||||
# ...
|
||||
# end
|
||||
#
|
||||
# Guard clauses before end are allowed without
|
||||
# line break.
|
||||
#
|
||||
# # good
|
||||
# if condition_a
|
||||
# do_something
|
||||
# else
|
||||
# do_something_else
|
||||
# return unless condition
|
||||
# end
|
||||
#
|
||||
# do_something_more
|
||||
class LineBreakAfterGuardClauses < RuboCop::Cop::Cop
|
||||
MSG = 'Add a line break after guard clauses'
|
||||
|
||||
def_node_matcher :guard_clause_node?, <<-PATTERN
|
||||
[{(send nil? {:raise :fail :throw} ...) return break next} single_line?]
|
||||
PATTERN
|
||||
|
||||
def on_if(node)
|
||||
return unless node.single_line?
|
||||
return unless guard_clause?(node)
|
||||
return if next_line(node).blank? || clause_last_line?(next_line(node)) || guard_clause?(next_sibling(node))
|
||||
|
||||
add_offense(node, :expression, MSG)
|
||||
end
|
||||
|
||||
def autocorrect(node)
|
||||
lambda do |corrector|
|
||||
corrector.insert_after(node.loc.expression, "\n")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def guard_clause?(node)
|
||||
return false unless node.if_type?
|
||||
|
||||
guard_clause_node?(node.if_branch)
|
||||
end
|
||||
|
||||
def next_sibling(node)
|
||||
node.parent.children[node.sibling_index + 1]
|
||||
end
|
||||
|
||||
def next_line(node)
|
||||
processed_source[node.loc.line]
|
||||
end
|
||||
|
||||
def clause_last_line?(line)
|
||||
line =~ /^\s*(?:end|elsif|else|when|rescue|ensure)/
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -29,7 +29,7 @@ module RuboCop
|
|||
|
||||
opts.each_node(:pair) do |pair|
|
||||
if hash_key_type(pair) == :sym && hash_key_name(pair) == :default
|
||||
add_offense(node, :selector)
|
||||
add_offense(node, location: :selector)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ module RuboCop
|
|||
|
||||
name = node.children[1]
|
||||
|
||||
add_offense(node, :selector) if name == :add_foreign_key
|
||||
add_offense(node, location: :selector) if name == :add_foreign_key
|
||||
end
|
||||
|
||||
def method_name(node)
|
||||
|
|
|
@ -21,7 +21,7 @@ module RuboCop
|
|||
node.each_ancestor(:def) do |def_node|
|
||||
next unless method_name(def_node) == :change
|
||||
|
||||
add_offense(def_node, :name)
|
||||
add_offense(def_node, location: :name)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ module RuboCop
|
|||
# data in these tables yet.
|
||||
next if new_tables.include?(first_arg)
|
||||
|
||||
add_offense(send_node, :selector)
|
||||
add_offense(send_node, location: :selector)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ module RuboCop
|
|||
def on_send(node)
|
||||
return unless in_migration?(node)
|
||||
|
||||
add_offense(node, :selector) if method_name(node) == :add_timestamps
|
||||
add_offense(node, location: :selector) if method_name(node) == :add_timestamps
|
||||
end
|
||||
|
||||
def method_name(node)
|
||||
|
|
|
@ -17,7 +17,7 @@ module RuboCop
|
|||
method_name = node.children[1]
|
||||
|
||||
if method_name == :datetime || method_name == :timestamp
|
||||
add_offense(send_node, :selector, format(MSG, method_name))
|
||||
add_offense(send_node, location: :selector, message: format(MSG, method_name))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -32,7 +32,7 @@ module RuboCop
|
|||
last_argument = descendant.children.last
|
||||
|
||||
if last_argument == :datetime || last_argument == :timestamp
|
||||
add_offense(node, :expression, format(MSG, last_argument))
|
||||
add_offense(node, location: :expression, message: format(MSG, last_argument))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ module RuboCop
|
|||
hash_key_name(pair) == :using
|
||||
|
||||
if hash_key_value(pair).to_s == 'hash'
|
||||
add_offense(pair, :expression)
|
||||
add_offense(pair, location: :expression)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ module RuboCop
|
|||
send_method = send_node.children[1]
|
||||
|
||||
if send_method == :remove_column
|
||||
add_offense(send_node, :selector)
|
||||
add_offense(send_node, location: :selector)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ module RuboCop
|
|||
return unless node.children[1] == :remove_concurrent_index
|
||||
|
||||
node.each_ancestor(:def) do |def_node|
|
||||
add_offense(def_node, :name) if method_name(def_node) == :change
|
||||
add_offense(def_node, location: :name) if method_name(def_node) == :change
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ module RuboCop
|
|||
return unless in_migration?(node)
|
||||
|
||||
node.each_descendant(:send) do |send_node|
|
||||
add_offense(send_node, :selector) if method_name(send_node) == :remove_index
|
||||
add_offense(send_node, location: :selector) if method_name(send_node) == :remove_index
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ module RuboCop
|
|||
include MigrationHelpers
|
||||
|
||||
def_node_matcher :add_column_with_default?, <<~PATTERN
|
||||
(send nil :add_column_with_default $...)
|
||||
(send nil? :add_column_with_default $...)
|
||||
PATTERN
|
||||
|
||||
def_node_matcher :defines_change?, <<~PATTERN
|
||||
|
@ -26,7 +26,7 @@ module RuboCop
|
|||
node.each_ancestor(:def) do |def_node|
|
||||
next unless defines_change?(def_node)
|
||||
|
||||
add_offense(def_node, :name)
|
||||
add_offense(def_node, location: :name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,7 +28,7 @@ module RuboCop
|
|||
].freeze
|
||||
|
||||
def_node_matcher :add_column?, <<~PATTERN
|
||||
(send nil :add_column $...)
|
||||
(send nil? :add_column $...)
|
||||
PATTERN
|
||||
|
||||
def on_send(node)
|
||||
|
@ -54,7 +54,7 @@ module RuboCop
|
|||
NULL_OFFENSE
|
||||
end
|
||||
|
||||
add_offense(node, :expression, format(offense, table)) if offense
|
||||
add_offense(node, location: :expression, message: format(offense, table)) if offense
|
||||
end
|
||||
|
||||
def no_default?(opts)
|
||||
|
|
|
@ -14,7 +14,7 @@ module RuboCop
|
|||
return unless in_migration?(node)
|
||||
|
||||
node.each_descendant(:send) do |send_node|
|
||||
add_offense(send_node, :selector) if method_name(send_node) == :timestamps
|
||||
add_offense(send_node, location: :selector) if method_name(send_node) == :timestamps
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ module RuboCop
|
|||
spec_path = spec_filename(node)
|
||||
|
||||
unless File.exist?(File.expand_path(spec_path, rails_root))
|
||||
add_offense(node, :expression, format(MSG, spec_path))
|
||||
add_offense(node, location: :expression, message: format(MSG, spec_path))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ module RuboCop
|
|||
].freeze
|
||||
|
||||
def_node_matcher :batch_update?, <<~PATTERN
|
||||
(send nil ${:add_column_with_default :update_column_in_batches} $(sym ...) ...)
|
||||
(send nil? ${:add_column_with_default :update_column_in_batches} $(sym ...) ...)
|
||||
PATTERN
|
||||
|
||||
def on_send(node)
|
||||
|
@ -49,7 +49,7 @@ module RuboCop
|
|||
|
||||
return unless LARGE_TABLES.include?(table)
|
||||
|
||||
add_offense(node, :expression, format(MSG, update_method, table))
|
||||
add_offense(node, location: :expression, message: format(MSG, update_method, table))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
require_relative '../model_helpers'
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
# Cop that prevents the use of polymorphic associations
|
||||
class PolymorphicAssociations < RuboCop::Cop::Cop
|
||||
include ModelHelpers
|
||||
|
||||
MSG = 'Do not use polymorphic associations, use separate tables instead'.freeze
|
||||
|
||||
def on_send(node)
|
||||
return unless in_model?(node)
|
||||
return unless node.children[1] == :belongs_to
|
||||
|
||||
node.children.last.each_node(:pair) do |pair|
|
||||
key_name = pair.children[0].children[0]
|
||||
|
||||
add_offense(pair, :expression) if key_name == :polymorphic
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -17,7 +17,7 @@ module RuboCop
|
|||
return unless method_name(namespace_expr) == :namespace
|
||||
return unless receiver(namespace_expr) == project_expr
|
||||
|
||||
add_offense(node, :selector)
|
||||
add_offense(node, location: :selector)
|
||||
end
|
||||
|
||||
def autocorrect(node)
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
module RuboCop
|
||||
module Cop
|
||||
# This cop prevents usage of 'redirect_to' in actions 'destroy' without specifying 'status'.
|
||||
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/31840
|
||||
class RedirectWithStatus < RuboCop::Cop::Cop
|
||||
MSG = 'Do not use "redirect_to" without "status" in "destroy" action'.freeze
|
||||
|
||||
def on_def(node)
|
||||
return unless in_controller?(node)
|
||||
return unless destroy?(node) || destroy_all?(node)
|
||||
|
||||
node.each_descendant(:send) do |def_node|
|
||||
next unless redirect_to?(def_node)
|
||||
|
||||
methods = []
|
||||
|
||||
def_node.children.last.each_node(:pair) do |pair|
|
||||
methods << pair.children.first.children.first
|
||||
end
|
||||
|
||||
add_offense(def_node, :selector) unless methods.include?(:status)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def in_controller?(node)
|
||||
node.location.expression.source_buffer.name.end_with?('_controller.rb')
|
||||
end
|
||||
|
||||
def destroy?(node)
|
||||
node.children.first == :destroy
|
||||
end
|
||||
|
||||
def destroy_all?(node)
|
||||
node.children.first == :destroy_all
|
||||
end
|
||||
|
||||
def redirect_to?(node)
|
||||
node.children[1] == :redirect_to
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,3 @@
|
|||
require 'rubocop-rspec'
|
||||
require_relative '../../spec_helpers'
|
||||
|
||||
module RuboCop
|
||||
|
@ -17,7 +16,7 @@ module RuboCop
|
|||
# before do
|
||||
# stub_env('FOO', 'bar')
|
||||
# end
|
||||
class EnvAssignment < Cop
|
||||
class EnvAssignment < RuboCop::Cop::Cop
|
||||
include SpecHelpers
|
||||
|
||||
MESSAGE = "Don't assign to ENV, use `stub_env` instead.".freeze
|
||||
|
@ -32,7 +31,7 @@ module RuboCop
|
|||
return unless in_spec?(node)
|
||||
return unless env_assignment?(node)
|
||||
|
||||
add_offense(node, :expression, MESSAGE)
|
||||
add_offense(node, location: :expression, message: MESSAGE)
|
||||
end
|
||||
|
||||
def autocorrect(node)
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
require 'rubocop-rspec'
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module RSpec
|
||||
# This cop checks for single-line hook blocks
|
||||
#
|
||||
# @example
|
||||
#
|
||||
# # bad
|
||||
# before { do_something }
|
||||
# after(:each) { undo_something }
|
||||
#
|
||||
# # good
|
||||
# before do
|
||||
# do_something
|
||||
# end
|
||||
#
|
||||
# after(:each) do
|
||||
# undo_something
|
||||
# end
|
||||
class SingleLineHook < Cop
|
||||
MESSAGE = "Don't use single-line hook blocks.".freeze
|
||||
|
||||
def_node_search :rspec_hook?, <<~PATTERN
|
||||
(send nil {:after :around :before} ...)
|
||||
PATTERN
|
||||
|
||||
def on_block(node)
|
||||
return unless rspec_hook?(node)
|
||||
return unless node.single_line?
|
||||
|
||||
add_offense(node, :expression, MESSAGE)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,74 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rubocop-rspec'
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module RSpec
|
||||
# Checks for verbose include metadata used in the specs.
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
# describe MyClass, js: true do
|
||||
# end
|
||||
#
|
||||
# # good
|
||||
# describe MyClass, :js do
|
||||
# end
|
||||
class VerboseIncludeMetadata < Cop
|
||||
MSG = 'Use `%s` instead of `%s`.'
|
||||
|
||||
SELECTORS = %i[describe context feature example_group it specify example scenario its].freeze
|
||||
|
||||
def_node_matcher :include_metadata, <<-PATTERN
|
||||
(send {(const nil :RSpec) nil} {#{SELECTORS.map(&:inspect).join(' ')}}
|
||||
!const
|
||||
...
|
||||
(hash $...))
|
||||
PATTERN
|
||||
|
||||
def_node_matcher :invalid_metadata?, <<-PATTERN
|
||||
(pair
|
||||
(sym $...)
|
||||
(true))
|
||||
PATTERN
|
||||
|
||||
def on_send(node)
|
||||
invalid_metadata_matches(node) do |match|
|
||||
add_offense(node, :expression, format(MSG, good(match), bad(match)))
|
||||
end
|
||||
end
|
||||
|
||||
def autocorrect(node)
|
||||
lambda do |corrector|
|
||||
invalid_metadata_matches(node) do |match|
|
||||
corrector.replace(match.loc.expression, good(match))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def invalid_metadata_matches(node)
|
||||
include_metadata(node) do |matches|
|
||||
matches.select(&method(:invalid_metadata?)).each do |match|
|
||||
yield match
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def bad(match)
|
||||
"#{metadata_key(match)}: true"
|
||||
end
|
||||
|
||||
def good(match)
|
||||
":#{metadata_key(match)}"
|
||||
end
|
||||
|
||||
def metadata_key(match)
|
||||
match.children[0].source
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,7 +9,7 @@ module RuboCop
|
|||
MSG = 'Do not manually set a queue; `ApplicationWorker` sets one automatically.'.freeze
|
||||
|
||||
def_node_matcher :sidekiq_options?, <<~PATTERN
|
||||
(send nil :sidekiq_options $...)
|
||||
(send nil? :sidekiq_options $...)
|
||||
PATTERN
|
||||
|
||||
def on_send(node)
|
||||
|
@ -19,7 +19,7 @@ module RuboCop
|
|||
node.arguments.first.each_node(:pair) do |pair|
|
||||
key_name = pair.key.children[0]
|
||||
|
||||
add_offense(pair, :expression) if key_name == :queue
|
||||
add_offense(pair, location: :expression) if key_name == :queue
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
module RuboCop
|
||||
module ModelHelpers
|
||||
# Returns true if the given node originated from the models directory.
|
||||
def in_model?(node)
|
||||
path = node.location.expression.source_buffer.name
|
||||
models_path = File.join(Dir.pwd, 'app', 'models')
|
||||
|
||||
path.start_with?(models_path)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,15 +1,6 @@
|
|||
require_relative 'cop/active_record_dependent'
|
||||
require_relative 'cop/active_record_serialize'
|
||||
require_relative 'cop/custom_error_class'
|
||||
require_relative 'cop/gem_fetcher'
|
||||
require_relative 'cop/in_batches'
|
||||
require_relative 'cop/include_sidekiq_worker'
|
||||
require_relative 'cop/line_break_after_guard_clauses'
|
||||
require_relative 'cop/polymorphic_associations'
|
||||
require_relative 'cop/project_path_helper'
|
||||
require_relative 'cop/redirect_with_status'
|
||||
require_relative 'cop/gitlab/module_with_instance_variables'
|
||||
require_relative 'cop/sidekiq_options_queue'
|
||||
require_relative 'cop/include_sidekiq_worker'
|
||||
require_relative 'cop/migration/add_column'
|
||||
require_relative 'cop/migration/add_concurrent_foreign_key'
|
||||
require_relative 'cop/migration/add_concurrent_index'
|
||||
|
@ -25,6 +16,8 @@ require_relative 'cop/migration/safer_boolean_column'
|
|||
require_relative 'cop/migration/timestamps'
|
||||
require_relative 'cop/migration/update_column_in_batches'
|
||||
require_relative 'cop/migration/update_large_table'
|
||||
require_relative 'cop/project_path_helper'
|
||||
require_relative 'cop/rspec/env_assignment'
|
||||
require_relative 'cop/rspec/single_line_hook'
|
||||
require_relative 'cop/rspec/verbose_include_metadata'
|
||||
require_relative 'cop/sidekiq_options_queue'
|
||||
|
|
|
@ -14,6 +14,7 @@ FactoryBot.define do
|
|||
|
||||
trait :closed do
|
||||
state :closed
|
||||
closed_at { Time.now }
|
||||
end
|
||||
|
||||
factory :closed_issue, traits: [:closed]
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
require 'spec_helper'
|
||||
require 'rubocop'
|
||||
require 'rubocop/rspec/support'
|
||||
require_relative '../../../rubocop/cop/active_record_dependent'
|
||||
|
||||
describe RuboCop::Cop::ActiveRecordDependent do
|
||||
include CopHelper
|
||||
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context 'inside the app/models directory' do
|
||||
it 'registers an offense when dependent: is used' do
|
||||
allow(cop).to receive(:in_model?).and_return(true)
|
||||
|
||||
inspect_source(cop, 'belongs_to :foo, dependent: :destroy')
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
expect(cop.offenses.map(&:line)).to eq([1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'outside the app/models directory' do
|
||||
it 'does nothing' do
|
||||
allow(cop).to receive(:in_model?).and_return(false)
|
||||
|
||||
inspect_source(cop, 'belongs_to :foo, dependent: :destroy')
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,33 +0,0 @@
|
|||
require 'spec_helper'
|
||||
require 'rubocop'
|
||||
require 'rubocop/rspec/support'
|
||||
require_relative '../../../rubocop/cop/active_record_serialize'
|
||||
|
||||
describe RuboCop::Cop::ActiveRecordSerialize do
|
||||
include CopHelper
|
||||
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context 'inside the app/models directory' do
|
||||
it 'registers an offense when serialize is used' do
|
||||
allow(cop).to receive(:in_model?).and_return(true)
|
||||
|
||||
inspect_source(cop, 'serialize :foo')
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
expect(cop.offenses.map(&:line)).to eq([1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'outside the app/models directory' do
|
||||
it 'does nothing' do
|
||||
allow(cop).to receive(:in_model?).and_return(false)
|
||||
|
||||
inspect_source(cop, 'serialize :foo')
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,111 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
require 'rubocop'
|
||||
require 'rubocop/rspec/support'
|
||||
|
||||
require_relative '../../../rubocop/cop/custom_error_class'
|
||||
|
||||
describe RuboCop::Cop::CustomErrorClass do
|
||||
include CopHelper
|
||||
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context 'when a class has a body' do
|
||||
it 'does nothing' do
|
||||
inspect_source(cop, 'class CustomError < StandardError; def foo; end; end')
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a class has no explicit superclass' do
|
||||
it 'does nothing' do
|
||||
inspect_source(cop, 'class CustomError; end')
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a class has a superclass that does not end in Error' do
|
||||
it 'does nothing' do
|
||||
inspect_source(cop, 'class CustomError < BasicObject; end')
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a class is empty and inherits from a class ending in Error' do
|
||||
context 'when the class is on a single line' do
|
||||
let(:source) do
|
||||
<<-SOURCE
|
||||
module Foo
|
||||
class CustomError < Bar::Baz::BaseError; end
|
||||
end
|
||||
SOURCE
|
||||
end
|
||||
|
||||
let(:expected) do
|
||||
<<-EXPECTED
|
||||
module Foo
|
||||
CustomError = Class.new(Bar::Baz::BaseError)
|
||||
end
|
||||
EXPECTED
|
||||
end
|
||||
|
||||
it 'registers an offense' do
|
||||
expected_highlights = source.split("\n")[1].strip
|
||||
|
||||
inspect_source(cop, source)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
expect(cop.offenses.map(&:line)).to eq([2])
|
||||
expect(cop.highlights).to contain_exactly(expected_highlights)
|
||||
end
|
||||
end
|
||||
|
||||
it 'autocorrects to the right version' do
|
||||
autocorrected = autocorrect_source(cop, source, 'foo/custom_error.rb')
|
||||
|
||||
expect(autocorrected).to eq(expected)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the class is on multiple lines' do
|
||||
let(:source) do
|
||||
<<-SOURCE
|
||||
module Foo
|
||||
class CustomError < Bar::Baz::BaseError
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
end
|
||||
|
||||
let(:expected) do
|
||||
<<-EXPECTED
|
||||
module Foo
|
||||
CustomError = Class.new(Bar::Baz::BaseError)
|
||||
end
|
||||
EXPECTED
|
||||
end
|
||||
|
||||
it 'registers an offense' do
|
||||
expected_highlights = source.split("\n")[1..2].join("\n").strip
|
||||
|
||||
inspect_source(cop, source)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
expect(cop.offenses.map(&:line)).to eq([2])
|
||||
expect(cop.highlights).to contain_exactly(expected_highlights)
|
||||
end
|
||||
end
|
||||
|
||||
it 'autocorrects to the right version' do
|
||||
autocorrected = autocorrect_source(cop, source, 'foo/custom_error.rb')
|
||||
|
||||
expect(autocorrected).to eq(expected)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,46 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
require 'rubocop'
|
||||
require 'rubocop/rspec/support'
|
||||
|
||||
require_relative '../../../rubocop/cop/gem_fetcher'
|
||||
|
||||
describe RuboCop::Cop::GemFetcher do
|
||||
include CopHelper
|
||||
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context 'in Gemfile' do
|
||||
before do
|
||||
allow(cop).to receive(:gemfile?).and_return(true)
|
||||
end
|
||||
|
||||
it 'registers an offense when a gem uses `git`' do
|
||||
inspect_source(cop, 'gem "foo", git: "https://gitlab.com/foo/bar.git"')
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
expect(cop.offenses.map(&:line)).to eq([1])
|
||||
expect(cop.highlights).to eq(['git: "https://gitlab.com/foo/bar.git"'])
|
||||
end
|
||||
end
|
||||
|
||||
it 'registers an offense when a gem uses `github`' do
|
||||
inspect_source(cop, 'gem "foo", github: "foo/bar.git"')
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
expect(cop.offenses.map(&:line)).to eq([1])
|
||||
expect(cop.highlights).to eq(['github: "foo/bar.git"'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'outside of Gemfile' do
|
||||
it 'registers no offense' do
|
||||
inspect_source(cop, 'gem "foo", git: "https://gitlab.com/foo/bar.git"')
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -12,7 +12,7 @@ describe RuboCop::Cop::Gitlab::ModuleWithInstanceVariables do
|
|||
let(:offending_lines) { options[:offending_lines] }
|
||||
|
||||
it 'registers an offense when instance variable is used in a module' do
|
||||
inspect_source(cop, source)
|
||||
inspect_source(source)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(offending_lines.size)
|
||||
|
@ -23,7 +23,7 @@ describe RuboCop::Cop::Gitlab::ModuleWithInstanceVariables do
|
|||
|
||||
shared_examples('not registering offense') do
|
||||
it 'does not register offenses' do
|
||||
inspect_source(cop, source)
|
||||
inspect_source(source)
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
require 'spec_helper'
|
||||
require 'rubocop'
|
||||
require 'rubocop/rspec/support'
|
||||
require_relative '../../../rubocop/cop/in_batches'
|
||||
|
||||
describe RuboCop::Cop::InBatches do
|
||||
include CopHelper
|
||||
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
it 'registers an offense when in_batches is used' do
|
||||
inspect_source(cop, 'foo.in_batches do; end')
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
expect(cop.offenses.map(&:line)).to eq([1])
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
require 'rubocop'
|
||||
require 'rubocop/rspec/support'
|
||||
|
||||
require_relative '../../../rubocop/cop/include_sidekiq_worker'
|
||||
|
||||
describe RuboCop::Cop::IncludeSidekiqWorker do
|
||||
|
@ -13,7 +15,7 @@ describe RuboCop::Cop::IncludeSidekiqWorker do
|
|||
let(:correct_source) { 'include ApplicationWorker' }
|
||||
|
||||
it 'registers an offense ' do
|
||||
inspect_source(cop, source)
|
||||
inspect_source(source)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -23,7 +25,7 @@ describe RuboCop::Cop::IncludeSidekiqWorker do
|
|||
end
|
||||
|
||||
it 'autocorrects to the right version' do
|
||||
autocorrected = autocorrect_source(cop, source)
|
||||
autocorrected = autocorrect_source(source)
|
||||
|
||||
expect(autocorrected).to eq(correct_source)
|
||||
end
|
||||
|
|
|
@ -1,160 +0,0 @@
|
|||
require 'spec_helper'
|
||||
require 'rubocop'
|
||||
require 'rubocop/rspec/support'
|
||||
require_relative '../../../rubocop/cop/line_break_after_guard_clauses'
|
||||
|
||||
describe RuboCop::Cop::LineBreakAfterGuardClauses do
|
||||
include CopHelper
|
||||
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
shared_examples 'examples with guard clause' do |title|
|
||||
%w[if unless].each do |conditional|
|
||||
it "flags violation for #{title} #{conditional} without line breaks" do
|
||||
source = <<~RUBY
|
||||
#{title} #{conditional} condition
|
||||
do_stuff
|
||||
RUBY
|
||||
inspect_source(cop, source)
|
||||
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
offense = cop.offenses.first
|
||||
|
||||
expect(offense.line).to eq(1)
|
||||
expect(cop.highlights).to eq(["#{title} #{conditional} condition"])
|
||||
expect(offense.message).to eq('Add a line break after guard clauses')
|
||||
end
|
||||
|
||||
it "doesn't flag violation for #{title} #{conditional} with line break" do
|
||||
source = <<~RUBY
|
||||
#{title} #{conditional} condition
|
||||
|
||||
do_stuff
|
||||
RUBY
|
||||
inspect_source(cop, source)
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
||||
it "doesn't flag violation for #{title} #{conditional} on multiple lines without line break" do
|
||||
source = <<~RUBY
|
||||
#{conditional} condition
|
||||
#{title}
|
||||
end
|
||||
do_stuff
|
||||
RUBY
|
||||
inspect_source(cop, source)
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
||||
it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by end keyword" do
|
||||
source = <<~RUBY
|
||||
def test
|
||||
#{title} #{conditional} condition
|
||||
end
|
||||
RUBY
|
||||
inspect_source(cop, source)
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
||||
it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by elsif keyword" do
|
||||
source = <<~RUBY
|
||||
if model
|
||||
#{title} #{conditional} condition
|
||||
elsif
|
||||
do_something
|
||||
end
|
||||
RUBY
|
||||
inspect_source(cop, source)
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
||||
it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by else keyword" do
|
||||
source = <<~RUBY
|
||||
if model
|
||||
#{title} #{conditional} condition
|
||||
else
|
||||
do_something
|
||||
end
|
||||
RUBY
|
||||
inspect_source(cop, source)
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
||||
it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by when keyword" do
|
||||
source = <<~RUBY
|
||||
case model
|
||||
when condition_a
|
||||
#{title} #{conditional} condition
|
||||
when condition_b
|
||||
do_something
|
||||
end
|
||||
RUBY
|
||||
inspect_source(cop, source)
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
||||
it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by rescue keyword" do
|
||||
source = <<~RUBY
|
||||
begin
|
||||
#{title} #{conditional} condition
|
||||
rescue StandardError
|
||||
do_something
|
||||
end
|
||||
RUBY
|
||||
inspect_source(cop, source)
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
||||
it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by ensure keyword" do
|
||||
source = <<~RUBY
|
||||
def foo
|
||||
#{title} #{conditional} condition
|
||||
ensure
|
||||
do_something
|
||||
end
|
||||
RUBY
|
||||
inspect_source(cop, source)
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
||||
it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by another guard clause" do
|
||||
source = <<~RUBY
|
||||
#{title} #{conditional} condition
|
||||
#{title} #{conditional} condition
|
||||
|
||||
do_stuff
|
||||
RUBY
|
||||
inspect_source(cop, source)
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
||||
it "autocorrects #{title} #{conditional} guard clauses without line break" do
|
||||
source = <<~RUBY
|
||||
#{title} #{conditional} condition
|
||||
do_stuff
|
||||
RUBY
|
||||
autocorrected = autocorrect_source(cop, source)
|
||||
|
||||
expected_source = <<~RUBY
|
||||
#{title} #{conditional} condition
|
||||
|
||||
do_stuff
|
||||
RUBY
|
||||
expect(autocorrected).to eql(expected_source)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
%w[return fail raise next break throw].each do |example|
|
||||
it_behaves_like 'examples with guard clause', example
|
||||
end
|
||||
end
|
|
@ -1,6 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
require 'rubocop'
|
||||
require 'rubocop/rspec/support'
|
||||
|
||||
require_relative '../../../../rubocop/cop/migration/add_concurrent_foreign_key'
|
||||
|
||||
describe RuboCop::Cop::Migration::AddConcurrentForeignKey do
|
||||
|
@ -10,7 +12,7 @@ describe RuboCop::Cop::Migration::AddConcurrentForeignKey do
|
|||
|
||||
context 'outside of a migration' do
|
||||
it 'does not register any offenses' do
|
||||
inspect_source(cop, 'def up; add_foreign_key(:projects, :users, column: :user_id); end')
|
||||
inspect_source('def up; add_foreign_key(:projects, :users, column: :user_id); end')
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
@ -22,7 +24,7 @@ describe RuboCop::Cop::Migration::AddConcurrentForeignKey do
|
|||
end
|
||||
|
||||
it 'registers an offense when using add_foreign_key' do
|
||||
inspect_source(cop, 'def up; add_foreign_key(:projects, :users, column: :user_id); end')
|
||||
inspect_source('def up; add_foreign_key(:projects, :users, column: :user_id); end')
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
|
|
@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::AddConcurrentIndex do
|
|||
end
|
||||
|
||||
it 'registers an offense when add_concurrent_index is used inside a change method' do
|
||||
inspect_source(cop, 'def change; add_concurrent_index :table, :column; end')
|
||||
inspect_source('def change; add_concurrent_index :table, :column; end')
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -25,7 +25,7 @@ describe RuboCop::Cop::Migration::AddConcurrentIndex do
|
|||
end
|
||||
|
||||
it 'registers no offense when add_concurrent_index is used inside an up method' do
|
||||
inspect_source(cop, 'def up; add_concurrent_index :table, :column; end')
|
||||
inspect_source('def up; add_concurrent_index :table, :column; end')
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
@ -33,7 +33,7 @@ describe RuboCop::Cop::Migration::AddConcurrentIndex do
|
|||
|
||||
context 'outside of migration' do
|
||||
it 'registers no offense' do
|
||||
inspect_source(cop, 'def change; add_concurrent_index :table, :column; end')
|
||||
inspect_source('def change; add_concurrent_index :table, :column; end')
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
|
|
@ -53,7 +53,7 @@ describe RuboCop::Cop::Migration::AddTimestamps do
|
|||
end
|
||||
|
||||
it 'registers an offense when the "add_timestamps" method is used' do
|
||||
inspect_source(cop, migration_with_add_timestamps)
|
||||
inspect_source(migration_with_add_timestamps)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -62,7 +62,7 @@ describe RuboCop::Cop::Migration::AddTimestamps do
|
|||
end
|
||||
|
||||
it 'does not register an offense when the "add_timestamps" method is not used' do
|
||||
inspect_source(cop, migration_without_add_timestamps)
|
||||
inspect_source(migration_without_add_timestamps)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
|
@ -70,7 +70,7 @@ describe RuboCop::Cop::Migration::AddTimestamps do
|
|||
end
|
||||
|
||||
it 'does not register an offense when the "add_timestamps_with_timezone" method is used' do
|
||||
inspect_source(cop, migration_with_add_timestamps_with_timezone)
|
||||
inspect_source(migration_with_add_timestamps_with_timezone)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
|
@ -80,9 +80,9 @@ describe RuboCop::Cop::Migration::AddTimestamps do
|
|||
|
||||
context 'outside of migration' do
|
||||
it 'registers no offense' do
|
||||
inspect_source(cop, migration_with_add_timestamps)
|
||||
inspect_source(cop, migration_without_add_timestamps)
|
||||
inspect_source(cop, migration_with_add_timestamps_with_timezone)
|
||||
inspect_source(migration_with_add_timestamps)
|
||||
inspect_source(migration_without_add_timestamps)
|
||||
inspect_source(migration_with_add_timestamps_with_timezone)
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
|
|
@ -67,7 +67,7 @@ describe RuboCop::Cop::Migration::Datetime do
|
|||
end
|
||||
|
||||
it 'registers an offense when the ":datetime" data type is used' do
|
||||
inspect_source(cop, migration_with_datetime)
|
||||
inspect_source(migration_with_datetime)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -77,7 +77,7 @@ describe RuboCop::Cop::Migration::Datetime do
|
|||
end
|
||||
|
||||
it 'registers an offense when the ":timestamp" data type is used' do
|
||||
inspect_source(cop, migration_with_timestamp)
|
||||
inspect_source(migration_with_timestamp)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -87,7 +87,7 @@ describe RuboCop::Cop::Migration::Datetime do
|
|||
end
|
||||
|
||||
it 'does not register an offense when the ":datetime" data type is not used' do
|
||||
inspect_source(cop, migration_without_datetime)
|
||||
inspect_source(migration_without_datetime)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
|
@ -95,7 +95,7 @@ describe RuboCop::Cop::Migration::Datetime do
|
|||
end
|
||||
|
||||
it 'does not register an offense when the ":datetime_with_timezone" data type is used' do
|
||||
inspect_source(cop, migration_with_datetime_with_timezone)
|
||||
inspect_source(migration_with_datetime_with_timezone)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
|
@ -105,10 +105,10 @@ describe RuboCop::Cop::Migration::Datetime do
|
|||
|
||||
context 'outside of migration' do
|
||||
it 'registers no offense' do
|
||||
inspect_source(cop, migration_with_datetime)
|
||||
inspect_source(cop, migration_with_timestamp)
|
||||
inspect_source(cop, migration_without_datetime)
|
||||
inspect_source(cop, migration_with_datetime_with_timezone)
|
||||
inspect_source(migration_with_datetime)
|
||||
inspect_source(migration_with_timestamp)
|
||||
inspect_source(migration_without_datetime)
|
||||
inspect_source(migration_with_datetime_with_timezone)
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::HashIndex do
|
|||
end
|
||||
|
||||
it 'registers an offense when creating a hash index' do
|
||||
inspect_source(cop, 'def change; add_index :table, :column, using: :hash; end')
|
||||
inspect_source('def change; add_index :table, :column, using: :hash; end')
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -25,7 +25,7 @@ describe RuboCop::Cop::Migration::HashIndex do
|
|||
end
|
||||
|
||||
it 'registers an offense when creating a concurrent hash index' do
|
||||
inspect_source(cop, 'def change; add_concurrent_index :table, :column, using: :hash; end')
|
||||
inspect_source('def change; add_concurrent_index :table, :column, using: :hash; end')
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -34,7 +34,7 @@ describe RuboCop::Cop::Migration::HashIndex do
|
|||
end
|
||||
|
||||
it 'registers an offense when creating a hash index using t.index' do
|
||||
inspect_source(cop, 'def change; t.index :table, :column, using: :hash; end')
|
||||
inspect_source('def change; t.index :table, :column, using: :hash; end')
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -45,7 +45,7 @@ describe RuboCop::Cop::Migration::HashIndex do
|
|||
|
||||
context 'outside of migration' do
|
||||
it 'registers no offense' do
|
||||
inspect_source(cop, 'def change; index :table, :column, using: :hash; end')
|
||||
inspect_source('def change; index :table, :column, using: :hash; end')
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
|
|
@ -21,7 +21,7 @@ describe RuboCop::Cop::Migration::RemoveColumn do
|
|||
end
|
||||
|
||||
it 'registers an offense when remove_column is used in the change method' do
|
||||
inspect_source(cop, source('change'))
|
||||
inspect_source(source('change'))
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -30,7 +30,7 @@ describe RuboCop::Cop::Migration::RemoveColumn do
|
|||
end
|
||||
|
||||
it 'registers an offense when remove_column is used in the up method' do
|
||||
inspect_source(cop, source('up'))
|
||||
inspect_source(source('up'))
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -39,7 +39,7 @@ describe RuboCop::Cop::Migration::RemoveColumn do
|
|||
end
|
||||
|
||||
it 'registers no offense when remove_column is used in the down method' do
|
||||
inspect_source(cop, source('down'))
|
||||
inspect_source(source('down'))
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
@ -52,7 +52,7 @@ describe RuboCop::Cop::Migration::RemoveColumn do
|
|||
end
|
||||
|
||||
it 'registers no offense' do
|
||||
inspect_source(cop, source)
|
||||
inspect_source(source)
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
@ -60,7 +60,7 @@ describe RuboCop::Cop::Migration::RemoveColumn do
|
|||
|
||||
context 'outside of a migration' do
|
||||
it 'registers no offense' do
|
||||
inspect_source(cop, source)
|
||||
inspect_source(source)
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::RemoveConcurrentIndex do
|
|||
end
|
||||
|
||||
it 'registers an offense when remove_concurrent_index is used inside a change method' do
|
||||
inspect_source(cop, 'def change; remove_concurrent_index :table, :column; end')
|
||||
inspect_source('def change; remove_concurrent_index :table, :column; end')
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -25,7 +25,7 @@ describe RuboCop::Cop::Migration::RemoveConcurrentIndex do
|
|||
end
|
||||
|
||||
it 'registers no offense when remove_concurrent_index is used inside an up method' do
|
||||
inspect_source(cop, 'def up; remove_concurrent_index :table, :column; end')
|
||||
inspect_source('def up; remove_concurrent_index :table, :column; end')
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
@ -33,7 +33,7 @@ describe RuboCop::Cop::Migration::RemoveConcurrentIndex do
|
|||
|
||||
context 'outside of migration' do
|
||||
it 'registers no offense' do
|
||||
inspect_source(cop, 'def change; remove_concurrent_index :table, :column; end')
|
||||
inspect_source('def change; remove_concurrent_index :table, :column; end')
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::RemoveIndex do
|
|||
end
|
||||
|
||||
it 'registers an offense when remove_index is used' do
|
||||
inspect_source(cop, 'def change; remove_index :table, :column; end')
|
||||
inspect_source('def change; remove_index :table, :column; end')
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -27,7 +27,7 @@ describe RuboCop::Cop::Migration::RemoveIndex do
|
|||
|
||||
context 'outside of migration' do
|
||||
it 'registers no offense' do
|
||||
inspect_source(cop, 'def change; remove_index :table, :column; end')
|
||||
inspect_source('def change; remove_index :table, :column; end')
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::ReversibleAddColumnWithDefault do
|
|||
end
|
||||
|
||||
it 'registers an offense when add_column_with_default is used inside a change method' do
|
||||
inspect_source(cop, 'def change; add_column_with_default :table, :column, default: false; end')
|
||||
inspect_source('def change; add_column_with_default :table, :column, default: false; end')
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -25,7 +25,7 @@ describe RuboCop::Cop::Migration::ReversibleAddColumnWithDefault do
|
|||
end
|
||||
|
||||
it 'registers no offense when add_column_with_default is used inside an up method' do
|
||||
inspect_source(cop, 'def up; add_column_with_default :table, :column, default: false; end')
|
||||
inspect_source('def up; add_column_with_default :table, :column, default: false; end')
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
@ -33,7 +33,7 @@ describe RuboCop::Cop::Migration::ReversibleAddColumnWithDefault do
|
|||
|
||||
context 'outside of migration' do
|
||||
it 'registers no offense' do
|
||||
inspect_source(cop, 'def change; add_column_with_default :table, :column, default: false; end')
|
||||
inspect_source('def change; add_column_with_default :table, :column, default: false; end')
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do
|
|||
sources_and_offense.each do |source, offense|
|
||||
context "given the source \"#{source}\"" do
|
||||
it "registers the offense matching \"#{offense}\"" do
|
||||
inspect_source(cop, source)
|
||||
inspect_source(source)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.first.message).to match(offense)
|
||||
|
@ -49,7 +49,7 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do
|
|||
inoffensive_sources.each do |source|
|
||||
context "given the source \"#{source}\"" do
|
||||
it "registers no offense" do
|
||||
inspect_source(cop, source)
|
||||
inspect_source(source)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses).to be_empty
|
||||
|
@ -61,14 +61,14 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do
|
|||
end
|
||||
|
||||
it 'registers no offense for tables not listed in SMALL_TABLES' do
|
||||
inspect_source(cop, "add_column :large_table, :column, :boolean")
|
||||
inspect_source("add_column :large_table, :column, :boolean")
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
||||
it 'registers no offense for non-boolean columns' do
|
||||
table = described_class::SMALL_TABLES.sample
|
||||
inspect_source(cop, "add_column :#{table}, :column, :string")
|
||||
inspect_source("add_column :#{table}, :column, :string")
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
@ -77,7 +77,7 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do
|
|||
context 'outside of migration' do
|
||||
it 'registers no offense' do
|
||||
table = described_class::SMALL_TABLES.sample
|
||||
inspect_source(cop, "add_column :#{table}, :column, :boolean")
|
||||
inspect_source("add_column :#{table}, :column, :boolean")
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
|
|
@ -62,7 +62,7 @@ describe RuboCop::Cop::Migration::Timestamps do
|
|||
end
|
||||
|
||||
it 'registers an offense when the "timestamps" method is used' do
|
||||
inspect_source(cop, migration_with_timestamps)
|
||||
inspect_source(migration_with_timestamps)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -71,7 +71,7 @@ describe RuboCop::Cop::Migration::Timestamps do
|
|||
end
|
||||
|
||||
it 'does not register an offense when the "timestamps" method is not used' do
|
||||
inspect_source(cop, migration_without_timestamps)
|
||||
inspect_source(migration_without_timestamps)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
|
@ -79,7 +79,7 @@ describe RuboCop::Cop::Migration::Timestamps do
|
|||
end
|
||||
|
||||
it 'does not register an offense when the "timestamps_with_timezone" method is used' do
|
||||
inspect_source(cop, migration_with_timestamps_with_timezone)
|
||||
inspect_source(migration_with_timestamps_with_timezone)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
|
@ -89,9 +89,9 @@ describe RuboCop::Cop::Migration::Timestamps do
|
|||
|
||||
context 'outside of migration' do
|
||||
it 'registers no offense' do
|
||||
inspect_source(cop, migration_with_timestamps)
|
||||
inspect_source(cop, migration_without_timestamps)
|
||||
inspect_source(cop, migration_with_timestamps_with_timezone)
|
||||
inspect_source(migration_with_timestamps)
|
||||
inspect_source(migration_without_timestamps)
|
||||
inspect_source(migration_with_timestamps_with_timezone)
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
require 'rubocop'
|
||||
require 'rubocop/rspec/support'
|
||||
|
||||
require_relative '../../../../rubocop/cop/migration/update_column_in_batches'
|
||||
|
||||
describe RuboCop::Cop::Migration::UpdateColumnInBatches do
|
||||
|
@ -25,7 +27,7 @@ describe RuboCop::Cop::Migration::UpdateColumnInBatches do
|
|||
|
||||
context 'outside of a migration' do
|
||||
it 'does not register any offenses' do
|
||||
inspect_source(cop, migration_code)
|
||||
inspect_source(migration_code)
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
@ -49,7 +51,7 @@ describe RuboCop::Cop::Migration::UpdateColumnInBatches do
|
|||
let(:relative_spec_filepath) { Pathname.new(spec_filepath).relative_path_from(tmp_rails_root) }
|
||||
|
||||
it 'registers an offense when using update_column_in_batches' do
|
||||
inspect_source(cop, migration_code, @migration_file)
|
||||
inspect_source(migration_code, @migration_file)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -72,7 +74,7 @@ describe RuboCop::Cop::Migration::UpdateColumnInBatches do
|
|||
end
|
||||
|
||||
it 'does not register any offenses' do
|
||||
inspect_source(cop, migration_code, @migration_file)
|
||||
inspect_source(migration_code, @migration_file)
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do
|
|||
shared_examples 'large tables' do |update_method|
|
||||
described_class::LARGE_TABLES.each do |table|
|
||||
it "registers an offense for the #{table} table" do
|
||||
inspect_source(cop, "#{update_method} :#{table}, :column, default: true")
|
||||
inspect_source("#{update_method} :#{table}, :column, default: true")
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -37,7 +37,7 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do
|
|||
end
|
||||
|
||||
it 'registers no offense for non-blacklisted tables' do
|
||||
inspect_source(cop, "add_column_with_default :table, :column, default: true")
|
||||
inspect_source("add_column_with_default :table, :column, default: true")
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
@ -45,7 +45,7 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do
|
|||
it 'registers no offense for non-blacklisted methods' do
|
||||
table = described_class::LARGE_TABLES.sample
|
||||
|
||||
inspect_source(cop, "some_other_method :#{table}, :column, default: true")
|
||||
inspect_source("some_other_method :#{table}, :column, default: true")
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
@ -55,13 +55,13 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do
|
|||
let(:table) { described_class::LARGE_TABLES.sample }
|
||||
|
||||
it 'registers no offense for add_column_with_default' do
|
||||
inspect_source(cop, "add_column_with_default :#{table}, :column, default: true")
|
||||
inspect_source("add_column_with_default :#{table}, :column, default: true")
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
||||
it 'registers no offense for update_column_in_batches' do
|
||||
inspect_source(cop, "add_column_with_default :#{table}, :column, default: true")
|
||||
inspect_source("add_column_with_default :#{table}, :column, default: true")
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
require 'spec_helper'
|
||||
require 'rubocop'
|
||||
require 'rubocop/rspec/support'
|
||||
require_relative '../../../rubocop/cop/polymorphic_associations'
|
||||
|
||||
describe RuboCop::Cop::PolymorphicAssociations do
|
||||
include CopHelper
|
||||
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context 'inside the app/models directory' do
|
||||
it 'registers an offense when polymorphic: true is used' do
|
||||
allow(cop).to receive(:in_model?).and_return(true)
|
||||
|
||||
inspect_source(cop, 'belongs_to :foo, polymorphic: true')
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
expect(cop.offenses.map(&:line)).to eq([1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'outside the app/models directory' do
|
||||
it 'does nothing' do
|
||||
allow(cop).to receive(:in_model?).and_return(false)
|
||||
|
||||
inspect_source(cop, 'belongs_to :foo, polymorphic: true')
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
|
@ -15,7 +15,7 @@ describe RuboCop::Cop::ProjectPathHelper do
|
|||
let(:correct_source) { 'edit_project_issue_path(@issue.project, @issue)' }
|
||||
|
||||
it 'registers an offense' do
|
||||
inspect_source(cop, source)
|
||||
inspect_source(source)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -25,7 +25,7 @@ describe RuboCop::Cop::ProjectPathHelper do
|
|||
end
|
||||
|
||||
it 'autocorrects to the right version' do
|
||||
autocorrected = autocorrect_source(cop, source)
|
||||
autocorrected = autocorrect_source(source)
|
||||
|
||||
expect(autocorrected).to eq(correct_source)
|
||||
end
|
||||
|
@ -33,7 +33,7 @@ describe RuboCop::Cop::ProjectPathHelper do
|
|||
|
||||
context 'when using namespace_project with a different namespace' do
|
||||
it 'registers no offense' do
|
||||
inspect_source(cop, 'edit_namespace_project_issue_path(namespace, project)')
|
||||
inspect_source('edit_namespace_project_issue_path(namespace, project)')
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
require 'rubocop'
|
||||
require 'rubocop/rspec/support'
|
||||
|
||||
require_relative '../../../rubocop/cop/redirect_with_status'
|
||||
|
||||
describe RuboCop::Cop::RedirectWithStatus do
|
||||
include CopHelper
|
||||
|
||||
subject(:cop) { described_class.new }
|
||||
let(:controller_fixture_without_status) do
|
||||
%q(
|
||||
class UserController < ApplicationController
|
||||
def show
|
||||
user = User.find(params[:id])
|
||||
redirect_to user_path if user.name == 'John Wick'
|
||||
end
|
||||
|
||||
def destroy
|
||||
user = User.find(params[:id])
|
||||
|
||||
if user.destroy
|
||||
redirect_to root_path
|
||||
else
|
||||
render :show
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
let(:controller_fixture_with_status) do
|
||||
%q(
|
||||
class UserController < ApplicationController
|
||||
def show
|
||||
user = User.find(params[:id])
|
||||
redirect_to user_path if user.name == 'John Wick'
|
||||
end
|
||||
|
||||
def destroy
|
||||
user = User.find(params[:id])
|
||||
|
||||
if user.destroy
|
||||
redirect_to root_path, status: 302
|
||||
else
|
||||
render :show
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
context 'in controller' do
|
||||
before do
|
||||
allow(cop).to receive(:in_controller?).and_return(true)
|
||||
end
|
||||
|
||||
it 'registers an offense when a "destroy" action uses "redirect_to" without "status"' do
|
||||
inspect_source(cop, controller_fixture_without_status)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
expect(cop.offenses.map(&:line)).to eq([12]) # 'redirect_to' is located on 12th line in controller_fixture.
|
||||
expect(cop.highlights).to eq(['redirect_to'])
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not register an offense when a "destroy" action uses "redirect_to" with "status"' do
|
||||
inspect_source(cop, controller_fixture_with_status)
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'outside of controller' do
|
||||
it 'registers no offense' do
|
||||
inspect_source(cop, controller_fixture_without_status)
|
||||
inspect_source(cop, controller_fixture_with_status)
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -17,7 +17,7 @@ describe RuboCop::Cop::RSpec::EnvAssignment do
|
|||
|
||||
shared_examples 'an offensive ENV#[]= call' do |content|
|
||||
it "registers an offense for `#{content}`" do
|
||||
inspect_source(cop, content, source_file)
|
||||
inspect_source(content, source_file)
|
||||
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
expect(cop.offenses.map(&:line)).to eq([1])
|
||||
|
@ -27,7 +27,7 @@ describe RuboCop::Cop::RSpec::EnvAssignment do
|
|||
|
||||
shared_examples 'an autocorrected ENV#[]= call' do |content, autocorrected_content|
|
||||
it "registers an offense for `#{content}` and autocorrects it to `#{autocorrected_content}`" do
|
||||
autocorrected = autocorrect_source(cop, content, source_file)
|
||||
autocorrected = autocorrect_source(content, source_file)
|
||||
|
||||
expect(autocorrected).to eql(autocorrected_content)
|
||||
end
|
||||
|
@ -51,7 +51,7 @@ describe RuboCop::Cop::RSpec::EnvAssignment do
|
|||
|
||||
context 'outside of a spec file' do
|
||||
it "does not register an offense for `#{OFFENSE_CALL_SINGLE_QUOTES_KEY}` in a non-spec file" do
|
||||
inspect_source(cop, OFFENSE_CALL_SINGLE_QUOTES_KEY)
|
||||
inspect_source(OFFENSE_CALL_SINGLE_QUOTES_KEY)
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
require 'rubocop'
|
||||
require 'rubocop/rspec/support'
|
||||
|
||||
require_relative '../../../../rubocop/cop/rspec/single_line_hook'
|
||||
|
||||
describe RuboCop::Cop::RSpec::SingleLineHook do
|
||||
include CopHelper
|
||||
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
# Override `CopHelper#inspect_source` to always appear to be in a spec file,
|
||||
# so that our RSpec-only cop actually runs
|
||||
def inspect_source(*args)
|
||||
super(*args, 'foo_spec.rb')
|
||||
end
|
||||
|
||||
it 'registers an offense for a single-line `before` block' do
|
||||
inspect_source(cop, 'before { do_something }')
|
||||
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
expect(cop.offenses.map(&:line)).to eq([1])
|
||||
expect(cop.highlights).to eq(['before { do_something }'])
|
||||
end
|
||||
|
||||
it 'registers an offense for a single-line `after` block' do
|
||||
inspect_source(cop, 'after(:each) { undo_something }')
|
||||
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
expect(cop.offenses.map(&:line)).to eq([1])
|
||||
expect(cop.highlights).to eq(['after(:each) { undo_something }'])
|
||||
end
|
||||
|
||||
it 'registers an offense for a single-line `around` block' do
|
||||
inspect_source(cop, 'around { |ex| do_something_else }')
|
||||
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
expect(cop.offenses.map(&:line)).to eq([1])
|
||||
expect(cop.highlights).to eq(['around { |ex| do_something_else }'])
|
||||
end
|
||||
|
||||
it 'ignores a multi-line `before` block' do
|
||||
inspect_source(cop, ['before do',
|
||||
' do_something',
|
||||
'end'])
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
||||
it 'ignores a multi-line `after` block' do
|
||||
inspect_source(cop, ['after(:each) do',
|
||||
' undo_something',
|
||||
'end'])
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
|
||||
it 'ignores a multi-line `around` block' do
|
||||
inspect_source(cop, ['around do |ex|',
|
||||
' do_something_else',
|
||||
'end'])
|
||||
|
||||
expect(cop.offenses.size).to eq(0)
|
||||
end
|
||||
end
|
|
@ -1,53 +0,0 @@
|
|||
require 'spec_helper'
|
||||
require 'rubocop'
|
||||
require 'rubocop/rspec/support'
|
||||
require_relative '../../../../rubocop/cop/rspec/verbose_include_metadata'
|
||||
|
||||
describe RuboCop::Cop::RSpec::VerboseIncludeMetadata do
|
||||
include CopHelper
|
||||
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
let(:source_file) { 'foo_spec.rb' }
|
||||
|
||||
# Override `CopHelper#inspect_source` to always appear to be in a spec file,
|
||||
# so that our RSpec-only cop actually runs
|
||||
def inspect_source(*args)
|
||||
super(*args, source_file)
|
||||
end
|
||||
|
||||
shared_examples 'examples with include syntax' do |title|
|
||||
it "flags violation for #{title} examples that uses verbose include syntax" do
|
||||
inspect_source(cop, "#{title} 'Test', js: true do; end")
|
||||
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
offense = cop.offenses.first
|
||||
|
||||
expect(offense.line).to eq(1)
|
||||
expect(cop.highlights).to eq(["#{title} 'Test', js: true"])
|
||||
expect(offense.message).to eq('Use `:js` instead of `js: true`.')
|
||||
end
|
||||
|
||||
it "doesn't flag violation for #{title} examples that uses compact include syntax", :aggregate_failures do
|
||||
inspect_source(cop, "#{title} 'Test', :js do; end")
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
||||
it "doesn't flag violation for #{title} examples that uses flag: symbol" do
|
||||
inspect_source(cop, "#{title} 'Test', flag: :symbol do; end")
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
||||
it "autocorrects #{title} examples that uses verbose syntax into compact syntax" do
|
||||
autocorrected = autocorrect_source(cop, "#{title} 'Test', js: true do; end", source_file)
|
||||
|
||||
expect(autocorrected).to eql("#{title} 'Test', :js do; end")
|
||||
end
|
||||
end
|
||||
|
||||
%w(describe context feature example_group it specify example scenario its).each do |example|
|
||||
it_behaves_like 'examples with include syntax', example
|
||||
end
|
||||
end
|
|
@ -1,6 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
require 'rubocop'
|
||||
require 'rubocop/rspec/support'
|
||||
|
||||
require_relative '../../../rubocop/cop/sidekiq_options_queue'
|
||||
|
||||
describe RuboCop::Cop::SidekiqOptionsQueue do
|
||||
|
@ -9,7 +11,7 @@ describe RuboCop::Cop::SidekiqOptionsQueue do
|
|||
subject(:cop) { described_class.new }
|
||||
|
||||
it 'registers an offense when `sidekiq_options` is used with the `queue` option' do
|
||||
inspect_source(cop, 'sidekiq_options queue: "some_queue"')
|
||||
inspect_source('sidekiq_options queue: "some_queue"')
|
||||
|
||||
aggregate_failures do
|
||||
expect(cop.offenses.size).to eq(1)
|
||||
|
@ -19,7 +21,7 @@ describe RuboCop::Cop::SidekiqOptionsQueue do
|
|||
end
|
||||
|
||||
it 'does not register an offense when `sidekiq_options` is used with another option' do
|
||||
inspect_source(cop, 'sidekiq_options retry: false')
|
||||
inspect_source('sidekiq_options retry: false')
|
||||
|
||||
expect(cop.offenses).to be_empty
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue