Performance/FlatMap: Configure EnabledForFlattenWithoutParams: true
What does this MR do and why?
Configure EnabledForFlattenWithoutParams: true
for Performance/FlatMap
Previously, the cop only flagged the following code:
array.map { ... }.flatten(1)
With this configuration it also flags:
array.map { ... }.flatten
Although we must be cautious when fixing existing offenses it's still worth the effort/risk to enable this option.
gitlab-org/gitlab
Impact on Click to expand
Offenses:
app/presenters/packages/nuget/service_index_presenter.rb:38:28: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
available_services.map { |service| build_service(service) } ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/projects/apple_target_platform_detector_service.rb:53:30: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
BUILD_CONFIG_FILENAMES.map do |filename| ...
^^^^^^^^^^^^^^^^^
ee/app/models/burndown.rb:36:8: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
.map { |issue| burndown_events_for(issue) } ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/app/models/geo_node_status.rb:52:37: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
Gitlab::Geo::REPLICATOR_CLASSES.map do |replicable_class| ...
^^^^^^^^^^^^^^^^^^^^^^^^^
ee/app/serializers/dashboard_environments_serializer.rb:28:29: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
environments = projects.map(&:environments_for_dashboard).flatten
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/app/services/elastic/process_bookkeeping_service.rb:75:27: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
keys = SHARDS.map { |m| [redis_set_key(m), redis_score_key(m)] }.flatten
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/lib/elastic/latest/issue_class_proxy.rb:120:35: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
rejected_ids = namespaces.map do |namespace| ...
^^^^^^^^^^^^^^^^^^
ee/spec/lib/elastic/latest/user_class_proxy_spec.rb:91:50: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
fuzzy_keys = fuzzy_query[:bool][:should].map { |s| s[:fuzzy].keys }.flatten
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/spec/lib/elastic/latest/user_class_proxy_spec.rb:106:52: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
fuzzy_keys = fuzzy_query[:bool][:should].map { |s| s[:fuzzy].keys }.flatten
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/spec/models/analytics/issues_analytics_spec.rb:24:17: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
seed_data.map do |month, seed_counters| ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/spec/requests/api/members_spec.rb:1145:34: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
expect(json_response.map(&:keys).flatten).not_to include('group_saml_identity')
^^^^^^^^^^^^^^^^^^^
ee/spec/support/helpers/license_scanning_report_helpers.rb:5:21: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
report.licenses.map { |license| license.dependencies.map(&:path) }.flatten.compact
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/spec/support/shared_examples/finders/security/findings_finder_shared_examples.rb:50:79: C: Performance/FlatMap: Use flat_map instead of collect...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
findings = { artifact_ds => report_ds, artifact_sast => report_sast }.collect do |artifact, report| ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/gitlab/ci/pipeline/chain/create_deployments.rb:19:29: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
pipeline.stages.map(&:statuses).flatten.map(&method(:create_deployment))
^^^^^^^^^^^^^^^^^^^^^^^
lib/gitlab/ci/pipeline/chain/ensure_environments.rb:9:29: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
pipeline.stages.map(&:statuses).flatten.each(&method(:ensure_environment))
^^^^^^^^^^^^^^^^^^^^^^^
lib/gitlab/ci/pipeline/chain/ensure_resource_groups.rb:9:29: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
pipeline.stages.map(&:statuses).flatten.each(&method(:ensure_resource_group))
^^^^^^^^^^^^^^^^^^^^^^^
lib/gitlab/database/query_analyzers/prevent_cross_database_modification.rb:90:63: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
all_tables = context[:modified_tables_by_db].values.map(&:to_a).flatten
^^^^^^^^^^^^^^^^^^^
lib/gitlab/diff/file_collection/base.rb:56:22: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
diff_files.map(&:paths).flatten.uniq
^^^^^^^^^^^^^^^^^^^^
lib/gitlab/instrumentation/redis_cluster_validator.rb:193:27: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
keys = commands.map { |command| extract_keys(command) }.flatten
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/gitlab/testing/request_inspector_middleware.rb:70:12: C: Performance/FlatMap: Use flat_map instead of collect...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
.collect { |k, v| [k.prepend('HTTP_'), v] } ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/gitlab/usage_data_counters/hll_redis_counter.rb:254:50: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
(start_date.to_date..end_date.to_date).map do |date| ...
^^^^^^^^^^^^^
lib/gitlab/usage_data_counters/hll_redis_counter.rb:261:50: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
(start_date.to_date..end_date.to_date).map do |date| ...
^^^^^^^^^^^^^
qa/qa/resource/base.rb:278:34: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
.map { |clazz| clazz.instance_variable_get(:@attribute_names) } ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
qa/qa/tools/ci/non_empty_suites.rb:64:25: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
mod.constants.map do |const| ...
^^^^^^^^^^^^^^
spec/controllers/projects/issues_controller_spec.rb:1897:27: C: Performance/FlatMap: Use flat_map instead of collect...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
json_response.collect { |discussion| discussion["notes"] }.flatten
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/lib/bulk_imports/groups/stage_spec.rb:37:61: C: Performance/FlatMap: Use flat_map instead of collect...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
pipeline_keys = described_class.new(entity).pipelines.collect(&:keys).flatten.uniq
^^^^^^^^^^^^^^^^^^^^^^^
spec/lib/bulk_imports/projects/stage_spec.rb:24:41: C: Performance/FlatMap: Use flat_map instead of collect...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
pipeline_keys = subject.pipelines.collect(&:keys).flatten.uniq
^^^^^^^^^^^^^^^^^^^^^^^
spec/lib/gitlab/ci/parsers/test/junit_spec.rb:475:29: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
test_suite.test_cases.map do |status, value| ...
^^^^^^^^^^^^^^^^^^^^^^
spec/models/ci/pipeline_spec.rb:3278:79: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
child_pipelines_jobs_canceled_by_ids = pipeline.child_pipelines.map(&:statuses).flatten.map(&:auto_canceled_by_id)
^^^^^^^^^^^^^^^^^^^^^^^
spec/requests/api/graphql/ci/pipelines_spec.rb:389:34: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
job_names = pipelines_data.map do |pipeline_data| ...
^^^^^^^^^^^^^^^^^^^^^^
spec/requests/api/graphql/ci/pipelines_spec.rb:496:66: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
downstream_pipelines_graphql_data = pipelines_graphql_data.map { |pip| pip['downstream']['nodes'] }.flatten
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/requests/api/projects_spec.rb:2290:35: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
keys = project_attributes.map do |relation, relation_config| ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/services/ci/create_pipeline_service/evaluate_runner_tags_spec.rb:123:34: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
let(:tags) { pipeline.builds.map(&:tags).flatten.pluck(:name) }
^^^^^^^^^^^^^^^^^^^
spec/services/git/process_ref_changes_service_spec.rb:77:11: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
].map do |change| ...
^^^^^^^^^^^^^^^
spec/support/shared_examples/models/with_debian_distributions_shared_examples.rb:10:45: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
distribution_file_paths = distributions.map do |distribution| ...
^^^^^^^^^^^^^^^^^^^^^
spec/support/shared_examples/requests/api/graphql/issue_list_shared_examples.rb:588:21: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
response_data.map do |node| ...
^^^^^^^^^^^^^
spec/support/shared_examples/requests/api/graphql/issue_list_shared_examples.rb:594:14: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
issues.map(&:labels).flatten.map(&:to_global_id).map(&:to_s)
^^^^^^^^^^^^^^^^^^^^^
spec/support/shared_examples/requests/api/graphql/issue_list_shared_examples.rb:637:21: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
response_data.map do |node| ...
^^^^^^^^^^^^^
spec/support/shared_examples/requests/api/graphql/issue_list_shared_examples.rb:643:14: C: Performance/FlatMap: Use flat_map instead of map...flatten. Beware, flat_map only flattens 1 level and flatten can be used to flatten multiple levels.
issues.map(&:assignees).flatten.map(&:to_global_id).map(&:to_s)
^^^^^^^^^^^^^^^^^^^^^^^^
29570 files inspected, 39 offenses detected
29570 files inspected, 39 offenses detected
Edited by Peter Leitzen