rubocop-infinum 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +3 -1
- data/lib/rubocop/cop/infinum/attribute_default_block_value.rb +14 -22
- data/lib/rubocop/infinum/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fc4711fd647610ed8335a849d8b9304fcef2e29c591db3f624b72edd9f2136c
|
4
|
+
data.tar.gz: c443ad3f100d2b96dae4b3cfb8be49949cfd68324633a2c940e9f3f13b335fef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a85ead5e9b4035c4261c4f72923a9ff460087db466aff4c74dee2fa1727412c327310bb0fb133c70cbb32f8e5db322f28a5c6e14234b1c2b514298b836c83095
|
7
|
+
data.tar.gz: 83ef437f62cc8fa3c48dfd046e8aee50cdee83784ba200bece3f83f3c26e76b96cac188224f0a079ab4e72973df2d5f8002c3ca0645df1f880f9660dad32334c
|
data/CHANGELOG.md
CHANGED
@@ -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
|
9
|
-
#
|
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
|
-
|
25
|
-
(
|
24
|
+
def_node_matcher :default_attribute, <<~PATTERN
|
25
|
+
(send nil? :attribute _ _ (hash <$#attribute ...>))
|
26
26
|
PATTERN
|
27
27
|
|
28
|
-
def_node_matcher :attribute
|
28
|
+
def_node_matcher :attribute, '(pair (sym :default) $_)'
|
29
29
|
|
30
30
|
def on_send(node)
|
31
|
-
|
31
|
+
default_attribute(node) do |attribute|
|
32
|
+
value = attribute.children.last
|
32
33
|
|
33
|
-
|
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
|
-
|
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
|
-
|
48
|
-
|
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
|
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
|
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
|
12
|
+
date: 2020-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pry-byebug
|