rubocop-infinum 0.5.1 → 0.8.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 +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/rubocop/cop/infinum/attribute_default_block_value.rb +4 -4
- data/lib/rubocop/cop/infinum/factory_bot_association.rb +94 -0
- data/lib/rubocop/cop/infinum_cops.rb +1 -0
- data/lib/rubocop/infinum/version.rb +1 -1
- data/rubocop-infinum.gemspec +2 -2
- data/rubocop.yml +1 -2
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb4cbafaa4d31485e68abafcf382d32ab840d0487c8414d260f40411b7017090
|
4
|
+
data.tar.gz: a0016264cc32af54cfde8fe31688f45cf189724c2df52fe462f91a947959a181
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90182373858f8f363ca0789478382a645a046df2588f55a41301e1bd1e8812781e97f261fc2c3832a7907855de189d4d965b25a5c18acbc6942bac03b3a791a1
|
7
|
+
data.tar.gz: f3cb86e550f0e7ed51419ddf30b18f80f26b1354879506f9e17241c1e7b1133fd46aaae7409b941f8dfbf3ded5af049605c146ac190135049256f2ffcabaa837
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# RuboCop Infinum Change Log
|
2
2
|
|
3
|
+
## 0.8.0 (May 11th, 2022)
|
4
|
+
|
5
|
+
- Remove TargetRubyVersion from rubocop yml template (@cilim)
|
6
|
+
|
7
|
+
## 0.7.0 (Apr 28th, 2022)
|
8
|
+
|
9
|
+
- Rename Layout/LineLength IgnoredPatterns to AllowedPatterns (@vlakre)
|
10
|
+
|
11
|
+
## 0.6.0 (Feb 18th, 2022)
|
12
|
+
|
13
|
+
- Create FactoryBotAssociation cop (@Benaaaaa)
|
14
|
+
- Fix issue with second optional parameter and refactor attribute_default_block_value cop (@Benaaaaa)
|
15
|
+
|
3
16
|
## 0.5.1 (Sep 16th, 2021)
|
4
17
|
|
5
18
|
- Enforce separated accessor grouping (@d4be4st)
|
@@ -22,21 +22,21 @@ module RuboCop
|
|
22
22
|
MSG = 'Pass method in a block to `:default` option.'
|
23
23
|
|
24
24
|
def_node_matcher :default_attribute, <<~PATTERN
|
25
|
-
(send nil? :attribute _ _ (hash <$#attribute ...>))
|
25
|
+
(send nil? :attribute _ ?_ (hash <$#attribute ...>))
|
26
26
|
PATTERN
|
27
27
|
|
28
28
|
def_node_matcher :attribute, '(pair (sym :default) $_)'
|
29
29
|
|
30
30
|
def on_send(node)
|
31
|
-
default_attribute(node) do |
|
32
|
-
value = attribute
|
31
|
+
default_attribute(node) do |hash_pair|
|
32
|
+
value = attribute(hash_pair)
|
33
33
|
|
34
34
|
add_offense(node, location: value) if value.send_type?
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def autocorrect(node)
|
39
|
-
expression = default_attribute(node)
|
39
|
+
expression = attribute(default_attribute(node))
|
40
40
|
|
41
41
|
lambda do |corrector|
|
42
42
|
corrector.replace(expression, "-> { #{expression.source} }")
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubocop'
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module Infinum
|
8
|
+
# This cop looks for 'association' in factories that specify a ':factory' option
|
9
|
+
# and tells you to use explicit build reference which improves the performance
|
10
|
+
# as cascading factories will not be saved unless needed to
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# #bad
|
14
|
+
# FactoryBot.define do
|
15
|
+
# factory :book do
|
16
|
+
# title { 'Lord of the Rings' }
|
17
|
+
# association :author
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# FactoryBoy.define do
|
22
|
+
# factory :book do
|
23
|
+
# title {'Lord of the Rings'}
|
24
|
+
# author { association :author }
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# #good
|
29
|
+
# FactoryBot.define do
|
30
|
+
# factory :book do
|
31
|
+
# title { 'Lord of the Rings' }
|
32
|
+
# author { build(:author) }
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# FactoryBot.define do
|
37
|
+
# factory :author do
|
38
|
+
# name { 'J. R. R. Tolkien' }
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
class FactoryBotAssociation < ::RuboCop::Cop::Cop
|
42
|
+
MSG = 'Use %<association_name>s { build(:%<factory_name>s) } instead'
|
43
|
+
|
44
|
+
def_node_matcher :association_definition, <<~PATTERN
|
45
|
+
(send nil? :association (:sym $_) (hash (pair (sym :factory) (:sym $_))) ?)
|
46
|
+
PATTERN
|
47
|
+
|
48
|
+
def_node_matcher :inline_association_definition, <<~PATTERN
|
49
|
+
(block (send nil? $_) (args) (send nil? :association (sym $_)))
|
50
|
+
PATTERN
|
51
|
+
|
52
|
+
def on_block(node)
|
53
|
+
inline_association_definition(node) do |association_name, factory_name|
|
54
|
+
message = format(MSG, association_name: association_name.to_s, factory_name: factory_name.to_s)
|
55
|
+
|
56
|
+
add_offense(node, location: node, message: message)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def on_send(node)
|
61
|
+
return unless corrections.empty?
|
62
|
+
|
63
|
+
association_definition(node) do |association_name, factory_name|
|
64
|
+
factory_name = [association_name] if factory_name.empty?
|
65
|
+
|
66
|
+
message = format(MSG, association_name: association_name.to_s, factory_name: factory_name.first.to_s)
|
67
|
+
|
68
|
+
add_offense(node, location: node, message: message)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def autocorrect(node)
|
73
|
+
lambda do |corrector|
|
74
|
+
if expression(node).size == 1
|
75
|
+
corrector.replace(node, "#{expression(node)[0]} { build(:#{expression(node)[0]}) }")
|
76
|
+
else
|
77
|
+
corrector.replace(node, "#{expression(node)[0]} { build(:#{expression(node)[1]}) }")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def expression(node)
|
85
|
+
@expression = if node.block_type?
|
86
|
+
inline_association_definition(node)
|
87
|
+
else
|
88
|
+
association_definition(node).flatten
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/rubocop-infinum.gemspec
CHANGED
@@ -5,7 +5,7 @@ require_relative 'lib/rubocop/infinum/version'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'rubocop-infinum'
|
7
7
|
spec.version = RuboCop::Infinum::VERSION
|
8
|
-
spec.authors = ['Marko Ćilimković', 'Stjepan Hađić']
|
8
|
+
spec.authors = ['Marko Ćilimković', 'Stjepan Hađić', 'Tin Benaković']
|
9
9
|
spec.email = ['team.backend@infinum.com']
|
10
10
|
|
11
11
|
spec.summary = 'Automatic Infinum code style checking tool.'
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency('pry-byebug', '< 4')
|
31
31
|
spec.add_development_dependency('rspec', '~> 3.9')
|
32
32
|
|
33
|
-
spec.add_runtime_dependency('rubocop')
|
33
|
+
spec.add_runtime_dependency('rubocop', '>= 1.28.0')
|
34
34
|
spec.add_runtime_dependency('rubocop-rails')
|
35
35
|
spec.add_runtime_dependency('rubocop-rspec')
|
36
36
|
spec.add_runtime_dependency('rubocop-performance')
|
data/rubocop.yml
CHANGED
@@ -5,7 +5,7 @@ require:
|
|
5
5
|
|
6
6
|
Layout/LineLength:
|
7
7
|
Max: 120
|
8
|
-
|
8
|
+
AllowedPatterns: ['\A#']
|
9
9
|
|
10
10
|
Naming/InclusiveLanguage:
|
11
11
|
Enabled: false
|
@@ -42,7 +42,6 @@ Metrics/BlockLength:
|
|
42
42
|
- 'spec/**/*_spec.rb'
|
43
43
|
|
44
44
|
AllCops:
|
45
|
-
TargetRubyVersion: 2.5
|
46
45
|
Exclude:
|
47
46
|
- 'db/schema.rb'
|
48
47
|
- 'db/migrate/*.rb'
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-infinum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marko Ćilimković
|
8
8
|
- Stjepan Hađić
|
9
|
+
- Tin Benaković
|
9
10
|
autorequire:
|
10
11
|
bindir: exe
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2022-05-11 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: pry-byebug
|
@@ -45,14 +46,14 @@ dependencies:
|
|
45
46
|
requirements:
|
46
47
|
- - ">="
|
47
48
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
49
|
+
version: 1.28.0
|
49
50
|
type: :runtime
|
50
51
|
prerelease: false
|
51
52
|
version_requirements: !ruby/object:Gem::Requirement
|
52
53
|
requirements:
|
53
54
|
- - ">="
|
54
55
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
56
|
+
version: 1.28.0
|
56
57
|
- !ruby/object:Gem::Dependency
|
57
58
|
name: rubocop-rails
|
58
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,6 +114,7 @@ files:
|
|
113
114
|
- bin/setup
|
114
115
|
- lib/rubocop-infinum.rb
|
115
116
|
- lib/rubocop/cop/infinum/attribute_default_block_value.rb
|
117
|
+
- lib/rubocop/cop/infinum/factory_bot_association.rb
|
116
118
|
- lib/rubocop/cop/infinum_cops.rb
|
117
119
|
- lib/rubocop/infinum.rb
|
118
120
|
- lib/rubocop/infinum/version.rb
|