diff --git a/danger/utility_css/Dangerfile b/danger/utility_css/Dangerfile new file mode 100644 index 0000000000000000000000000000000000000000..4f56c40379e42893b430677fca8400f7d0204b51 --- /dev/null +++ b/danger/utility_css/Dangerfile @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +common = 'app/assets/stylesheets/framework/common.scss' +utilities = 'app/assets/stylesheets/utilities.scss' + +def get_css_files(files, common_filepath, utilities_filepath) + files.select do |file| + file.include?(common_filepath) || + file.include?(utilities_filepath) + end +end + +changed_util_files = get_css_files(helper.all_changed_files.to_a, common, utilities) + +unless changed_util_files.empty? + + markdown(<<~MARKDOWN) + ## Changes to utility SCSS files + MARKDOWN + + if changed_util_files.include?(common) + + markdown(<<~MARKDOWN) + ### Addition to `#{common}` + + You have added a new rule to `#{common}`. Are you sure you need this rule? + + If it is a component class shared across items, could it be added to the component as a utility class or to the component's stylesheet? If not, you can ignore this warning. + + If it is a new utility class, is there another class that shares the same values in either this file or in `#{utilities}`? If not, please add it to `#{utilities}`, following the [Gitlab UI naming style](https://unpkg.com/browse/@gitlab/ui/src/scss/utilities.scss). + + MARKDOWN + + end + + if changed_util_files.include?(utilities) + markdown(<<~MARKDOWN) + ### Addition to `#{utilities}` + + You have added a new rule to `#{utilities}`. Are you sure you need this rule? + + If it is a component class shared across items, could it be added to the component as a utility class or to the component's stylesheet? If not, consider adding it to `#{common}` + + If it is a new utility class, is there another class that shares the same values in either this file or in `#{utilities}`? If not, please be sure this addition follows the [Gitlab UI naming style](https://unpkg.com/browse/@gitlab/ui/src/scss/utilities.scss) so it may be removed when these rules are included. See [Include gitlab-ui utility-class library](https://gitlab.com/gitlab-org/gitlab/issues/36857) for more about this project. + + MARKDOWN + end + + warn "This merge request adds a new rule to #{common} or #{utilities}." + +end diff --git a/lib/gitlab_danger.rb b/lib/gitlab_danger.rb index ee0951f18ca106b21da7188830c4d0338dd17cf5..ebfeb2671e2c26197093c19167240a9d077f11d9 100644 --- a/lib/gitlab_danger.rb +++ b/lib/gitlab_danger.rb @@ -12,6 +12,7 @@ class GitlabDanger database commit_messages telemetry + utility_css ].freeze CI_ONLY_RULES ||= %w[ diff --git a/spec/lib/gitlab_danger_spec.rb b/spec/lib/gitlab_danger_spec.rb index f4620e5497993622cb998ea759b9f2bd06e40b96..8115fbca5e04bafa56a9a578a41198592526355d 100644 --- a/spec/lib/gitlab_danger_spec.rb +++ b/spec/lib/gitlab_danger_spec.rb @@ -9,7 +9,7 @@ describe '.local_warning_message' do it 'returns an informational message with rules that can run' do - expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: changes_size, documentation, frozen_string, duplicate_yarn_dependencies, prettier, eslint, karma, database, commit_messages, telemetry') + expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: changes_size, documentation, frozen_string, duplicate_yarn_dependencies, prettier, eslint, karma, database, commit_messages, telemetry, utility_css') end end