|
1 | 1 | # Monkey patching! Here be dragons.
|
2 |
| -module RuboCop |
3 |
| - module Cop |
4 |
| - 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`. |
13 |
| - def add_offense(node, loc, message = nil, severity = nil) |
14 |
| - super(node, node.loc, message, severity) |
15 |
| - end |
16 |
| - end |
| 2 | +RuboCop::Cop::MethodComplexity.module_eval do |
| 3 | + # RuboCop's default implementation of `add_offense` in `Cop` only gets the |
| 4 | + # location of the keyword associated with the problem which, for things |
| 5 | + # like complexity checkers, is just the method def line. This isn't very |
| 6 | + # useful for checkers where the entire method body is relevant. Fetching |
| 7 | + # this information from an `Offense` instance is difficult, since the |
| 8 | + # original AST is no longer available. So it's easier to monkey-path |
| 9 | + # this method on complexity checkers to send the location of the entire |
| 10 | + # method to the created `Offense`. |
| 11 | + def add_offense(node, loc, message = nil, severity = nil) |
| 12 | + super(node, node.loc, message, severity) |
17 | 13 | end
|
18 | 14 | end
|
0 commit comments