Skip to content

Commit 5b079a3

Browse files
author
Will Fleming
committed
explain the monkey patching
1 parent 66a1a62 commit 5b079a3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/rubocop/cop/method_complexity_patch.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
module RuboCop
33
module Cop
44
module MethodComplexity
5+
# RuboCop's default implementation of `add_offense` in `Cop` only gets the
6+
# location of the keyword associated with the problem which, for things
7+
# like complexity checkers, is just the method def line. This isn't very
8+
# useful for checkers where the entire method body is relevant. Fetching
9+
# this information from an `Offense` instance is difficult, since the
10+
# original AST is no longer available. So it's easier to monkey-path
11+
# this method on complexity checkers to send the location of the entire
12+
# method to the created `Offense`.
513
def add_offense(node, loc, message = nil, severity = nil)
614
super(node, node.loc, message, severity)
715
end

0 commit comments

Comments
 (0)