rubocop-infinum 0.0.1 → 0.3.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
  SHA256:
3
- metadata.gz: 8880040332319a24731a15c229bf9ec8959c2f3b0a1307be6ff3104ddbf2caeb
4
- data.tar.gz: e276673139e2486ab42e3787aac4844543c5fb7516f809f533654e7f9c6ffa89
3
+ metadata.gz: bef0aacf541f51bc823409584a2e1a63092c6778e60965f75f237549b8bc4fc5
4
+ data.tar.gz: c8f072eae9fa8f5954e6114390d6129863cec2377c9d7b3a4235ff1dc159ab05
5
5
  SHA512:
6
- metadata.gz: f8869b6c02708ed18e174a91a723af17c652badb5f1022b78f2d2485945afa81945216a59940968cd679e855db4abb646adfe3bf21c3d1bee05d5c7e88ca9a0b
7
- data.tar.gz: 816242140887f448de62cb9ef450345870780225e7a572a8047b1e05a9c126a949534a578fd659c293a0a0913811f12a011b035db3be7734c7d1243f0672f102
6
+ metadata.gz: ce24d80185cb1b9aa639b7ba2779cbfc54b8712f590baf2159d5869ca590fa30d485bd548863ac0124ef3c8d1caa301b45348664a859d950c52a8f4680e4fa77
7
+ data.tar.gz: 9ea8c0b301e532b7bde66f290764906eccb48b944808d450c15a06713ba3c91ca9bd899b51cf6e47927a052f0451b66ad3c8829f950fc927ec26a628f9376d9f
@@ -3,16 +3,19 @@ require:
3
3
  - rubocop-rspec
4
4
 
5
5
  Layout/LineLength:
6
- Max: 100
6
+ Max: 120
7
+ IgnoredPatterns: ['\A#']
7
8
 
8
- Metrics/BlockLength:
9
- Exclude:
10
- - 'spec/**/*_spec.rb'
11
-
12
- Style/Documentation:
9
+ Naming/InclusiveLanguage:
13
10
  Enabled: false
14
11
 
15
- Style/FrozenStringLiteralComment:
12
+ Rails:
13
+ Enabled: true
14
+
15
+ RSpec/ExampleLength:
16
+ Max: 10
17
+
18
+ Style/Documentation:
16
19
  Enabled: false
17
20
 
18
21
  Style/WordArray:
@@ -30,11 +33,9 @@ Style/HashTransformKeys:
30
33
  Style/HashTransformValues:
31
34
  Enabled: true
32
35
 
33
- Rails:
34
- Enabled: true
35
-
36
- RSpec/ExampleLength:
37
- Max: 10
36
+ Metrics/BlockLength:
37
+ Exclude:
38
+ - 'spec/**/*_spec.rb'
38
39
 
39
40
  AllCops:
40
41
  TargetRubyVersion: 2.5
@@ -42,4 +43,6 @@ AllCops:
42
43
  - 'db/schema.rb'
43
44
  - 'db/migrate/*.rb'
44
45
  - 'config/**/*.rb'
46
+ - 'vendor/bundle/**/*'
47
+ - 'node_modules/**/*'
45
48
  NewCops: enable
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # RuboCop Infinum Change Log
2
2
 
3
+ ## 0.3.0 (Aug 20th, 2021)
4
+
5
+ - Rename config file to .infinum.yml (fixes inheriting configuration)
6
+
7
+ ## 0.2.0 (Jul 24th, 2021)
8
+
9
+ - Increase max line length to 120 chars and exclude comment lines
10
+
11
+ ## 0.1.1 (Jul 13th, 2021)
12
+
13
+ - exclude vendor/bundle for all cops
14
+
15
+ ## 0.1.0 (Sep 8th, 2020)
16
+
17
+ - add autocorrect method to `Rails/AttributeDefaultBlockValue`
18
+ - refactor cop `Rails/AttributeDefaultBlockValue` cop
19
+
20
+
3
21
  ## 0.0.1 (Aug 28th, 2020)
4
22
 
5
23
  - 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: .infinum.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.3.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.3.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: 2021-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry-byebug
@@ -89,8 +89,8 @@ extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
91
  - ".gitignore"
92
+ - ".infinum.yml"
92
93
  - ".rspec"
93
- - ".rubocop.yml"
94
94
  - ".ruby-version"
95
95
  - CHANGELOG.md
96
96
  - Gemfile