rubocop-config-captive 1.11.0 → 1.13.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: 3d97b68d10ca94ef35962dc273c1157d64839ac6b2fced7c99aed0f07f5eb4a7
4
- data.tar.gz: c98e237061db822fc35993bc780260340eb59bcae41b3cd252d04025effa8216
3
+ metadata.gz: b503af1733f071e5c225a59a847816f26d0875946d448922b6cc3b2a2ae6d9f2
4
+ data.tar.gz: e20df47f5ee50dc31edebc772837db84d83041bc6c825fa10e1cbf5c3c0f30d8
5
5
  SHA512:
6
- metadata.gz: 87ded8aca4ebc42f5eff1ff4bc5aa57c7f3289d02ba1f95c7b08b46f8ecd75927ffe49aa127d3f0066f004f6c5b81969a30f2137960e607c70c7b43230e74b83
7
- data.tar.gz: aa6036eeabf88151a60b912c0d805e1bbcedcfb36bf5e80d07c0ad5b4b6e55c98c3fc6fe7427e7ede5939657f5050d0227d5d6ac0698b4c6630118edd9ea38fa
6
+ metadata.gz: 462270c228e9abb16e6a204bcbd35f46051e71343688333b968ac2e3b347ed344c160d150ba4f58a0adcb56527db72067ae96810964164321c1d2f474aaaa1a6
7
+ data.tar.gz: 4aa2cad847ffb5f47859cd15288693cfa0bfb5fbd20eb2adc56689e181e65099aa393b181367c5ceb9d8813405739842c2c3e5e517a442b804f570fd12c3a490
@@ -7,6 +7,8 @@ require:
7
7
  - ../lib/rubocop/cop/captive/rails/force_ssl_enabled_in_production.rb
8
8
  - ../lib/rubocop/cop/captive/rails/migration_methods.rb
9
9
  - ../lib/rubocop/cop/captive/rails/no_email_from_controller.rb
10
+ - ../lib/rubocop/cop/captive/rails/no_float_price_columns.rb
11
+ - ../lib/rubocop/cop/captive/rails/no_find_by_in_scope.rb
10
12
  - ../lib/rubocop/cop/captive/string_where_in_scope.rb
11
13
  - ../lib/rubocop/cop/captive/no_app_env.rb
12
14
 
@@ -38,24 +40,31 @@ Captive/RSpec/SpecifyBeforeParameter:
38
40
  Include:
39
41
  - 'spec/**/*'
40
42
 
41
- # Rails
42
43
  Captive/Rails/ForceSslEnabledInProduction:
43
44
  Description: "Ensures SSL is forced in production, so that secure cookies are used."
44
45
  Include:
45
46
  - 'config/environments/production.rb'
46
47
 
47
- # Rails
48
48
  Captive/Rails/MigrationMethods:
49
49
  Description: "Avoid using ActiveRecord::Migration methods in `up` and `down` methods. Use `change` instead."
50
50
  Include:
51
51
  - 'db/migrate/**/*'
52
52
 
53
- # Rails
54
53
  Captive/Rails/NoEmailFromController:
55
54
  Description: "Do not send emails from controllers. Because it doesn't follow the MVC standard"
56
55
  Include:
57
56
  - 'app/controllers/**/*'
58
57
 
58
+ Captive/Rails/NoFloatPriceColumns:
59
+ Description: "Avoid using `float` type for price columns. Use `decimal, precision: 10, scale: 2` instead."
60
+ Include:
61
+ - 'db/migrate/**/*'
62
+
63
+ Captive/Rails/NoFindByInScope:
64
+ Description: "Avoid using `find_by` in a scope. Use `where` to return a collection or define a class method if you need a single record."
65
+ Include:
66
+ - 'app/models/**/*'
67
+
59
68
  # other
60
69
  Captive/StringWhereInScope:
61
70
  Description: 'The `where` method should be used in a scope in a model.'
@@ -3,6 +3,6 @@
3
3
  module RuboCop
4
4
  module Captive
5
5
  # Version information for the the Airbnb RuboCop plugin.
6
- VERSION = "1.11.0"
6
+ VERSION = "1.13.0"
7
7
  end
8
8
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Captive
6
+ module Rails
7
+ # Avoid using `find_by` in a scope. Use `where` to return a collection or define a class method if you need a single record.
8
+ class NoFindByInScope < RuboCop::Cop::Cop
9
+ MSG = "Avoid using `find_by` in a scope. Use `where` to return \
10
+ a collection or define a class method if you need a single record."
11
+
12
+ def_node_matcher :find_by_in_scope?, <<~PATTERN
13
+ (block
14
+ (send nil? :scope ...)
15
+ (args ...)
16
+ (send nil? :find_by ...))
17
+ PATTERN
18
+
19
+ def on_block(node)
20
+ find_by_in_scope?(node) do
21
+ add_offense(node, message: MSG)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Captive
6
+ module Rails
7
+ class NoFloatPriceColumns < Base
8
+ MSG = "Avoid using `float` type for price columns. \
9
+ Use `decimal, precision: 10, scale: 2` instead."
10
+
11
+ def_node_matcher :add_column_call?, <<~PATTERN
12
+ (send nil? :add_column _ $(sym {:price :prix}) (sym :float) ...)
13
+ PATTERN
14
+
15
+ def on_send(node)
16
+ add_column_call?(node) do |column|
17
+ add_offense(column, message: MSG)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-config-captive
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Captive
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-02-14 00:00:00.000000000 Z
13
+ date: 2024-09-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -187,6 +187,8 @@ files:
187
187
  - lib/rubocop/cop/captive/rails/force_ssl_enabled_in_production.rb
188
188
  - lib/rubocop/cop/captive/rails/migration_methods.rb
189
189
  - lib/rubocop/cop/captive/rails/no_email_from_controller.rb
190
+ - lib/rubocop/cop/captive/rails/no_find_by_in_scope.rb
191
+ - lib/rubocop/cop/captive/rails/no_float_price_columns.rb
190
192
  - lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
191
193
  - lib/rubocop/cop/captive/string_where_in_scope.rb
192
194
  - lib/rubocop/cop/captive/translation/devise_i18n_presence.rb
@@ -212,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
214
  - !ruby/object:Gem::Version
213
215
  version: '0'
214
216
  requirements: []
215
- rubygems_version: 3.3.26
217
+ rubygems_version: 3.3.27
216
218
  signing_key:
217
219
  specification_version: 4
218
220
  summary: Shared rubocop configurations