Skip to content
Snippets Groups Projects
Verified Commit 45bdd9bb authored by Jennifer Li's avatar Jennifer Li :three: Committed by GitLab
Browse files

Merge branch 'pl-danger-new-rubocop' into 'master'

Danger: Reminder to revisit RuboCop documentation on new TODOs

See merge request !148409



Merged-by: default avatarJennifer Li <jli@gitlab.com>
Approved-by: default avatarJennifer Li <jli@gitlab.com>
Co-authored-by: Peter Leitzen's avatarPeter Leitzen <pleitzen@gitlab.com>
parents a4b23d79 20e30e9d
No related branches found
No related tags found
1 merge request!148409Danger: Reminder to revisit RuboCop documentation on new TODOs
Pipeline #1242056128 passed
# frozen_string_literal: true
require_relative '../../tooling/danger/rubocop_inline_disable_suggestion'
require_relative '../../tooling/danger/rubocop_discourage_todo_addition'
require_relative '../../tooling/danger/rubocop_inline_disable_suggestion'
require_relative '../../tooling/danger/rubocop_new_todo'
require_relative '../../tooling/danger/rubocop_helper'
module Danger
......
......@@ -5,3 +5,4 @@ return if helper.revert_mr? && !helper.stable_branch?
rubocop.execute_inline_disable_suggestor
rubocop.execute_todo_suggestor
rubocop.execute_new_todo_reminder
# frozen_string_literal: true
require 'fast_spec_helper'
require 'gitlab/dangerfiles/spec_helper'
require_relative '../../../tooling/danger/rubocop_new_todo'
require_relative '../../../tooling/danger/project_helper'
RSpec.describe Tooling::Danger::RubocopNewTodo, feature_category: :tooling do
include_context "with dangerfile"
let(:filename) { 'spec/foo_spec.rb' }
let(:fake_danger) { DangerSpecHelper.fake_danger }
let(:fake_project_helper) { instance_double('Tooling::Danger::ProjectHelper') }
let(:context) { fake_danger.new(helper: fake_helper) }
let(:template) { described_class::SUGGESTION }
let(:file_lines) do
<<~RUBY.split("\n")
---
A/Rule/Name:
Details: grace period
Exclude:
- 'foo_spec.rb'
RUBY
end
let(:changed_lines) { file_lines.map { |line| "+#{line}" } }
subject(:new_todo) { described_class.new(filename, context: context) }
before do
allow(context).to receive(:project_helper).and_return(fake_project_helper)
allow(context.helper).to receive(:changed_lines).with(filename).and_return(changed_lines)
allow(context.project_helper).to receive(:file_lines).and_return(file_lines)
end
it 'adds comment once' do
expect(context).to receive(:markdown).with("\n#{template}".chomp, file: filename, line: 2)
new_todo.suggest
end
end
......@@ -22,11 +22,19 @@ def execute_todo_suggestor
# we'll assume a todo file modification only means regeneration/gem update/etc
return if contains_rubocop_update_files? || only_rubocop_todo_files?
modified_rubocop_todo_files.each do |filename|
rubocop_todo_files(helper.modified_files).each do |filename|
add_todo_suggestion_for(filename)
end
end
def execute_new_todo_reminder
return if helper.draft_mr?
rubocop_todo_files(helper.added_files).each do |filename|
add_new_rubocop_reminder(filename)
end
end
private
def contains_rubocop_update_files?
......@@ -39,10 +47,8 @@ def only_rubocop_todo_files?
helper.all_changed_files.none? { |path| path !~ %r{\A\.rubocop_todo/.*/\w+.yml\b} }
end
def modified_rubocop_todo_files
files = helper.modified_files
files.select { |path| path =~ %r{\A\.rubocop_todo/.*/\w+.yml\b} }
def rubocop_todo_files(files)
files.grep(%r{\A\.rubocop_todo/.*/\w+.yml\b})
end
def add_todo_suggestion_for(filename)
......@@ -52,6 +58,10 @@ def add_todo_suggestion_for(filename)
def add_inline_disable_suggestions_for(filename)
Tooling::Danger::RubocopInlineDisableSuggestion.new(filename, context: self).suggest
end
def add_new_rubocop_reminder(filename)
Tooling::Danger::RubocopNewTodo.new(filename, context: self).suggest
end
end
end
end
# frozen_string_literal: true
require_relative 'suggestion'
module Tooling
module Danger
class RubocopNewTodo < Suggestion
# For example: `Gitlab/DocUrl:`.
MATCH = %r{^\+\w+/.*:}
REPLACEMENT = nil
SUGGESTION = <<~MARKDOWN
Please review RuboCop documentation related to [Enabling a new cop](https://docs.gitlab.com/ee/development/rubocop_development_guide.html#enabling-a-new-cop) and ensure you have followed all of the steps before resolving this comment.
----
[Improve this message](https://gitlab.com/gitlab-org/gitlab/-/blob/master/tooling/danger/rubocop_new_todo.rb).
MARKDOWN
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment