sevencop 0.21.0 → 0.23.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97218861b57331e3ffaa577f6a7a7a7d9ec05d0b7f6d7a8034e41ab831854a5d
4
- data.tar.gz: 076a2bb553cd96314b4c10144e943cd67a3c8bee532950d9945d54a8cbad96ad
3
+ metadata.gz: 0f1682050c56b200417e16dfd5e9f90898838834b29609ef01548b40ab4d4700
4
+ data.tar.gz: f44e1c9e38ee48b6719e7df278d7858d9f6dc846c3469a96d11975b5a0d572b9
5
5
  SHA512:
6
- metadata.gz: 7dbc8187110fae79a6c21c61e2292d7f6e6d42a0f51bdf35066d281a2b44fa47e1b6a2fcc920fa192cda30dfd9c77b73836e57a518d61e5de1a7ff6fc97c3576
7
- data.tar.gz: 0ad3d66a1ecbbec56054a771626e8cb22eb2bc425501fbe0b6f38290be315110de2875a73670bfead59e3cd854d41214f919178622e0807a07c91b2dac8a283e
6
+ metadata.gz: 5c3fe3df83f0a4aef3503cfe39d8d82262c1dfd3bdd5b8745922a2649991d56c208d9a6ccc8a6b2f87757e7cdb1423e33f97869a39f4172984c15b4941797df9
7
+ data.tar.gz: e9dc4ceaac5717391ba294a3995572e9cce89f3316104d2e2139af30fc994d60a9e13c0ee2eb864566b27b2e6d04ff634f0b714d1d93c0ce1f4d969294bf2da9
data/.rubocop.yml CHANGED
@@ -13,6 +13,9 @@ AllCops:
13
13
  Gemspec/RequireMFA:
14
14
  Enabled: false
15
15
 
16
+ Layout/LineLength:
17
+ Enabled: false
18
+
16
19
  Metrics:
17
20
  Enabled: false
18
21
 
@@ -49,6 +52,9 @@ Sevencop/MethodDefinitionKeywordArgumentOrdered:
49
52
  Sevencop/MethodDefinitionOrdered:
50
53
  Enabled: true
51
54
 
55
+ Sevencop/RequireOrdered:
56
+ Enabled: true
57
+
52
58
  Style/Documentation:
53
59
  Enabled: false
54
60
 
data/Gemfile.lock CHANGED
@@ -1,15 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sevencop (0.21.0)
4
+ sevencop (0.23.0)
5
+ activesupport
5
6
  rubocop
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
11
+ activesupport (7.0.4)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
10
16
  ast (2.4.2)
17
+ concurrent-ruby (1.1.10)
11
18
  diff-lcs (1.5.0)
19
+ i18n (1.12.0)
20
+ concurrent-ruby (~> 1.0)
12
21
  json (2.6.2)
22
+ minitest (5.16.3)
13
23
  parallel (1.22.1)
14
24
  parser (3.1.2.1)
15
25
  ast (~> 2.4.1)
@@ -50,6 +60,8 @@ GEM
50
60
  rubocop-rspec (2.13.1)
51
61
  rubocop (~> 1.33)
52
62
  ruby-progressbar (1.11.0)
63
+ tzinfo (2.0.5)
64
+ concurrent-ruby (~> 1.0)
53
65
  unicode-display_width (2.3.0)
54
66
 
55
67
  PLATFORMS
data/README.md CHANGED
@@ -24,9 +24,9 @@ Sevencop/MethodDefinitionOrdered:
24
24
  Enabled: true
25
25
  ```
26
26
 
27
- ## Cops
27
+ Note that all cops are `Enabled: false` by default.
28
28
 
29
- Choose the cops you want to use and enable them on your .rubocop.yml.
29
+ ## Cops
30
30
 
31
31
  - [Sevencop/AutoloadOrdered](lib/rubocop/cop/sevencop/autoload_ordered.rb)
32
32
  - [Sevencop/FactoryBotAssociationOption](lib/rubocop/cop/sevencop/factory_bot_association_option.rb)
@@ -38,12 +38,9 @@ Choose the cops you want to use and enable them on your .rubocop.yml.
38
38
  - [Sevencop/MethodDefinitionOrdered](lib/rubocop/cop/sevencop/method_definition_ordered.rb)
39
39
  - [Sevencop/RailsBelongsToOptional](lib/rubocop/cop/sevencop/rails_belongs_to_optional.rb)
40
40
  - [Sevencop/RailsInferredSpecType](lib/rubocop/cop/sevencop/rails_inferred_spec_type.rb)
41
- - [Sevencop/RailsMigrationReservedWordMysql](lib/rubocop/cop/sevencop/rails_migration_reserved_word_mysql.rb)
42
41
  - [Sevencop/RailsOrderField](lib/rubocop/cop/sevencop/rails_order_field.rb)
43
42
  - [Sevencop/RailsUniquenessValidatorExplicitCaseSensitivity](lib/rubocop/cop/sevencop/rails_uniqueness_validator_explicit_case_sensitivity.rb)
44
43
  - [Sevencop/RailsWhereNot](lib/rubocop/cop/sevencop/rails_where_not.rb)
45
44
  - [Sevencop/RequireOrdered](lib/rubocop/cop/sevencop/require_ordered.rb)
46
45
  - [Sevencop/RSpecDescribeHttpEndpoint](lib/rubocop/cop/sevencop/rspec_describe_http_endpoint.rb)
47
46
  - [Sevencop/RSpecExamplesInSameGroup](lib/rubocop/cop/sevencop/rspec_examples_in_same_group.rb)
48
-
49
- Note that all cops are `Enabled: false` by default.
data/config/default.yml CHANGED
@@ -82,15 +82,6 @@ Sevencop/RailsInferredSpecType:
82
82
  Safe: false
83
83
  VersionAdded: '0.9'
84
84
 
85
- Sevencop/RailsMigrationReservedWordMysql:
86
- Description: |
87
- Avoid using MySQL reserved words as identifiers.
88
- Enabled: false
89
- Safe: false
90
- VersionAdded: '0.20'
91
- Include:
92
- - db/migrate/**/*.rb
93
-
94
85
  Sevencop/RailsOrderField:
95
86
  Description: |
96
87
  Wrap safe SQL String by `Arel.sql`.
@@ -58,7 +58,7 @@ module RuboCop
58
58
  <
59
59
  $(pair
60
60
  (sym :factory)
61
- (sym _)
61
+ sym
62
62
  )
63
63
  ...
64
64
  >
@@ -41,7 +41,7 @@ module RuboCop
41
41
  # @param node [RuboCop::AST::SendNode]
42
42
  # @return [void]
43
43
  def on_send(node)
44
- wrong_associations_in(node).each do |association|
44
+ bad_associations_in(node).each do |association|
45
45
  add_offense(association) do |corrector|
46
46
  autocorrect(corrector, association)
47
47
  end
@@ -51,7 +51,7 @@ module RuboCop
51
51
  private
52
52
 
53
53
  # @!method explicit_association?(node)
54
- # @param node [RuboCop::AST::Node]
54
+ # @param node [RuboCop::AST::SendNode]
55
55
  # @return [Boolean]
56
56
  def_node_matcher :explicit_association?, <<~PATTERN
57
57
  (send
@@ -62,7 +62,7 @@ module RuboCop
62
62
  PATTERN
63
63
 
64
64
  # @!method implicit_association?(node)
65
- # @param node [RuboCop::AST::Node]
65
+ # @param node [RuboCop::AST::SendNode]
66
66
  # @return [Boolean]
67
67
  def_node_matcher :implicit_association?, <<~PATTERN
68
68
  (send
@@ -111,56 +111,56 @@ module RuboCop
111
111
  node.arguments.one?
112
112
  end
113
113
 
114
- # @param node [RuboCop::AST::SendNode]
115
- # @return [Array<RuboCop::AST::Node>]
116
- def children_of_factory_block(node)
117
- block = node.parent
118
- return [] unless block
119
- return [] unless block.block_type?
120
-
121
- if block.body.begin_type?
122
- block.body.children
123
- else
124
- [block.body]
125
- end
126
- end
127
-
128
- # @param method_name [Symbol]
129
- # @return [Boolean]
130
- def non_implicit_association_method_name?(method_name)
131
- cop_config['NonImplicitAssociationMethodNames'].include?(method_name.to_s)
132
- end
133
-
134
114
  # @param node [RuboCop::AST::SendNode]
135
115
  # @return [Boolean]
136
- def wrong?(node)
116
+ def bad?(node)
137
117
  case style
138
118
  when :explicit
139
- wrong_to_explicit_style?(node)
119
+ bad_to_explicit_style?(node)
140
120
  when :implicit
141
- wrong_to_implicit_style?(node)
121
+ bad_to_implicit_style?(node)
142
122
  end
143
123
  end
144
124
 
145
125
  # @param node [RuboCop::AST::SendNode]
146
126
  # @return [Array<RuboCop::AST::SendNode>]
147
- def wrong_associations_in(node)
127
+ def bad_associations_in(node)
148
128
  children_of_factory_block(node).select do |child|
149
- wrong?(child)
129
+ bad?(child)
150
130
  end
151
131
  end
152
132
 
153
- # @param node [RuboCop::AST::Node]
133
+ # @param node [RuboCop::AST::SendNode]
154
134
  # @return [Boolean]
155
- def wrong_to_explicit_style?(node)
135
+ def bad_to_explicit_style?(node)
156
136
  implicit_association?(node)
157
137
  end
158
138
 
159
139
  # @param node [RuboCop::AST::SendNode]
160
140
  # @return [Boolean]
161
- def wrong_to_implicit_style?(node)
141
+ def bad_to_implicit_style?(node)
162
142
  explicit_association?(node) && autocorrectable_to_implicit_style?(node)
163
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
+
152
+ if block.body.begin_type?
153
+ block.body.children
154
+ else
155
+ [block.body]
156
+ end
157
+ end
158
+
159
+ # @param method_name [Symbol]
160
+ # @return [Boolean]
161
+ def non_implicit_association_method_name?(method_name)
162
+ cop_config['NonImplicitAssociationMethodNames'].include?(method_name.to_s)
163
+ end
164
164
  end
165
165
  end
166
166
  end
@@ -73,7 +73,7 @@ module RuboCop
73
73
  _*
74
74
  ({ hash | kwargs }
75
75
  (pair ...)*
76
- $(pair (sym :type) (sym _))
76
+ $(pair (sym :type) sym)
77
77
  (pair ...)*
78
78
  )
79
79
  )
@@ -5,23 +5,24 @@ require 'rubocop'
5
5
  module Sevencop
6
6
  # Merge default RuboCop config with plugin config.
7
7
  class ConfigLoader
8
- PLUGIN_CONFIG_PATH = ::File.expand_path(
9
- '../../config/default.yml',
10
- __dir__
11
- )
12
-
13
8
  class << self
9
+ # @param path [String]
14
10
  # @return [RuboCop::Config]
15
- def call
16
- new.call
11
+ def call(path:)
12
+ new(path: path).call
17
13
  end
18
14
  end
19
15
 
16
+ # @param path [String]
17
+ def initialize(path:)
18
+ @path = path
19
+ end
20
+
20
21
  # @return [RuboCop::Config]
21
22
  def call
22
23
  ::RuboCop::ConfigLoader.merge_with_default(
23
24
  plugin_config,
24
- PLUGIN_CONFIG_PATH
25
+ @path
25
26
  )
26
27
  end
27
28
 
@@ -31,7 +32,7 @@ module Sevencop
31
32
  def plugin_config
32
33
  config = ::RuboCop::Config.new(
33
34
  plugin_config_hash,
34
- PLUGIN_CONFIG_PATH
35
+ @path
35
36
  )
36
37
  config.make_excludes_absolute
37
38
  config
@@ -41,7 +42,7 @@ module Sevencop
41
42
  def plugin_config_hash
42
43
  ::RuboCop::ConfigLoader.send(
43
44
  :load_yaml_configuration,
44
- PLUGIN_CONFIG_PATH
45
+ @path
45
46
  )
46
47
  end
47
48
  end
@@ -6,5 +6,10 @@ require_relative 'config_loader'
6
6
 
7
7
  RuboCop::ConfigLoader.instance_variable_set(
8
8
  :@default_configuration,
9
- Sevencop::ConfigLoader.call
9
+ Sevencop::ConfigLoader.call(
10
+ path: ::File.expand_path(
11
+ '../../config/default.yml',
12
+ __dir__
13
+ )
14
+ )
10
15
  )
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sevencop
4
- VERSION = '0.21.0'
4
+ VERSION = '0.23.0'
5
5
  end
data/lib/sevencop.rb CHANGED
@@ -14,7 +14,6 @@ require_relative 'rubocop/cop/sevencop/method_definition_keyword_argument_ordere
14
14
  require_relative 'rubocop/cop/sevencop/method_definition_ordered'
15
15
  require_relative 'rubocop/cop/sevencop/rails_belongs_to_optional'
16
16
  require_relative 'rubocop/cop/sevencop/rails_inferred_spec_type'
17
- require_relative 'rubocop/cop/sevencop/rails_migration_reserved_word_mysql'
18
17
  require_relative 'rubocop/cop/sevencop/rails_order_field'
19
18
  require_relative 'rubocop/cop/sevencop/rails_uniqueness_validator_explicit_case_sensitivity'
20
19
  require_relative 'rubocop/cop/sevencop/rails_where_not'
data/sevencop.gemspec CHANGED
@@ -28,5 +28,6 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ['lib']
30
30
 
31
+ spec.add_runtime_dependency 'activesupport'
31
32
  spec.add_runtime_dependency 'rubocop'
32
33
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sevencop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-14 00:00:00.000000000 Z
11
+ date: 2022-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rubocop
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +66,6 @@ files:
52
66
  - lib/rubocop/cop/sevencop/method_definition_ordered.rb
53
67
  - lib/rubocop/cop/sevencop/rails_belongs_to_optional.rb
54
68
  - lib/rubocop/cop/sevencop/rails_inferred_spec_type.rb
55
- - lib/rubocop/cop/sevencop/rails_migration_reserved_word_mysql.rb
56
69
  - lib/rubocop/cop/sevencop/rails_order_field.rb
57
70
  - lib/rubocop/cop/sevencop/rails_uniqueness_validator_explicit_case_sensitivity.rb
58
71
  - lib/rubocop/cop/sevencop/rails_where_not.rb
@@ -1,249 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'set'
4
-
5
- module RuboCop
6
- module Cop
7
- module Sevencop
8
- # Avoid using MySQL reserved words as identifiers.
9
- #
10
- # @example
11
- # # bad
12
- # # NOTE: `role` is a reserved word in MySQL.
13
- # add_column :users, :role, :string
14
- #
15
- # # good
16
- # add_column :users, :some_other_good_name, :string
17
- class RailsMigrationReservedWordMysql < RuboCop::Cop::Base
18
- COLUMN_TYPE_METHOD_NAMES = ::Set.new(
19
- %i[
20
- bigint
21
- binary
22
- blob
23
- boolean
24
- date
25
- datetime
26
- decimal
27
- float
28
- integer
29
- numeric
30
- primary_key
31
- string
32
- text
33
- time
34
- ]
35
- ).freeze
36
-
37
- MSG = 'Avoid using MySQL reserved words as identifiers.'
38
-
39
- # Obtained from https://dev.mysql.com/doc/refman/8.0/en/keywords.html.
40
- PATH_TO_RESERVED_WORDS_FILE = File.expand_path(
41
- '../../../../data/reserved_words_mysql.txt',
42
- __dir__
43
- ).freeze
44
-
45
- RESTRICT_ON_SEND = [
46
- :add_column,
47
- :add_index,
48
- :add_reference,
49
- :create_join_table,
50
- :create_table,
51
- :rename,
52
- :rename_column,
53
- :rename_index,
54
- :rename_table,
55
- *COLUMN_TYPE_METHOD_NAMES
56
- ].freeze
57
-
58
- class << self
59
- # @return [Array<String>]
60
- def reserved_words
61
- @reserved_words ||= ::Set.new(
62
- ::File.read(PATH_TO_RESERVED_WORDS_FILE).split("\n")
63
- ).freeze
64
- end
65
- end
66
-
67
- # @param node [RuboCop::AST::DefNode]
68
- # @return [void]
69
- def on_send(node)
70
- offended_identifier_nodes_from(node).each do |identifier_node|
71
- add_offense(identifier_node)
72
- end
73
- end
74
-
75
- private
76
-
77
- # @!method index_name_option_from_add_index(node)
78
- # @param node [RuboCop::AST::SendNode]
79
- # @return [RuboCop::AST::Node, nil]
80
- def_node_matcher :index_name_option_from_add_index, <<~PATTERN
81
- (send
82
- nil?
83
- :add_index
84
- _
85
- _
86
- (hash
87
- <
88
- (pair
89
- (sym :name)
90
- $_
91
- )
92
- >
93
- ...
94
- )
95
- )
96
- PATTERN
97
-
98
- # @!method index_name_option_from_add_reference(node)
99
- # @param node [RuboCop::AST::SendNode]
100
- # @return [RuboCop::AST::Node, nil]
101
- def_node_matcher :index_name_option_from_add_reference, <<~PATTERN
102
- (send
103
- nil?
104
- :add_reference
105
- _
106
- _
107
- (hash
108
- <
109
- (pair
110
- (sym :index)
111
- (hash
112
- <
113
- (pair
114
- (sym :name)
115
- $_
116
- )
117
- >
118
- ...
119
- )
120
- )
121
- >
122
- ...
123
- )
124
- )
125
- PATTERN
126
-
127
- # @!method index_name_option_from_column_type(node)
128
- # @param node [RuboCop::AST::SendNode]
129
- # @return [RuboCop::AST::Node, nil]
130
- def_node_matcher :index_name_option_from_column_type, <<~PATTERN
131
- (send
132
- (lvar _)
133
- COLUMN_TYPE_METHOD_NAMES
134
- _
135
- (hash
136
- <
137
- (pair
138
- (sym :index)
139
- (hash
140
- <
141
- (pair
142
- (sym :name)
143
- $_
144
- )
145
- ...
146
- >
147
- )
148
- )
149
- ...
150
- >
151
- )
152
- )
153
- PATTERN
154
-
155
- # @!method table_name_option_from(node)
156
- # @param node [RuboCop::AST::SendNode]
157
- # @return [RuboCop::AST::Node, nil]
158
- def_node_matcher :table_name_option_from, <<~PATTERN
159
- (send
160
- nil?
161
- :create_join_table
162
- _
163
- _
164
- (hash
165
- <
166
- (pair
167
- (sym :table_name)
168
- $_
169
- )
170
- ...
171
- >
172
- )
173
- )
174
- PATTERN
175
-
176
- # @param node [RuboCop::AST::SendNode]
177
- # @return [Array<RuboCop::AST::Node>]
178
- def identifier_column_name_nodes_from(node)
179
- case node.method_name
180
- when :add_column, :rename
181
- [node.arguments[1]]
182
- when :rename_column
183
- [node.arguments[2]]
184
- when *COLUMN_TYPE_METHOD_NAMES
185
- [node.arguments[0]]
186
- else
187
- []
188
- end
189
- end
190
-
191
- # @param node [RuboCop::AST::SendNode]
192
- # @return [Array<RuboCop::AST::Node>]
193
- def identifier_index_name_nodes_from(node)
194
- case node.method_name
195
- when :add_index
196
- [index_name_option_from_add_index(node)].compact
197
- when :add_reference
198
- [index_name_option_from_add_reference(node)].compact
199
- when :rename_index
200
- [node.arguments[2]]
201
- when *COLUMN_TYPE_METHOD_NAMES
202
- [index_name_option_from_column_type(node)].compact
203
- else
204
- []
205
- end
206
- end
207
-
208
- # @param node [RuboCop::AST::SendNode]
209
- # @return [Array<RuboCop::AST::Node>]
210
- def identifier_nodes_from(node)
211
- identifier_table_name_nodes_from(node) +
212
- identifier_column_name_nodes_from(node) +
213
- identifier_index_name_nodes_from(node)
214
- end
215
-
216
- # @param node [RuboCop::AST::SendNode]
217
- # @return [Array<RuboCop::AST::Node>]
218
- def identifier_table_name_nodes_from(node)
219
- case node.method_name
220
- when :create_join_table
221
- [table_name_option_from(node)].compact
222
- when :create_table
223
- [node.arguments[0]]
224
- when :rename_table
225
- [node.arguments[1]]
226
- else
227
- []
228
- end
229
- end
230
-
231
- # @param node [RuboCop::AST::Node]
232
- # @return [Array<RuboCop::AST::Node>]
233
- def offended_identifier_nodes_from(node)
234
- identifier_nodes_from(node).select do |identifier_node|
235
- reserved_word_identifier_node?(identifier_node)
236
- end
237
- end
238
-
239
- # @param node [RuboCop::AST::Node]
240
- # @return [Boolean]
241
- def reserved_word_identifier_node?(node)
242
- return false unless node.respond_to?(:value)
243
-
244
- self.class.reserved_words.include?(node.value.to_s)
245
- end
246
- end
247
- end
248
- end
249
- end