rubocop-betterment 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +0 -4
- data/lib/rubocop/cop/betterment/memoization_with_arguments.rb +33 -0
- data/lib/rubocop/cop/betterment.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a8e6e836b70797730769203cc1f58e341cce95e
|
4
|
+
data.tar.gz: d28f3bc8399c4778f7e29cf0815c44808951ede9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b605a6a49483f80ae71a00540075adc516e4478c9bd4ff8f28e2b258201a484445044cf01953f36cd73c215b544abf40b99ac3a0c01bdd5f195d21602effb1d
|
7
|
+
data.tar.gz: b8081a6defeb7207bd158934c762965be285e6db38b25cf620c956f0fe997875bdee136648760482dffa592ba38338194954ca095321fe409377fa56787e8bd6
|
data/config/default.yml
CHANGED
@@ -54,10 +54,6 @@ Lint/BooleanSymbol:
|
|
54
54
|
Exclude:
|
55
55
|
- 'spec/**/*'
|
56
56
|
|
57
|
-
# cop is removed on unreleased rubocop master https://github.com/bbatsov/rubocop/blob/master/CHANGELOG.md#master-unreleased
|
58
|
-
Lint/SplatKeywordArguments:
|
59
|
-
Enabled: false
|
60
|
-
|
61
57
|
Metrics/AbcSize:
|
62
58
|
Exclude:
|
63
59
|
- 'spec/**/*'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module RuboCop
|
2
|
+
module Cop
|
3
|
+
module Betterment
|
4
|
+
class MemoizationWithArguments < Cop
|
5
|
+
MSG = 'Memoized method `%<method>s` accepts arguments, ' \
|
6
|
+
'which may cause it to return a stale result. ' \
|
7
|
+
'Remove memoization or refactor to remove arguments.'.freeze
|
8
|
+
|
9
|
+
def self.node_pattern
|
10
|
+
memo_assign = '(or_asgn $(ivasgn _) _)'
|
11
|
+
memoized_at_end_of_method = "(begin ... #{memo_assign})"
|
12
|
+
instance_method =
|
13
|
+
"(def $_ _ {#{memo_assign} #{memoized_at_end_of_method}})"
|
14
|
+
class_method =
|
15
|
+
"(defs self $_ _ {#{memo_assign} #{memoized_at_end_of_method}})"
|
16
|
+
"{#{instance_method} #{class_method}}"
|
17
|
+
end
|
18
|
+
|
19
|
+
private_class_method :node_pattern
|
20
|
+
def_node_matcher :memoized?, node_pattern
|
21
|
+
|
22
|
+
def on_def(node)
|
23
|
+
(method_name, ivar_assign) = memoized?(node)
|
24
|
+
return if ivar_assign.nil? || node.arguments.length.zero?
|
25
|
+
|
26
|
+
msg = format(MSG, method: method_name)
|
27
|
+
add_offense(node, location: ivar_assign.source_range, message: msg)
|
28
|
+
end
|
29
|
+
alias on_defs on_def
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-betterment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Development
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- STYLEGUIDE.md
|
92
92
|
- config/default.yml
|
93
93
|
- lib/rubocop/cop/betterment.rb
|
94
|
+
- lib/rubocop/cop/betterment/memoization_with_arguments.rb
|
94
95
|
- lib/rubocop/cop/betterment/timeout.rb
|
95
96
|
homepage:
|
96
97
|
licenses:
|