rubocop-config-captive 2.0.0.pre.alpha → 2.0.1

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: 89d7f60a4c0f6bf82d38c7edb07550329610e4582994eab5fb226f24f89c8151
4
- data.tar.gz: 05efb5230791a782bf022fba4b8b8846b2afda8d9a4ffb59e6762e182ff54ef7
3
+ metadata.gz: 025aa502d3ae6f6bf653e87ae00bdc61386dc3497706c87c2f6a30f3fb46e0e1
4
+ data.tar.gz: 498f927eb7dd914eb6416401cb06cd7ecc53d5fc839479e152a6bc978e9eb332
5
5
  SHA512:
6
- metadata.gz: '08acab7ddee1ce4de738918def23ef8dd9604f6983f2cda849ee3fe61f8e880a2d10d29a2eeff871f5679fabdacc175b3cd31757af81d5093bc0b42a5e866fc6'
7
- data.tar.gz: 337bd6708b8a78899344d7d768b691b3b3d8748ceb48933a611cf7df0f5179091acacd97db5d66a7b5b6304f1bffb3f5ff88e310bc7b6c3d16bf38271dc4e03d
6
+ metadata.gz: de0db8c0afe4f0fdab648baba4a25fda50df28fabc4773eaa2bf28a12a3947add08da9d9d1bb6f0a375e9efa4729ac4487ecdc15ad252f3a267e7813e3e69b7b
7
+ data.tar.gz: 234503342ef955c2caf0929e3144d1db474361b8f5f56ea5589c4077f00e90852ce1146ac8aadfdd6aacf1373156f74d30e028e10b46c0057a4361ea5006c505
data/README.md CHANGED
@@ -11,7 +11,7 @@ add the follow line into your `Gemfile`
11
11
 
12
12
  ```ruby
13
13
  group :test, :development do
14
- gem 'rubocop-config-captive'
14
+ gem 'rubocop-config-captive', '~> 2.0'
15
15
  end
16
16
  ```
17
17
 
@@ -1,6 +1,5 @@
1
1
  ### ⚠️ GENERATED WITH `script/pull`. DO NOT EDIT MANUALLY. ###
2
- require:
3
- - rubocop-capybara
2
+ plugins: rubocop-capybara
4
3
 
5
4
  Capybara/CurrentPathExpectation:
6
5
  Description: Checks that no expectations are set on Capybara's `current_path`.
@@ -48,7 +48,7 @@ Naming/MethodName:
48
48
  - snake_case
49
49
  - camelCase
50
50
 
51
- Naming/PredicateName:
51
+ Naming/PredicatePrefix:
52
52
  Description: Check the names of predicate methods.
53
53
  StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#bool-methods-qmark
54
54
  Enabled: false
@@ -4,8 +4,10 @@ require:
4
4
  - ../lib/rubocop/cop/captive/translation/rails_i18n_presence.rb
5
5
  - ../lib/rubocop/cop/captive/translation/kaminari_i18n_presence.rb
6
6
  - ../lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
7
+ - ../lib/rubocop/cop/captive/rails/after_commit_not_allowed.rb
7
8
  - ../lib/rubocop/cop/captive/rails/force_ssl_enabled_in_production.rb
8
9
  - ../lib/rubocop/cop/captive/rails/migration_methods.rb
10
+ - ../lib/rubocop/cop/captive/rails/no_disable_ddl_transaction.rb
9
11
  - ../lib/rubocop/cop/captive/rails/no_email_from_controller.rb
10
12
  - ../lib/rubocop/cop/captive/rails/no_float_price_columns.rb
11
13
  - ../lib/rubocop/cop/captive/rails/no_find_by_in_scope.rb
@@ -40,6 +42,16 @@ Captive/RSpec/SpecifyBeforeParameter:
40
42
  Include:
41
43
  - 'spec/**/*'
42
44
 
45
+ # Rails
46
+ Captive/Rails/AfterCommitNotAllowed:
47
+ Description: "Interdit l'utilisation de `after_commit` dans les modèles Rails."
48
+ Severity: error
49
+ Enabled: true
50
+ Include:
51
+ - 'app/models/**/*.rb'
52
+ Exclude: []
53
+ Match: 'after_commit'
54
+
43
55
  Captive/Rails/ForceSslEnabledInProduction:
44
56
  Description: "Ensures SSL is forced in production, so that secure cookies are used."
45
57
  Include:
@@ -50,6 +62,11 @@ Captive/Rails/MigrationMethods:
50
62
  Include:
51
63
  - 'db/migrate/**/*'
52
64
 
65
+ Captive/Rails/NoDisableDdlTransaction:
66
+ Description: "Avoid using 'disable_ddl_transaction!' in migrations."
67
+ Include:
68
+ - 'db/migrate/**/*'
69
+
53
70
  Captive/Rails/NoEmailFromController:
54
71
  Description: "Do not send emails from controllers. Because it doesn't follow the MVC standard"
55
72
  Include:
@@ -1,2 +1 @@
1
- require:
2
- - rubocop-capybara
1
+ plugins: rubocop-capybara
@@ -1,2 +1 @@
1
- require:
2
- - rubocop-factory_bot
1
+ plugins: rubocop-factory_bot
@@ -1,2 +1,2 @@
1
- require:
2
- - rubocop-rails-omakase
1
+ inherit_gem:
2
+ rubocop-rails-omakase: rubocop.yml
@@ -1,2 +1 @@
1
- require:
2
- - rubocop-rake
1
+ plugins: rubocop-rake
@@ -11,7 +11,7 @@ module RuboCop
11
11
  path = CONFIG_DEFAULT.to_s
12
12
  hash = ConfigLoader.load_file(path).to_hash
13
13
  config = Config.new(hash, path)
14
- puts "configuration from #{path}" if ConfigLoader.debug?
14
+ Rails.logger.debug "configuration from #{path}" if ConfigLoader.debug?
15
15
  config = ConfigLoader.merge_with_default(config, path)
16
16
  ConfigLoader.instance_variable_set(:@default_configuration, config)
17
17
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Captive
5
- VERSION = "2.0.0-alpha"
5
+ VERSION = "2.0.1"
6
6
  end
7
7
  end
@@ -0,0 +1,52 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Captive
4
+ module Rails
5
+ # This cop checks for the use of `after_commit` in Rails models.
6
+ # Using `after_commit` can lead to unexpected behaviors and is discouraged.
7
+ # Instead, consider using a service object to handle the logic that would
8
+ # otherwise be placed inside an `after_commit` callback.
9
+ #
10
+ # For more information, see the documentation:
11
+ # https://captive.notion.site/Quota-expir-PDF-Monkey-25e707bff8eb8094ba48ecc564fe5bd7?source=copy_link
12
+ #
13
+ # @example
14
+ # # bad
15
+ # class MyModel < ApplicationRecord
16
+ # after_commit :some_method
17
+ # end
18
+ #
19
+ # # good
20
+ # class MyModel < ApplicationRecord
21
+ # def save_something
22
+ # MyService.new(self).call
23
+ # end
24
+ # end
25
+ #
26
+ # # better
27
+ # # Use a service object for handling post-persistence logic
28
+ # class MyService
29
+ # def initialize(model)
30
+ # @model = model
31
+ # end
32
+ #
33
+ # def call
34
+ # # Perform the operations needed after commit
35
+ # end
36
+ # end
37
+ class AfterCommitNotAllowed < Base
38
+ MSG = "Interdit l'utilisation de `after_commit` dans les modèles Rails. \
39
+ Utilisez un service plutôt."
40
+
41
+ def_node_matcher :after_commit?, <<~PATTERN
42
+ (send nil? :after_commit ...)
43
+ PATTERN
44
+
45
+ def on_send(node)
46
+ add_offense(node, message: MSG) if after_commit?(node)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -31,7 +31,7 @@ module RuboCop
31
31
  MSG = "Avoid using ActiveRecord::Migration methods in `up` and `down` methods. \
32
32
  Use `change` instead."
33
33
 
34
- BLACKLISTED_METHODS = %i(
34
+ BLACKLISTED_METHODS = %i[
35
35
  add_column
36
36
  add_foreign_key
37
37
  add_index
@@ -50,14 +50,14 @@ module RuboCop
50
50
  rename_column
51
51
  rename_index
52
52
  rename_table
53
- ).freeze
53
+ ].freeze
54
54
 
55
55
  def_node_search :migration_method?, <<~PATTERN
56
56
  (send nil? {#{BLACKLISTED_METHODS.map(&:inspect).join(" ")}} ...)
57
57
  PATTERN
58
58
 
59
59
  def on_def(node)
60
- return unless %i(up down).include?(node.method_name)
60
+ return unless %i[up down].include?(node.method_name)
61
61
  return unless migration_method?(node)
62
62
 
63
63
  add_offense(node, message: MSG)
@@ -0,0 +1,44 @@
1
+ # lib/rubocop/no_disable_ddl_transaction.rb
2
+ module RuboCop
3
+ module Cop
4
+ module Captive
5
+ module Rails
6
+ ##
7
+ # Cette migration utilise `disable_ddl_transaction!`, ce qui peut rendre le comportement de la migration
8
+ # difficile à prévoir et potentiellement dangereux. Voici pourquoi il est important de l'éviter :
9
+ #
10
+ # 1. **Transactions atomiques :** Les migrations sont généralement exécutées dans une transaction afin de garantir
11
+ # que toutes les modifications d'une migration réussissent ou échouent ensemble. Cela permet de maintenir la
12
+ # cohérence de la base de données.
13
+ #
14
+ # 2. **Erreurs de schéma :** En désactivant la transaction, une erreur survenant lors de l'application des modifications
15
+ # peut laisser la base de données dans un état intermédiaire, ce qui complique le débogage et le retour en arrière.
16
+ #
17
+ # 3. **Verrouillage des tables :** Les opérations DDL sans transaction peuvent provoquer un verrouillage prolongé de
18
+ # la base de données, impactant la performance et l'accessibilité des tables pour d'autres requêtes pendant
19
+ # l'exécution de la migration.
20
+ #
21
+ # 4. **Difficulté de maintenance :** L'absence de transactions peut rendre plus difficile la maintenance de l'application,
22
+ # car il devient plus compliqué de conserver un historique clair des modifications apportées au schéma.
23
+ #
24
+ # Pour toutes ces raisons, nous devons éviter d'utiliser `disable_ddl_transaction!` afin de garantir une gestion
25
+ # sécurisée et fiable des migrations.
26
+ #
27
+ # @see https://captive-team.atlassian.net/browse/CAE-290?focusedCommentId=24501
28
+ class NoDisableDdlTransaction < Base
29
+ MSG = "Avoid using 'disable_ddl_transaction!' in migrations.".freeze
30
+
31
+ def_node_matcher :disable_ddl_transaction?, <<~PATTERN
32
+ (send nil? :disable_ddl_transaction!)
33
+ PATTERN
34
+
35
+ def on_send(node)
36
+ return unless disable_ddl_transaction?(node)
37
+
38
+ add_offense(node)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
8
8
  gem.version = RuboCop::Captive::VERSION
9
9
  gem.summary = "Shared rubocop configurations"
10
10
  gem.description = "Shared rubocop configuration for Captive projects"
11
- gem.authors = ["Captive", "Julien Polo", "Clément Prod'homme"]
12
- gem.email = ["julien.polo@captive.fr"]
11
+ gem.authors = [ "Captive", "Julien Polo", "Clément Prod'homme" ]
12
+ gem.email = [ "julien.polo@captive.fr" ]
13
13
  gem.homepage = "https://github.com/Captive-Studio/rubocop-config"
14
14
  gem.license = "MIT"
15
15
  gem.required_ruby_version = ">= 2.6"
@@ -21,6 +21,8 @@ Gem::Specification.new do |gem|
21
21
  "Gemfile",
22
22
  ]
23
23
 
24
+ # Pour mettre à jour les dépendances, vous pouvez utiliser le script :
25
+ # ruby script/update_dependencies.rb
24
26
  gem.add_dependency("rubocop", "~> 1.77.0")
25
27
  gem.add_dependency("rubocop-performance", "~> 1.25.0")
26
28
  gem.add_dependency("rubocop-rake", "~> 0.7.1")
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-config-captive
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.alpha
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Captive
8
8
  - Julien Polo
9
9
  - Clément Prod'homme
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2025-06-24 00:00:00.000000000 Z
12
+ date: 1980-01-02 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rubocop
@@ -195,8 +194,10 @@ files:
195
194
  - lib/rubocop/captive/version.rb
196
195
  - lib/rubocop/cop/captive/active_admin/active_admin_addons_presence.rb
197
196
  - lib/rubocop/cop/captive/no_app_env.rb
197
+ - lib/rubocop/cop/captive/rails/after_commit_not_allowed.rb
198
198
  - lib/rubocop/cop/captive/rails/force_ssl_enabled_in_production.rb
199
199
  - lib/rubocop/cop/captive/rails/migration_methods.rb
200
+ - lib/rubocop/cop/captive/rails/no_disable_ddl_transaction.rb
200
201
  - lib/rubocop/cop/captive/rails/no_email_from_controller.rb
201
202
  - lib/rubocop/cop/captive/rails/no_find_by_in_scope.rb
202
203
  - lib/rubocop/cop/captive/rails/no_float_price_columns.rb
@@ -210,7 +211,6 @@ homepage: https://github.com/Captive-Studio/rubocop-config
210
211
  licenses:
211
212
  - MIT
212
213
  metadata: {}
213
- post_install_message:
214
214
  rdoc_options: []
215
215
  require_paths:
216
216
  - lib
@@ -221,12 +221,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
221
221
  version: '2.6'
222
222
  required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  requirements:
224
- - - ">"
224
+ - - ">="
225
225
  - !ruby/object:Gem::Version
226
- version: 1.3.1
226
+ version: '0'
227
227
  requirements: []
228
- rubygems_version: 3.3.27
229
- signing_key:
228
+ rubygems_version: 3.6.9
230
229
  specification_version: 4
231
230
  summary: Shared rubocop configurations
232
231
  test_files: []