sevencop 0.40.1 → 0.41.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: b9d291c9bf0ec6bb349a6f7a70ebca387c933ddb9ca4a84bfa34f8906b044d68
4
- data.tar.gz: 3d005e1c0636815cf76667e80866a48f6279bfbbbe251f58920f356728ad96ec
3
+ metadata.gz: fb5397adad61614b94d14106b30c1ca48a436ca36fa4154986e0ff37127e5c54
4
+ data.tar.gz: ef34c4ac93d16b2396abd8a61947c5fa317e0b0639bbb40ee61d186d3fa90f83
5
5
  SHA512:
6
- metadata.gz: be809d23bb893cbbff03f3bdd6a95f79db7aac41f3920defba5f55393b71f24b44cb0fd178f4e2920e00e94fbc9f724b73d7ee4d76c53bbca43a266cb053e1ca
7
- data.tar.gz: 66342ee1af89275c848a4c8c11ff06337fbfefb53a659c350621cdc5b0bc7fb784a1ee58cf77fcf1556bb2e1b8ca8e7ac896c10a02eee67ab6d3716850004a66
6
+ metadata.gz: a602e9e8e23e56a86f99b5cededd1fa3e8cdd002fba5a5bb0de3534fd5fc219d5c793dc61024a4d4ab8d45fbf45c645f197b24da9a58a4eb97a97b0c8947921e
7
+ data.tar.gz: 3b8868e249ab3e426b691a1ad287e1803f1ce854925d4b195e31bf20f49cb2a135e425579671a374ced892ee653ae0b3e7af156451553ec5d23439cb8cc160e8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sevencop (0.40.1)
4
+ sevencop (0.41.0)
5
5
  activesupport
6
6
  rubocop
7
7
 
data/README.md CHANGED
@@ -29,8 +29,6 @@ Note that all cops are `Enabled: false` by default.
29
29
  ## Cops
30
30
 
31
31
  - [Sevencop/AutoloadOrdered](lib/rubocop/cop/sevencop/autoload_ordered.rb)
32
- - [Sevencop/FactoryBotAssociationOption](lib/rubocop/cop/sevencop/factory_bot_association_option.rb)
33
- - [Sevencop/FactoryBotAssociationStyle](lib/rubocop/cop/sevencop/factory_bot_association_style.rb)
34
32
  - [Sevencop/HashElementOrdered](lib/rubocop/cop/sevencop/hash_element_ordered.rb)
35
33
  - [Sevencop/MapMethodChain](lib/rubocop/cop/sevencop/map_method_chain.rb)
36
34
  - [Sevencop/MethodDefinitionArgumentsMultiline](lib/rubocop/cop/sevencop/method_definition_arguments_multiline.rb)
data/config/default.yml CHANGED
@@ -4,30 +4,6 @@ Sevencop/AutoloadOrdered:
4
4
  Enabled: false
5
5
  Safe: false
6
6
 
7
- Sevencop/FactoryBotAssociationOption:
8
- Description: |
9
- Avoid redundant options on FactoryBot associations.
10
- Enabled: false
11
-
12
- Sevencop/FactoryBotAssociationStyle:
13
- Description: |
14
- Use consistent style in FactoryBot associations.
15
- Enabled: false
16
- Safe: false
17
- EnforcedStyle: implicit
18
- SupportedStyles:
19
- - explicit
20
- - implicit
21
- inherit_mode:
22
- merge:
23
- - NonImplicitAssociationMethodNames
24
- NonImplicitAssociationMethodNames:
25
- - skip_create
26
- Include:
27
- - "**/factories.rb"
28
- - "**/spec/factories/*.rb"
29
- - "**/test/factories/*.rb"
30
-
31
7
  Sevencop/HashElementOrdered:
32
8
  Description: |
33
9
  Sort Hash elements by key.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sevencop
4
- VERSION = '0.40.1'
4
+ VERSION = '0.41.0'
5
5
  end
data/lib/sevencop.rb CHANGED
@@ -5,8 +5,6 @@ require_relative 'sevencop/rubocop_extension'
5
5
  require_relative 'sevencop/version'
6
6
 
7
7
  require_relative 'rubocop/cop/sevencop/autoload_ordered'
8
- require_relative 'rubocop/cop/sevencop/factory_bot_association_option'
9
- require_relative 'rubocop/cop/sevencop/factory_bot_association_style'
10
8
  require_relative 'rubocop/cop/sevencop/hash_element_ordered'
11
9
  require_relative 'rubocop/cop/sevencop/map_method_chain'
12
10
  require_relative 'rubocop/cop/sevencop/method_definition_arguments_multiline'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sevencop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.40.1
4
+ version: 0.41.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
@@ -57,8 +57,6 @@ files:
57
57
  - config/default.yml
58
58
  - data/reserved_words_mysql.txt
59
59
  - lib/rubocop/cop/sevencop/autoload_ordered.rb
60
- - lib/rubocop/cop/sevencop/factory_bot_association_option.rb
61
- - lib/rubocop/cop/sevencop/factory_bot_association_style.rb
62
60
  - lib/rubocop/cop/sevencop/hash_element_ordered.rb
63
61
  - lib/rubocop/cop/sevencop/map_method_chain.rb
64
62
  - lib/rubocop/cop/sevencop/method_definition_arguments_multiline.rb
@@ -1,89 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module Sevencop
6
- # Avoid redundant options on FactoryBot associations.
7
- #
8
- # @example
9
- # # bad
10
- # association :user, factory: :user
11
- #
12
- # # good
13
- # association :user
14
- class FactoryBotAssociationOption < RuboCop::Cop::Base
15
- extend AutoCorrector
16
-
17
- include RangeHelp
18
-
19
- MSG = 'Avoid redundant options on FactoryBot associations.'
20
-
21
- RESTRICT_ON_SEND = %i[association].freeze
22
-
23
- # @param node [RuboCop::AST::SendNode]
24
- # @return [void]
25
- def on_send(node)
26
- association_name = association_name_from(node)
27
- factory_option = factory_option_from(node)
28
- return if !factory_option || association_name != factory_option.value.value
29
-
30
- add_offense(factory_option) do |corrector|
31
- autocorrect(corrector, factory_option)
32
- end
33
- end
34
-
35
- private
36
-
37
- # @!method association_name_from(node)
38
- # @param node [RuboCop::AST::SendNode]
39
- # @return [Symbol, nil]
40
- def_node_matcher :association_name_from, <<~PATTERN
41
- (send
42
- nil?
43
- _
44
- (sym $_)
45
- ...
46
- )
47
- PATTERN
48
-
49
- # @!method factory_option_from(node)
50
- # @param node [RuboCop::AST::SendNode]
51
- # @return [RuboCop::AST::PairNode, nil]
52
- def_node_matcher :factory_option_from, <<~PATTERN
53
- (send
54
- nil?
55
- _
56
- _
57
- (hash
58
- <
59
- $(pair
60
- (sym :factory)
61
- sym
62
- )
63
- ...
64
- >
65
- )
66
- )
67
- PATTERN
68
-
69
- # @param corrector [RuboCop::Cop::Corrector]
70
- # @param node [RuboCop::AST::PairNode]
71
- # @return [void]
72
- def autocorrect(
73
- corrector,
74
- node
75
- )
76
- corrector.remove(
77
- range_with_surrounding_comma(
78
- range_with_surrounding_space(
79
- node.source_range,
80
- side: :left
81
- ),
82
- :left
83
- )
84
- )
85
- end
86
- end
87
- end
88
- end
89
- end
@@ -1,168 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module Sevencop
6
- # Use consistent style in FactoryBot associations.
7
- #
8
- # @safety
9
- # This cop may cause false-positives in `EnforcedStyle: explicit` case.
10
- # It recognizes any method call that has no arguments as an implicit association
11
- # but it might be a user-defined trait call.
12
- #
13
- # @example EnforcedStyle: implicit (default)
14
- # # bad
15
- # association :user
16
- #
17
- # # good
18
- # user
19
- #
20
- # # good
21
- # association :author, factory: user
22
- #
23
- # @example EnforcedStyle: explicit
24
- # # bad
25
- # user
26
- #
27
- # # good
28
- # association :user
29
- #
30
- # # good (defined in NonImplicitAssociationMethodNames)
31
- # skip_create
32
- class FactoryBotAssociationStyle < RuboCop::Cop::Base
33
- extend AutoCorrector
34
-
35
- include ConfigurableEnforcedStyle
36
-
37
- MSG = 'Use consistent style in FactoryBot associations.'
38
-
39
- RESTRICT_ON_SEND = %i[factory].freeze
40
-
41
- # @param node [RuboCop::AST::SendNode]
42
- # @return [void]
43
- def on_send(node)
44
- bad_associations_in(node).each do |association|
45
- add_offense(association) do |corrector|
46
- autocorrect(corrector, association)
47
- end
48
- end
49
- end
50
-
51
- private
52
-
53
- # @!method explicit_association?(node)
54
- # @param node [RuboCop::AST::SendNode]
55
- # @return [Boolean]
56
- def_node_matcher :explicit_association?, <<~PATTERN
57
- (send
58
- nil?
59
- :association
60
- ...
61
- )
62
- PATTERN
63
-
64
- # @!method implicit_association?(node)
65
- # @param node [RuboCop::AST::SendNode]
66
- # @return [Boolean]
67
- def_node_matcher :implicit_association?, <<~PATTERN
68
- (send
69
- nil?
70
- !#non_implicit_association_method_name?
71
- )
72
- PATTERN
73
-
74
- # @param corrector [RuboCop::Cop::Corrector]
75
- # @param node [RuboCop::AST::SendNode]
76
- def autocorrect(
77
- corrector,
78
- node
79
- )
80
- case style
81
- when :explicit
82
- autocorrect_to_explicit_style(corrector, node)
83
- when :implicit
84
- autocorrect_to_implicit_style(corrector, node)
85
- end
86
- end
87
-
88
- # @param corrector [RuboCop::Cop::Corrector]
89
- # @param node [RuboCop::AST::SendNode]
90
- # @return [void]
91
- def autocorrect_to_explicit_style(
92
- corrector,
93
- node
94
- )
95
- corrector.replace(node, "association :#{node.method_name}")
96
- end
97
-
98
- # @param corrector [RuboCop::Cop::Corrector]
99
- # @param node [RuboCop::AST::SendNode]
100
- # @return [void]
101
- def autocorrect_to_implicit_style(
102
- corrector,
103
- node
104
- )
105
- corrector.replace(node, node.first_argument.value.to_s)
106
- end
107
-
108
- # @param node [RuboCop::AST::SendNode]
109
- # @return [Boolean]
110
- def autocorrectable_to_implicit_style?(node)
111
- node.arguments.one?
112
- end
113
-
114
- # @param node [RuboCop::AST::SendNode]
115
- # @return [Boolean]
116
- def bad?(node)
117
- case style
118
- when :explicit
119
- bad_to_explicit_style?(node)
120
- when :implicit
121
- bad_to_implicit_style?(node)
122
- end
123
- end
124
-
125
- # @param node [RuboCop::AST::SendNode]
126
- # @return [Array<RuboCop::AST::SendNode>]
127
- def bad_associations_in(node)
128
- children_of_factory_block(node).select do |child|
129
- bad?(child)
130
- end
131
- end
132
-
133
- # @param node [RuboCop::AST::SendNode]
134
- # @return [Boolean]
135
- def bad_to_explicit_style?(node)
136
- implicit_association?(node)
137
- end
138
-
139
- # @param node [RuboCop::AST::SendNode]
140
- # @return [Boolean]
141
- def bad_to_implicit_style?(node)
142
- explicit_association?(node) && autocorrectable_to_implicit_style?(node)
143
- end
144
-
145
- # @param node [RuboCop::AST::SendNode]
146
- # @return [Array<RuboCop::AST::Node>]
147
- def children_of_factory_block(node)
148
- block = node.parent
149
- return [] unless block
150
- return [] unless block.block_type?
151
- return [] unless block.body
152
-
153
- if block.body.begin_type?
154
- block.body.children
155
- else
156
- [block.body]
157
- end
158
- end
159
-
160
- # @param method_name [Symbol]
161
- # @return [Boolean]
162
- def non_implicit_association_method_name?(method_name)
163
- cop_config['NonImplicitAssociationMethodNames'].include?(method_name.to_s)
164
- end
165
- end
166
- end
167
- end
168
- end