Skip to content

Commit 9e13f03

Browse files
committed
Merge pull request #10 from codeclimate/will/monkeypatch-failfast
change monkey patch to use module_eval
2 parents be6dd8a + 938cb31 commit 9e13f03

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

lib/cc/engine/rubocop.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require "json"
22
require "pathname"
3-
require "rubocop/cop/method_complexity_patch"
43
require "rubocop"
4+
require "rubocop/cop/method_complexity_patch"
55
require "cc/engine/category_parser"
66

77
module CC
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
# 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)
1713
end
1814
end

0 commit comments

Comments
 (0)