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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b6ae27fccfc7b1e8dc8aefdb9822f54ea623342
4
- data.tar.gz: fc6ff9090037f1d181c50630935fdaee2e9ed7f8
3
+ metadata.gz: 5a8e6e836b70797730769203cc1f58e341cce95e
4
+ data.tar.gz: d28f3bc8399c4778f7e29cf0815c44808951ede9
5
5
  SHA512:
6
- metadata.gz: a7220b89d221787ea823b648a4ddca7d4212f8dd754f79283292e211f27f1215527df35815936c5d5550e967121323abea0d1b46db1731c365e21b0ff96d5ce6
7
- data.tar.gz: 7d6abfa5b94ad179925c08b4fb355b067ef18788b5d142de596b6f4034a0c3f2e54dfe65aca5bd70b501c6dd63245be60ce635fa39bcfb242a02eefa4674dc61
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
@@ -1 +1,2 @@
1
1
  require 'rubocop/cop/betterment/timeout'
2
+ require 'rubocop/cop/betterment/memoization_with_arguments'
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.5.0
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-10-15 00:00:00.000000000 Z
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: