rubocop-infinum 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8880040332319a24731a15c229bf9ec8959c2f3b0a1307be6ff3104ddbf2caeb
4
- data.tar.gz: e276673139e2486ab42e3787aac4844543c5fb7516f809f533654e7f9c6ffa89
3
+ metadata.gz: 4fc4711fd647610ed8335a849d8b9304fcef2e29c591db3f624b72edd9f2136c
4
+ data.tar.gz: c443ad3f100d2b96dae4b3cfb8be49949cfd68324633a2c940e9f3f13b335fef
5
5
  SHA512:
6
- metadata.gz: f8869b6c02708ed18e174a91a723af17c652badb5f1022b78f2d2485945afa81945216a59940968cd679e855db4abb646adfe3bf21c3d1bee05d5c7e88ca9a0b
7
- data.tar.gz: 816242140887f448de62cb9ef450345870780225e7a572a8047b1e05a9c126a949534a578fd659c293a0a0913811f12a011b035db3be7734c7d1243f0672f102
6
+ metadata.gz: a85ead5e9b4035c4261c4f72923a9ff460087db466aff4c74dee2fa1727412c327310bb0fb133c70cbb32f8e5db322f28a5c6e14234b1c2b514298b836c83095
7
+ data.tar.gz: 83ef437f62cc8fa3c48dfd046e8aee50cdee83784ba200bece3f83f3c26e76b96cac188224f0a079ab4e72973df2d5f8002c3ca0645df1f880f9660dad32334c
@@ -1,5 +1,11 @@
1
1
  # RuboCop Infinum Change Log
2
2
 
3
+ ## 0.1.0 (Sep 8th, 2020)
4
+
5
+ - add autocorrect method to `Rails/AttributeDefaultBlockValue`
6
+ - refactor cop `Rails/AttributeDefaultBlockValue` cop
7
+
8
+
3
9
  ## 0.0.1 (Aug 28th, 2020)
4
10
 
5
11
  - create custom cop `Rails/AttributeDefaultBlockValue`
data/README.md CHANGED
@@ -12,7 +12,9 @@ And add to the top of your project's RuboCop configuration file:
12
12
 
13
13
  ~~~yml
14
14
  inherit_gem:
15
- rubocop-infinum: rubocop.yml
15
+ rubocop-infinum: .rubocop.yml
16
+
17
+ require: rubocop-infinum
16
18
  ~~~
17
19
 
18
20
  If you dislike some rules, please check [RuboCop's documentation](https://rubocop.readthedocs.io/en/latest/configuration/#inheriting-configuration-from-a-dependency-gem) on inheriting configuration from a gem.
@@ -5,8 +5,8 @@ require 'rubocop'
5
5
  module RuboCop
6
6
  module Cop
7
7
  module Infinum
8
- # This cop looks for `attribute` class methods that don't
9
- # specify a `:default` option inside a block.
8
+ # This cop looks for `attribute` class methods that specify a `:default` option
9
+ # and pass it a method without a block.
10
10
  #
11
11
  # @example
12
12
  # # bad
@@ -19,36 +19,28 @@ module RuboCop
19
19
  # attribute :confirmed_at, :datetime, default: -> { Time.zone.now }
20
20
  # end
21
21
  class AttributeDefaultBlockValue < ::RuboCop::Cop::Cop
22
- MSG = 'Pass a block to `:default` option.'
22
+ MSG = 'Pass method in a block to `:default` option.'
23
23
 
24
- def_node_search :active_resource_class?, <<~PATTERN
25
- (const (const nil? :ActiveResource) :Base)
24
+ def_node_matcher :default_attribute, <<~PATTERN
25
+ (send nil? :attribute _ _ (hash <$#attribute ...>))
26
26
  PATTERN
27
27
 
28
- def_node_matcher :attribute?, '(send nil? :attribute _ _ $hash)'
28
+ def_node_matcher :attribute, '(pair (sym :default) $_)'
29
29
 
30
30
  def on_send(node)
31
- return if active_resource?(node.parent)
31
+ default_attribute(node) do |attribute|
32
+ value = attribute.children.last
32
33
 
33
- attribute?(node) do |third_arg|
34
- default_attribute = default_attribute(third_arg)
35
-
36
- unless [:block, :true, :false].include?(default_attribute.children.last.type) # rubocop:disable Lint/BooleanSymbol
37
- add_offense(node, location: default_attribute)
38
- end
34
+ add_offense(node, location: value) if value.send_type?
39
35
  end
40
36
  end
41
37
 
42
- private
43
-
44
- def active_resource?(node)
45
- return false if node.nil?
38
+ def autocorrect(node)
39
+ expression = default_attribute(node).children.last
46
40
 
47
- active_resource_class?(node)
48
- end
49
-
50
- def default_attribute(node)
51
- node.children.first
41
+ lambda do |corrector|
42
+ corrector.replace(expression, "-> { #{expression.source} }")
43
+ end
52
44
  end
53
45
  end
54
46
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Infinum
5
- VERSION = '0.0.1'
5
+ VERSION = '0.1.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-infinum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marko Ćilimković
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-08-28 00:00:00.000000000 Z
12
+ date: 2020-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry-byebug