rubocop-config-captive 2.0.0.pre.alpha.1 → 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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 025aa502d3ae6f6bf653e87ae00bdc61386dc3497706c87c2f6a30f3fb46e0e1
|
|
4
|
+
data.tar.gz: 498f927eb7dd914eb6416401cb06cd7ecc53d5fc839479e152a6bc978e9eb332
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de0db8c0afe4f0fdab648baba4a25fda50df28fabc4773eaa2bf28a12a3947add08da9d9d1bb6f0a375e9efa4729ac4487ecdc15ad252f3a267e7813e3e69b7b
|
|
7
|
+
data.tar.gz: 234503342ef955c2caf0929e3144d1db474361b8f5f56ea5589c4077f00e90852ce1146ac8aadfdd6aacf1373156f74d30e028e10b46c0057a4361ea5006c505
|
data/README.md
CHANGED
data/config/rubocop-captive.yml
CHANGED
|
@@ -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:
|
|
@@ -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
|
|
@@ -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
|
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.
|
|
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:
|
|
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:
|
|
226
|
+
version: '0'
|
|
227
227
|
requirements: []
|
|
228
|
-
rubygems_version: 3.
|
|
229
|
-
signing_key:
|
|
228
|
+
rubygems_version: 3.6.9
|
|
230
229
|
specification_version: 4
|
|
231
230
|
summary: Shared rubocop configurations
|
|
232
231
|
test_files: []
|