carwow_rubocop 4.2.0 → 5.0.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: fb0368d67c7728b8bb6ae4427868535d8e1fca18fc91eaf7cf61409a74116827
4
- data.tar.gz: e0a7aee5cc8953d93e1aa5e5e85bc538b3c237f3306c4eb0e595df841066fe39
3
+ metadata.gz: e23461bfdf3292ee603d6094aaa3b6b5d6e0e9d5475e3db9bf7345674b57076d
4
+ data.tar.gz: ced30bc35295b82176b390599e33f9bb6b54a150be76c3c5e04bd2329a775855
5
5
  SHA512:
6
- metadata.gz: d681a96c87057770250378b262ca70963d4d20c5987daca64d26c45a8dac9de816775d911d57e0df522d7c08c381f8e9f6ee80e849c976e075b89ad8d737744b
7
- data.tar.gz: 4fae7c1ba3b2a704af6248f7a9e7e970cfcc75498ab6f0db637359f95afda913a6d663abbe44f68d658b7d1090a657111a6cd0d976a07673f46094c8ebba771e
6
+ metadata.gz: 9faf779b59d6ba0bf8cd5c5076869eb29b90874f0d845e3a95ba058d55bca36811476962c94b76ece7bd4f89a4b45517414d05a9021fe84f3297e2e9ad8f0892
7
+ data.tar.gz: b7dc05cf6539f33a19f17aa572f29985963c757288592782ffeb0298d4b400b4831af5ccbaec183856dec7cc9ac105802cd0e86b23ec46695a823bdf7bc1b67c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- carwow_rubocop (4.2.0)
4
+ carwow_rubocop (5.0.0)
5
5
  rubocop (>= 1.44)
6
6
  rubocop-performance
7
7
  rubocop-rspec
@@ -31,3 +31,8 @@ Carwow/NoStubbingBusinessEvent:
31
31
  Include: &spec_only
32
32
  - "**/*_spec.rb"
33
33
  - "**/spec/**/*"
34
+
35
+ Carwow/AddColumnWithComment:
36
+ Enabled: true
37
+ Include: &migrations_only
38
+ - "**/db/migrate/**/*.rb"
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module Carwow
3
- VERSION = '4.2.0'.freeze
3
+ VERSION = '5.0.0'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Carwow
8
+ # Checks the migration to confirm that new columns have a comment.
9
+ #
10
+ # @example
11
+ # # bad
12
+ # add_column :users, :name, :string
13
+ #
14
+ # # bad
15
+ # create_table :users do |t|
16
+ # t.string :name
17
+ # t.string :email
18
+ # end
19
+ #
20
+ # # good
21
+ # add_column :users, :name, :string, comment: 'The name of the user'
22
+ #
23
+ # # good
24
+ # create_table :users do |t|
25
+ # t.string :name, comment: 'The name of the user'
26
+ # t.string :email, comment: 'The email of the user'
27
+ # end
28
+ #
29
+ class AddColumnWithComment < Cop
30
+ MSG = "Missing 'comment' parameter for new column."
31
+
32
+ def_node_matcher :inside_create_table_block?, <<~PATTERN
33
+ (block (send nil? :create_table ...) (args ...) ...)
34
+ PATTERN
35
+
36
+ def_node_matcher :add_column?, <<~PATTERN
37
+ (send nil? :add_column ...)
38
+ PATTERN
39
+
40
+ def on_send(node)
41
+ return unless add_column?(node) || inside_create_table_block?(node.parent.parent)
42
+
43
+ # Timestamps and indexes do not need comments
44
+ return if %i[timestamps index].include?(node.method_name)
45
+
46
+ # Extract arguments
47
+ _receiver, _method_name, *args = *node
48
+
49
+ # Check if there is a 'comment' argument
50
+ comment_arg = find_comment_arg(args)
51
+
52
+ return if comment_arg
53
+
54
+ add_offense(node, location: :expression, message: MSG)
55
+ end
56
+
57
+ private
58
+
59
+ def find_comment_arg(args)
60
+ args.find { |arg| arg.hash_type? && arg.pairs.any? { |pair| pair.key.value == :comment } }
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carwow_rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - carwow Developers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-14 00:00:00.000000000 Z
11
+ date: 2023-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -144,6 +144,7 @@ files:
144
144
  - lib/rubocop/carwow.rb
145
145
  - lib/rubocop/carwow/inject.rb
146
146
  - lib/rubocop/carwow/version.rb
147
+ - lib/rubocop/cop/carwow/add_column_with_comment.rb
147
148
  - lib/rubocop/cop/carwow/jobs.rb
148
149
  - lib/rubocop/cop/carwow/jobs_must_define_queue.rb
149
150
  - lib/rubocop/cop/carwow/jobs_queue_name_style.rb
@@ -153,7 +154,7 @@ licenses:
153
154
  - MIT
154
155
  metadata:
155
156
  rubygems_mfa_required: 'true'
156
- post_install_message:
157
+ post_install_message:
157
158
  rdoc_options: []
158
159
  require_paths:
159
160
  - lib
@@ -169,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
170
  version: '0'
170
171
  requirements: []
171
172
  rubygems_version: 3.1.6
172
- signing_key:
173
+ signing_key:
173
174
  specification_version: 4
174
175
  summary: carwow's rubocop configuration
175
176
  test_files: []