diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-20 00:12:57 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-20 00:12:57 +0000 |
commit | 8277a5b4ba05fe11174397c689c66cef5c06fc38 (patch) | |
tree | c4abbec1509476efbb14c040045ca163042de3bf /tooling/danger/specs/project_factory_suggestion.rb | |
parent | f46a8dbf1a0999e27dfeddd258096ef97def8d64 (diff) | |
download | gitlab-ce-8277a5b4ba05fe11174397c689c66cef5c06fc38.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'tooling/danger/specs/project_factory_suggestion.rb')
-rw-r--r-- | tooling/danger/specs/project_factory_suggestion.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tooling/danger/specs/project_factory_suggestion.rb b/tooling/danger/specs/project_factory_suggestion.rb new file mode 100644 index 00000000000..4e5a70ac8e5 --- /dev/null +++ b/tooling/danger/specs/project_factory_suggestion.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require_relative '../suggestion' + +module Tooling + module Danger + module Specs + class ProjectFactorySuggestion < Suggestion + PROJECT_FACTORIES = %w[ + :project + :project_empty_repo + :forked_project_with_submodules + :project_with_design + ].freeze + + MATCH = / + ^\+? # Start of the line, which may or may not have a `+` + (?<head>\s*) # 0-many leading whitespace captured in a group named head + let!? # Literal `let` which may or may not end in `!` + (?<tail> # capture group named tail + \([^)]+\) # Two parenthesis with any non-parenthesis characters between them + \s*\{\s* # Opening curly brace surrounded by 0-many whitespace characters + create\( # literal + (?:#{PROJECT_FACTORIES.join('|')}) # Any of the project factory names + \W # Non-word character, avoid matching factories like :project_badge + ) # end capture group named tail + /x + + REPLACEMENT = '\k<head>let_it_be\k<tail>' + SUGGESTION = <<~SUGGEST_COMMENT + Project creations are very slow. Use `let_it_be`, `build` or `build_stubbed` if possible. + See [testing best practices](https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#optimize-factory-usage) + for background information and alternative options. + SUGGEST_COMMENT + end + end + end +end |