Class: RuboCop::Cop::Gusto::SmartTodoTeam
- Inherits:
-
SmartTodo::SmartTodoCop
- Object
- SmartTodo::SmartTodoCop
- RuboCop::Cop::Gusto::SmartTodoTeam
- Defined in:
- lib/rubocop/cop/gusto/smart_todo_team.rb
Overview
Enforces SmartTodo syntax (via the upstream ‘SmartTodo/SmartTodoCop`) and, in addition, requires every TODO’s ‘to:` assignee to name a valid team as defined by CodeTeams (`config/teams/*/.yml`).
All of the upstream cop’s failure modes are preserved verbatim via ‘super`. The only additional offense is raised when an otherwise-valid SmartTodo comment is assigned to an unknown team.
Constant Summary collapse
- TEAM_HELP =
"TODO `to:` must name a valid team (see config/teams). Match the human readable `name:` key (ex: 'Benefits Admin Transfers'), *not* a sluggified form."
Instance Method Summary collapse
Instance Method Details
#on_new_investigation ⇒ void
This method returns an undefined value.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rubocop/cop/gusto/smart_todo_team.rb', line 30 def on_new_investigation # Registers every existing SmartTodo offense. RuboCop dedupes offenses by # source range (see Cop::Base#add_offense), so any comment flagged here # silently swallows the duplicate team offense we might add below. super processed_source.comments.each do |comment| next unless TODO_PATTERN.match?(comment.text) # `is_a?(String)` guards CodeTeams.find's Sorbet signature, which raises on a # non-string. Such assignees are already flagged by `super` (invalid assignee). unknown = (comment.text).assignees.select { |assignee| assignee.is_a?(String) && !CodeTeams.find(assignee) } next if unknown.empty? add_offense(comment, message: "Unknown team(s): #{unknown.join(', ')}. #{TEAM_HELP}") end end |