rubocop-infinum 0.3.0 → 0.6.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 +16 -0
- data/README.md +1 -1
- 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 -1
- data/{.infinum.yml → rubocop.yml} +4 -0
- metadata +24 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eab4ddaf8d28fe1b4549a6cada698ea7a839c65dedd6ada156b7347273783946
|
4
|
+
data.tar.gz: 696b1a2a1c359e2da6c4ccc699a7cf1738be0ec21e63bdcdbca36a2c227628bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc4248284de8b3665408d46d2251c170d5b1285173ac690f90a6df1acec8d8c38dfbee66762681ade893907d49dd34d467666301543f92940ceec832915f35b6
|
7
|
+
data.tar.gz: 951a92324c0b959841771b982558b093039e9f633ce2ec1a00788956aa6a86667d149460d4bd42093165755617f3cf33243f3404bd997c9a5f65f52fa60136b4
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# RuboCop Infinum Change Log
|
2
2
|
|
3
|
+
## 0.6.0 (Feb 18th, 2022)
|
4
|
+
|
5
|
+
- Create FactoryBotAssociation cop (@Benaaaaa)
|
6
|
+
- Fix issue with second optional parameter and refactor attribute_default_block_value cop (@Benaaaaa)
|
7
|
+
## 0.5.1 (Sep 16th, 2021)
|
8
|
+
|
9
|
+
- Enforce separated accessor grouping (@d4be4st)
|
10
|
+
|
11
|
+
## 0.5.0 (Aug 25th, 2021)
|
12
|
+
|
13
|
+
- Add rubocop-performance (@PetarCurkovic)
|
14
|
+
|
15
|
+
## 0.4.0 (Aug 20th, 2021)
|
16
|
+
|
17
|
+
- Rename config file to rubocop.yml (keeping a convention with other rubocop gems)
|
18
|
+
|
3
19
|
## 0.3.0 (Aug 20th, 2021)
|
4
20
|
|
5
21
|
- Rename config file to .infinum.yml (fixes inheriting configuration)
|
data/README.md
CHANGED
@@ -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.'
|
@@ -33,4 +33,5 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_runtime_dependency('rubocop')
|
34
34
|
spec.add_runtime_dependency('rubocop-rails')
|
35
35
|
spec.add_runtime_dependency('rubocop-rspec')
|
36
|
+
spec.add_runtime_dependency('rubocop-performance')
|
36
37
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require:
|
2
2
|
- rubocop-rails
|
3
3
|
- rubocop-rspec
|
4
|
+
- rubocop-performance
|
4
5
|
|
5
6
|
Layout/LineLength:
|
6
7
|
Max: 120
|
@@ -15,6 +16,9 @@ Rails:
|
|
15
16
|
RSpec/ExampleLength:
|
16
17
|
Max: 10
|
17
18
|
|
19
|
+
Style/AccessorGrouping:
|
20
|
+
EnforcedStyle: separated
|
21
|
+
|
18
22
|
Style/Documentation:
|
19
23
|
Enabled: false
|
20
24
|
|
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.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marko Ćilimković
|
8
8
|
- Stjepan Hađić
|
9
|
-
|
9
|
+
- Tin Benaković
|
10
|
+
autorequire:
|
10
11
|
bindir: exe
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2022-02-18 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: pry-byebug
|
@@ -81,7 +82,21 @@ dependencies:
|
|
81
82
|
- - ">="
|
82
83
|
- !ruby/object:Gem::Version
|
83
84
|
version: '0'
|
84
|
-
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: rubocop-performance
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
type: :runtime
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
description:
|
85
100
|
email:
|
86
101
|
- team.backend@infinum.com
|
87
102
|
executables: []
|
@@ -89,7 +104,6 @@ extensions: []
|
|
89
104
|
extra_rdoc_files: []
|
90
105
|
files:
|
91
106
|
- ".gitignore"
|
92
|
-
- ".infinum.yml"
|
93
107
|
- ".rspec"
|
94
108
|
- ".ruby-version"
|
95
109
|
- CHANGELOG.md
|
@@ -100,10 +114,12 @@ files:
|
|
100
114
|
- bin/setup
|
101
115
|
- lib/rubocop-infinum.rb
|
102
116
|
- lib/rubocop/cop/infinum/attribute_default_block_value.rb
|
117
|
+
- lib/rubocop/cop/infinum/factory_bot_association.rb
|
103
118
|
- lib/rubocop/cop/infinum_cops.rb
|
104
119
|
- lib/rubocop/infinum.rb
|
105
120
|
- lib/rubocop/infinum/version.rb
|
106
121
|
- rubocop-infinum.gemspec
|
122
|
+
- rubocop.yml
|
107
123
|
homepage: https://github.com/infinum/rubocop-infinum
|
108
124
|
licenses:
|
109
125
|
- MIT
|
@@ -111,7 +127,7 @@ metadata:
|
|
111
127
|
allowed_push_host: https://rubygems.org
|
112
128
|
homepage_uri: https://github.com/infinum/rubocop-infinum
|
113
129
|
source_code_uri: https://github.com/infinum/rubocop-infinum
|
114
|
-
post_install_message:
|
130
|
+
post_install_message:
|
115
131
|
rdoc_options: []
|
116
132
|
require_paths:
|
117
133
|
- lib
|
@@ -126,9 +142,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
142
|
- !ruby/object:Gem::Version
|
127
143
|
version: '0'
|
128
144
|
requirements: []
|
129
|
-
rubyforge_project:
|
145
|
+
rubyforge_project:
|
130
146
|
rubygems_version: 2.7.3
|
131
|
-
signing_key:
|
147
|
+
signing_key:
|
132
148
|
specification_version: 4
|
133
149
|
summary: Automatic Infinum code style checking tool.
|
134
150
|
test_files: []
|