Commit 944ff4a6 authored by Markus Koller's avatar Markus Koller

Remove custom Danger check for frozen_string_literal comments

This is redundant with Rubocop's Style/FrozenStringLiteralComment cop,
which we didn't have enabled when this was introduced.

To preserve the same behaviour we also:

- Switch to `EnforcedStyle: always_true`, to forbid `false` values.
- Replace the wildcard list with an explicit list of all violations,
  so we still catch all newly added files.
parent 83c7e006
...@@ -78,21 +78,7 @@ Style/AccessModifierDeclarations: ...@@ -78,21 +78,7 @@ Style/AccessModifierDeclarations:
# Frozen String Literal # Frozen String Literal
Style/FrozenStringLiteralComment: Style/FrozenStringLiteralComment:
Enabled: true Enabled: true
Exclude: EnforcedStyle: always_true
- 'config.ru'
- 'Dangerfile'
- 'Gemfile'
- 'Rakefile'
- 'app/views/**/*'
- 'config/**/*'
- 'danger/**/*'
- 'db/**/*'
- 'ee/db/**/*'
- 'ee/lib/tasks/**/*'
- 'lib/tasks/**/*'
- 'qa/**/*'
- 'rubocop/**/*'
- 'scripts/**/*'
RSpec/FilePath: RSpec/FilePath:
Exclude: Exclude:
......
...@@ -2721,3 +2721,315 @@ Gitlab/NamespacedClass: ...@@ -2721,3 +2721,315 @@ Gitlab/NamespacedClass:
- 'spec/support/sidekiq_middleware.rb' - 'spec/support/sidekiq_middleware.rb'
- 'spec/tasks/gitlab/task_helpers_spec.rb' - 'spec/tasks/gitlab/task_helpers_spec.rb'
- 'spec/uploaders/object_storage_spec.rb' - 'spec/uploaders/object_storage_spec.rb'
# WIP: https://gitlab.com/gitlab-org/gitlab/-/issues/299105
Style/FrozenStringLiteralComment:
Exclude:
- 'Gemfile'
- 'Rakefile'
- 'app/views/dashboard/issues.atom.builder'
- 'app/views/dashboard/projects/index.atom.builder'
- 'app/views/events/_event.atom.builder'
- 'app/views/groups/issues.atom.builder'
- 'app/views/groups/show.atom.builder'
- 'app/views/issues/_issue.atom.builder'
- 'app/views/issues/_issues_calendar.ics.ruby'
- 'app/views/layouts/xml.atom.builder'
- 'app/views/projects/commits/_commit.atom.builder'
- 'app/views/projects/commits/show.atom.builder'
- 'app/views/projects/issues/index.atom.builder'
- 'app/views/projects/show.atom.builder'
- 'app/views/projects/tags/_tag.atom.builder'
- 'app/views/projects/tags/index.atom.builder'
- 'app/views/users/show.atom.builder'
- 'bin/secpick'
- 'config.ru'
- 'config/boot.rb'
- 'config/environment.rb'
- 'config/environments/development.rb'
- 'config/environments/production.rb'
- 'config/environments/test.rb'
- 'config/initializers/01_secret_token.rb'
- 'config/initializers/0_acts_as_taggable.rb'
- 'config/initializers/0_inject_feature_flags.rb'
- 'config/initializers/0_post_deployment_migrations.rb'
- 'config/initializers/1_settings.rb'
- 'config/initializers/2_gitlab.rb'
- 'config/initializers/5_backend.rb'
- 'config/initializers/6_validations.rb'
- 'config/initializers/7_prometheus_metrics.rb'
- 'config/initializers/7_redis.rb'
- 'config/initializers/8_devise.rb'
- 'config/initializers/8_gitaly.rb'
- 'config/initializers/9_fast_gettext.rb'
- 'config/initializers/action_dispatch_http_mime_negotiation.rb'
- 'config/initializers/action_mailer_hooks.rb'
- 'config/initializers/active_record_data_types.rb'
- 'config/initializers/active_record_ping.rb'
- 'config/initializers/active_record_preloader.rb'
- 'config/initializers/active_record_schema_ignore_tables.rb'
- 'config/initializers/active_record_table_definition.rb'
- 'config/initializers/ar_speed_up_migration_checking.rb'
- 'config/initializers/asset_proxy_settings.rb'
- 'config/initializers/attr_encrypted_no_db_connection.rb'
- 'config/initializers/backtrace_silencers.rb'
- 'config/initializers/batch_loader.rb'
- 'config/initializers/bootstrap_form.rb'
- 'config/initializers/bullet.rb'
- 'config/initializers/cluster_events_before_phased_restart.rb'
- 'config/initializers/console_message.rb'
- 'config/initializers/cookies_serializer.rb'
- 'config/initializers/date_time_formats.rb'
- 'config/initializers/default_url_options.rb'
- 'config/initializers/deprecations.rb'
- 'config/initializers/direct_upload_support.rb'
- 'config/initializers/doorkeeper.rb'
- 'config/initializers/doorkeeper_openid_connect.rb'
- 'config/initializers/etag_caching.rb'
- 'config/initializers/fill_shards.rb'
- 'config/initializers/fix_local_cache_middleware.rb'
- 'config/initializers/fog_google_https_private_urls.rb'
- 'config/initializers/forbid_sidekiq_in_transactions.rb'
- 'config/initializers/gettext_rails_i18n_patch.rb'
- 'config/initializers/gitlab_kas_secret.rb'
- 'config/initializers/gitlab_shell_secret_token.rb'
- 'config/initializers/gitlab_workhorse_secret.rb'
- 'config/initializers/go_get.rb'
- 'config/initializers/grpc.rb'
- 'config/initializers/hamlit.rb'
- 'config/initializers/health_check.rb'
- 'config/initializers/http_hostname_override.rb'
- 'config/initializers/kaminari_active_record_relation_methods_with_limit.rb'
- 'config/initializers/kaminari_config.rb'
- 'config/initializers/lograge.rb'
- 'config/initializers/mail_encoding_patch.rb'
- 'config/initializers/mime_types.rb'
- 'config/initializers/mini_magick.rb'
- 'config/initializers/new_framework_defaults.rb'
- 'config/initializers/octokit.rb'
- 'config/initializers/omniauth.rb'
- 'config/initializers/peek.rb'
- 'config/initializers/postgresql_cte.rb'
- 'config/initializers/premailer.rb'
- 'config/initializers/query_limiting.rb'
- 'config/initializers/rack_lineprof.rb'
- 'config/initializers/relative_naming_ci_namespace.rb'
- 'config/initializers/request_context.rb'
- 'config/initializers/request_profiler.rb'
- 'config/initializers/routing_draw.rb'
- 'config/initializers/sentry.rb'
- 'config/initializers/server_uptime.rb'
- 'config/initializers/session_store.rb'
- 'config/initializers/sherlock.rb'
- 'config/initializers/sprockets.rb'
- 'config/initializers/static_files.rb'
- 'config/initializers/time_zone.rb'
- 'config/initializers/trusted_proxies.rb'
- 'config/initializers/warden.rb'
- 'config/initializers/workhorse_multipart.rb'
- 'config/initializers/wrap_parameters.rb'
- 'config/initializers/zz_metrics.rb'
- 'config/initializers_before_autoloader/000_inflections.rb'
- 'config/object_store_settings.rb'
- 'config/routes.rb'
- 'config/routes/admin.rb'
- 'config/routes/api.rb'
- 'config/routes/dashboard.rb'
- 'config/routes/development.rb'
- 'config/routes/explore.rb'
- 'config/routes/git_http.rb'
- 'config/routes/google_api.rb'
- 'config/routes/help.rb'
- 'config/routes/import.rb'
- 'config/routes/legacy_builds.rb'
- 'config/routes/repository.rb'
- 'config/routes/sherlock.rb'
- 'config/routes/sidekiq.rb'
- 'config/routes/snippets.rb'
- 'config/routes/uploads.rb'
- 'config/routes/wiki.rb'
- 'config/smime_signature_settings.rb'
- 'config/spring.rb'
- 'danger/changes_size/Dangerfile'
- 'danger/metadata/Dangerfile'
- 'db/migrate/20190325080727_truncate_user_fullname.rb'
- 'db/migrate/20190828110802_add_not_null_constraints_to_prometheus_metrics_y_label_and_unit.rb'
- 'db/migrate/20190828172831_create_package_tag.rb'
- 'db/migrate/20191003195218_add_pendo_enabled_to_application_settings.rb'
- 'db/migrate/20191003195620_add_pendo_url_to_application_settings.rb'
- 'db/migrate/20191120200015_add_index_to_grafana_integrations.rb'
- 'db/migrate/20200229171700_create_custom_emojis.rb'
- 'db/migrate/20201004163918_remove_project_id_and_id_index_from_vulnerabilities_table.rb'
- 'db/migrate/20201214000000_change_mr_allow_maintainer_to_push_default.rb'
- 'db/optional_migrations/composite_primary_keys.rb'
- 'db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb'
- 'db/post_migrate/20201030121314_schedule_update_existing_users_that_require_two_factor_auth.rb'
- 'ee/db/fixtures/development/20_burndown.rb'
- 'ee/db/fixtures/development/20_vulnerabilities.rb'
- 'ee/db/fixtures/development/22_epics.rb'
- 'ee/db/geo/migrate/20170206203234_create_project_registry.rb'
- 'ee/db/geo/migrate/20170223033541_create_file_registry.rb'
- 'ee/db/geo/migrate/20170302005747_add_index_to_project_id_on_project_registry.rb'
- 'ee/db/geo/migrate/20170526214010_convert_file_bytes_to_int64.rb'
- 'ee/db/geo/migrate/20170605154253_create_event_log_state.rb'
- 'ee/db/geo/migrate/20170606155045_add_needs_resync_to_project_registry.rb'
- 'ee/db/geo/migrate/20170614201943_add_last_wiki_synced_at_to_project_registry.rb'
- 'ee/db/geo/migrate/20170627195211_add_index_to_project_registry.rb'
- 'ee/db/geo/migrate/20170906174622_remove_duplicates_from_project_registry.rb'
- 'ee/db/geo/migrate/20170906182752_add_unique_index_to_project_id_on_project_registry.rb'
- 'ee/db/geo/migrate/20171005045404_remove_file_uploads_from_registry.rb'
- 'ee/db/geo/migrate/20171009162208_add_file_registry_success.rb'
- 'ee/db/geo/migrate/20171009162209_add_file_registry_success_index.rb'
- 'ee/db/geo/migrate/20171101105200_add_retry_count_fields_to_registries.rb'
- 'ee/db/geo/migrate/20171115143841_add_last_sync_failure_to_project_registry.rb'
- 'ee/db/geo/migrate/20180201154345_add_repository_verification_to_project_registry.rb'
- 'ee/db/geo/migrate/20180314175612_add_partial_index_to_project_registy_verification_failure_columns.rb'
- 'ee/db/geo/migrate/20180315222132_add_partial_index_to_project_registy_checksum_columns.rb'
- 'ee/db/geo/migrate/20180321144947_change_repository_verification_checksum_to_sha.rb'
- 'ee/db/geo/migrate/20180322062741_migrate_ci_job_artifacts_to_separate_registry.rb'
- 'ee/db/geo/migrate/20180323182105_add_missing_on_primary_to_file_registry.rb'
- 'ee/db/geo/migrate/20180327071612_add_partial_index_to_project_registy_checksum_sha_columns.rb'
- 'ee/db/geo/migrate/20180402170913_add_missing_on_primary_to_job_artifact_registry..rb'
- 'ee/db/geo/migrate/20180405074130_add_partial_index_project_repository_verification.rb'
- 'ee/db/geo/migrate/20180412213305_add_index_to_artifact_id_on_job_artifact_registry.rb'
- 'ee/db/geo/migrate/20180419174834_add_checksum_mismatch_fields_to_project_registry.rb'
- 'ee/db/geo/migrate/20180419192603_add_indexes_to_checksum_mismatch_fields_on_project_registry.rb'
- 'ee/db/geo/migrate/20180427114641_add_repository_check_to_geo_project_registry.rb'
- 'ee/db/geo/migrate/20180510223634_set_resync_flag_for_retried_projects.rb'
- 'ee/db/geo/migrate/20180613184349_add_resync_was_scheduled_at_to_project_registry.rb'
- 'ee/db/geo/post_migrate/20180320011914_remove_last_verification_failed_columns_from_geo_project_registry.rb'
- 'ee/db/geo/post_migrate/20180320013929_remove_last_verification_at_columns_from_geo_project_registry.rb'
- 'ee/db/geo/post_migrate/20180326171626_remove_old_repository_verification_checksum_from_geo_project_registry.rb'
- 'ee/db/geo/post_migrate/20180331055706_delete_job_artifacts_from_file_registry.rb'
- 'ee/lib/tasks/geo.rake'
- 'ee/lib/tasks/geo/git.rake'
- 'ee/lib/tasks/geo/replication.rake'
- 'ee/lib/tasks/gitlab/db.rake'
- 'ee/lib/tasks/gitlab/elastic.rake'
- 'ee/lib/tasks/gitlab/elastic/test.rake'
- 'ee/lib/tasks/gitlab/geo.rake'
- 'ee/lib/tasks/gitlab/indexer.rake'
- 'ee/lib/tasks/gitlab/ldap.rake'
- 'ee/lib/tasks/gitlab/seed/insights.rake'
- 'ee/lib/tasks/gitlab/seed/metrics.rake'
- 'ee/lib/tasks/migrate/ldap.rake'
- 'lib/tasks/brakeman.rake'
- 'lib/tasks/cache.rake'
- 'lib/tasks/ci/cleanup.rake'
- 'lib/tasks/cleanup.rake'
- 'lib/tasks/config_lint.rake'
- 'lib/tasks/db_obsolete_ignored_columns.rake'
- 'lib/tasks/dev.rake'
- 'lib/tasks/downtime_check.rake'
- 'lib/tasks/eslint.rake'
- 'lib/tasks/file_hooks.rake'
- 'lib/tasks/frontend.rake'
- 'lib/tasks/gemojione.rake'
- 'lib/tasks/gitlab/artifacts/check.rake'
- 'lib/tasks/gitlab/artifacts/migrate.rake'
- 'lib/tasks/gitlab/backup.rake'
- 'lib/tasks/gitlab/bulk_add_permission.rake'
- 'lib/tasks/gitlab/check.rake'
- 'lib/tasks/gitlab/container_registry.rake'
- 'lib/tasks/gitlab/db.rake'
- 'lib/tasks/gitlab/doctor/secrets.rake'
- 'lib/tasks/gitlab/exclusive_lease.rake'
- 'lib/tasks/gitlab/external_diffs.rake'
- 'lib/tasks/gitlab/features.rake'
- 'lib/tasks/gitlab/generate_sample_prometheus_data.rake'
- 'lib/tasks/gitlab/git.rake'
- 'lib/tasks/gitlab/gitaly.rake'
- 'lib/tasks/gitlab/helpers.rake'
- 'lib/tasks/gitlab/import.rake'
- 'lib/tasks/gitlab/import_export.rake'
- 'lib/tasks/gitlab/info.rake'
- 'lib/tasks/gitlab/ldap.rake'
- 'lib/tasks/gitlab/lfs/check.rake'
- 'lib/tasks/gitlab/lfs/migrate.rake'
- 'lib/tasks/gitlab/list_repos.rake'
- 'lib/tasks/gitlab/packages/events.rake'
- 'lib/tasks/gitlab/packages/migrate.rake'
- 'lib/tasks/gitlab/pages.rake'
- 'lib/tasks/gitlab/praefect.rake'
- 'lib/tasks/gitlab/seed.rake'
- 'lib/tasks/gitlab/setup.rake'
- 'lib/tasks/gitlab/shell.rake'
- 'lib/tasks/gitlab/storage.rake'
- 'lib/tasks/gitlab/tcp_check.rake'
- 'lib/tasks/gitlab/test.rake'
- 'lib/tasks/gitlab/two_factor.rake'
- 'lib/tasks/gitlab/update_templates.rake'
- 'lib/tasks/gitlab/uploads/check.rake'
- 'lib/tasks/gitlab/uploads/migrate.rake'
- 'lib/tasks/gitlab/uploads/sanitize.rake'
- 'lib/tasks/gitlab/usage_data.rake'
- 'lib/tasks/gitlab/user_management.rake'
- 'lib/tasks/gitlab/web_hook.rake'
- 'lib/tasks/gitlab/workhorse.rake'
- 'lib/tasks/gitlab/x509/update.rake'
- 'lib/tasks/gitlab_danger.rake'
- 'lib/tasks/grape.rake'
- 'lib/tasks/haml-lint.rake'
- 'lib/tasks/import.rake'
- 'lib/tasks/karma.rake'
- 'lib/tasks/lint.rake'
- 'lib/tasks/migrate/composite_primary_keys.rake'
- 'lib/tasks/migrate/migrate_iids.rake'
- 'lib/tasks/migrate/setup_postgresql.rake'
- 'lib/tasks/pngquant.rake'
- 'lib/tasks/rubocop.rake'
- 'lib/tasks/scss-lint.rake'
- 'lib/tasks/setup.rake'
- 'lib/tasks/test.rake'
- 'lib/tasks/tokens.rake'
- 'qa/Gemfile'
- 'qa/Rakefile'
- 'qa/bin/qa'
- 'qa/bin/rubymine'
- 'qa/qa/fixtures/auto_devops_rack/Gemfile'
- 'qa/qa/fixtures/auto_devops_rack/Rakefile'
- 'qa/qa/fixtures/auto_devops_rack/config.ru'
- 'qa/qa/page/page_concern.rb'
- 'rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers.rb'
- 'rubocop/cop/gitlab/finder_with_find_by.rb'
- 'rubocop/cop/gitlab/keys-first-and-values-first.rb'
- 'rubocop/cop/gitlab/module_with_instance_variables.rb'
- 'rubocop/cop/gitlab/predicate_memoization.rb'
- 'rubocop/cop/migration/add_concurrent_foreign_key.rb'
- 'rubocop/cop/migration/add_concurrent_index.rb'
- 'rubocop/cop/migration/add_index.rb'
- 'rubocop/cop/migration/add_timestamps.rb'
- 'rubocop/cop/migration/datetime.rb'
- 'rubocop/cop/migration/hash_index.rb'
- 'rubocop/cop/migration/remove_column.rb'
- 'rubocop/cop/migration/remove_concurrent_index.rb'
- 'rubocop/cop/migration/remove_index.rb'
- 'rubocop/cop/migration/safer_boolean_column.rb'
- 'rubocop/cop/migration/timestamps.rb'
- 'rubocop/cop/migration/update_column_in_batches.rb'
- 'rubocop/cop/project_path_helper.rb'
- 'rubocop/migration_helpers.rb'
- 'rubocop/qa_helpers.rb'
- 'scripts/flaky_examples/detect-new-flaky-examples'
- 'scripts/flaky_examples/prune-old-flaky-examples'
- 'scripts/gather-test-memory-data'
- 'scripts/generate-gems-memory-metrics-static'
- 'scripts/generate-gems-size-metrics-static'
- 'scripts/generate-memory-metrics-on-boot'
- 'scripts/generate-test-mapping'
- 'scripts/gitaly-test-build'
- 'scripts/gitaly-test-spawn'
- 'scripts/gitaly_test.rb'
- 'scripts/insert-rspec-profiling-data'
- 'scripts/lint-rugged'
- 'scripts/merge-html-reports'
- 'scripts/merge-reports'
- 'scripts/merge-simplecov'
- 'scripts/no-ee-check'
- 'scripts/pack-test-mapping'
- 'scripts/static-analysis'
- 'scripts/sync-reports'
- 'scripts/unpack-test-mapping'
- 'scripts/update-feature-categories'
- 'scripts/used-feature-flags'
- 'scripts/verify-tff-mapping'
# frozen_string_literal: true
FILE_EXTENSION = ".rb"
FROZEN_STRING_MAGIC_COMMENT = "# frozen_string_literal: true"
SHEBANG_COMMENT = "#!"
def get_files_with_no_magic_comment(files)
files.select do |path|
path.end_with?(FILE_EXTENSION) &&
!file_has_frozen_string_magic_comment?(path)
end
end
def file_has_frozen_string_magic_comment?(path)
File.open(path) do |file|
first_line = file.gets
line_has_frozen_string_magic_comment?(first_line) ||
(line_has_shebang?(first_line) &&
line_has_frozen_string_magic_comment?(file.gets))
end
end
def line_has_frozen_string_magic_comment?(line)
line&.start_with?(FROZEN_STRING_MAGIC_COMMENT)
end
def line_has_shebang?(line)
line&.start_with?(SHEBANG_COMMENT)
end
files_to_fix = get_files_with_no_magic_comment(git.added_files)
if files_to_fix.any?
warn 'This merge request adds files that do not enforce frozen string literal. ' \
'See https://gitlab.com/gitlab-org/gitlab-foss/issues/47424 for more information.'
if GitlabDanger.new(helper.gitlab_helper).ci?
markdown(<<~MARKDOWN)
## Enable Frozen String Literal
The following files should have `#{FROZEN_STRING_MAGIC_COMMENT}` on the first line:
* #{files_to_fix.map { |path| "`#{path}`" }.join("\n* ")}
MARKDOWN
end
end
...@@ -4,7 +4,6 @@ class GitlabDanger ...@@ -4,7 +4,6 @@ class GitlabDanger
LOCAL_RULES ||= %w[ LOCAL_RULES ||= %w[
changes_size changes_size
documentation documentation
frozen_string
duplicate_yarn_dependencies duplicate_yarn_dependencies
prettier prettier
eslint eslint
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment