rubocop-config-captive 1.9.7 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec5056c440c47a77d6ebdfd69d963c4772814f674abf69787c86e341924db80e
4
- data.tar.gz: 5e9e205eb6474d30048e1bb1b22ff9c9e1a958d3dbeece107c68ff3066eaa4e1
3
+ metadata.gz: 3d97b68d10ca94ef35962dc273c1157d64839ac6b2fced7c99aed0f07f5eb4a7
4
+ data.tar.gz: c98e237061db822fc35993bc780260340eb59bcae41b3cd252d04025effa8216
5
5
  SHA512:
6
- metadata.gz: 3a5092b21d89eb654468c1008dd185ccbba615e9237f1112f6d2689531f6a046ff9791b4845268e67b9ca306d60eac679ca3521cca73c9955cf58ae7a582f525
7
- data.tar.gz: c88be3fa86c62a12b903b3d238c69cb1280e17115ed693ef602fac6aa2c79bb1c205fbbab959ef560223cb7b05b89a69dbc0a4de8282c086e9204867d23f5e61
6
+ metadata.gz: 87ded8aca4ebc42f5eff1ff4bc5aa57c7f3289d02ba1f95c7b08b46f8ecd75927ffe49aa127d3f0066f004f6c5b81969a30f2137960e607c70c7b43230e74b83
7
+ data.tar.gz: aa6036eeabf88151a60b912c0d805e1bbcedcfb36bf5e80d07c0ad5b4b6e55c98c3fc6fe7427e7ede5939657f5050d0227d5d6ac0698b4c6630118edd9ea38fa
data/README.md CHANGED
@@ -110,3 +110,18 @@ To contribute, here are some inspirations for good configurations :
110
110
  [license-image]: https://img.shields.io/badge/license-MIT-green.svg?style=flat-square
111
111
  <!-- AUTO-GENERATED-CONTENT:END -->
112
112
  [license-url]: ./LICENSE
113
+
114
+ About Captive
115
+ -------------
116
+
117
+ ![captive](https://raw.githubusercontent.com/Captive-Studio/assets/main/logo_captive_blue_avec_fond.webp)
118
+
119
+ rubocop-config-captive is maintained and funded by Captive.
120
+ The names and logos for captive are trademarks of captive-studio.
121
+
122
+ We love open source software!
123
+ See [our other projects][community] or
124
+ [hire us][hire] to design, develop, and grow your product.
125
+
126
+ [community]: https://github.com/Captive-Studio
127
+ [hire]: https://www.captive.fr/contact?utm_source=github
@@ -4,8 +4,9 @@ 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/no_email_from_controller.rb
8
7
  - ../lib/rubocop/cop/captive/rails/force_ssl_enabled_in_production.rb
8
+ - ../lib/rubocop/cop/captive/rails/migration_methods.rb
9
+ - ../lib/rubocop/cop/captive/rails/no_email_from_controller.rb
9
10
  - ../lib/rubocop/cop/captive/string_where_in_scope.rb
10
11
  - ../lib/rubocop/cop/captive/no_app_env.rb
11
12
 
@@ -37,18 +38,24 @@ Captive/RSpec/SpecifyBeforeParameter:
37
38
  Include:
38
39
  - 'spec/**/*'
39
40
 
40
- # Rails
41
- Captive/Rails/NoEmailFromController:
42
- Description: "Do not send emails from controllers. Because it doesn't follow the MVC standard"
43
- Include:
44
- - 'app/controllers/**/*'
45
-
46
41
  # Rails
47
42
  Captive/Rails/ForceSslEnabledInProduction:
48
43
  Description: "Ensures SSL is forced in production, so that secure cookies are used."
49
44
  Include:
50
45
  - 'config/environments/production.rb'
51
46
 
47
+ # Rails
48
+ Captive/Rails/MigrationMethods:
49
+ Description: "Avoid using ActiveRecord::Migration methods in `up` and `down` methods. Use `change` instead."
50
+ Include:
51
+ - 'db/migrate/**/*'
52
+
53
+ # Rails
54
+ Captive/Rails/NoEmailFromController:
55
+ Description: "Do not send emails from controllers. Because it doesn't follow the MVC standard"
56
+ Include:
57
+ - 'app/controllers/**/*'
58
+
52
59
  # other
53
60
  Captive/StringWhereInScope:
54
61
  Description: 'The `where` method should be used in a scope in a model.'
@@ -27,13 +27,7 @@ MagicNumbers/NoAssignment:
27
27
  - '**/config/**/*'
28
28
 
29
29
  MagicNumbers/NoDefault:
30
- Enabled: true
31
- Exclude:
32
- - '**/spec/**/*.rb'
33
- - '**/test/**/*.rb'
34
- - '**/*_spec.rb'
35
- - '**/*_test.rb'
36
- - '**/config/**/*'
30
+ Enabled: false
37
31
 
38
32
  MagicNumbers/NoReturn:
39
33
  Enabled: true
@@ -13,3 +13,19 @@ RSpec/ScatteredSetup:
13
13
  RSpec/RepeatedExample:
14
14
  Exclude:
15
15
  - 'spec/requests/**/*'
16
+
17
+ RSpec/ContextWording:
18
+ Enabled: true
19
+ Prefixes:
20
+ - when
21
+ - with
22
+ - without
23
+ - if
24
+ - unless
25
+ - for
26
+ - quand
27
+ - avec
28
+ - sans
29
+ - si
30
+ - sauf si
31
+ - pour
@@ -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.9.7"
6
+ VERSION = "1.11.0"
7
7
  end
8
8
  end
@@ -16,17 +16,15 @@ module RuboCop
16
16
  extend AutoCorrector
17
17
 
18
18
  MSG = "force_ssl should be enabled in production."
19
+ GOOD_PRACTICE = "ENV[\"SKIP_FORCE_SSL\"].blank?"
19
20
 
20
21
  def on_send(node)
21
22
  if setting_force_ssl_not_true?(node)
22
23
  add_offense(node, message: MSG) do |corrector|
23
- # Replace with 'true' only if the argument is not already 'true'
24
- unless node.arguments.first.true_type?
25
- corrector.replace(
26
- node.arguments.first.source_range,
27
- "true"
28
- )
29
- end
24
+ corrector.replace(
25
+ node.arguments.first.source_range,
26
+ GOOD_PRACTICE
27
+ )
30
28
  end
31
29
  end
32
30
  end
@@ -40,14 +38,25 @@ module RuboCop
40
38
  private
41
39
 
42
40
  def setting_force_ssl_not_true?(node)
43
- node.method_name == :force_ssl= && !node.arguments.first.true_type?
41
+ node.method_name == :force_ssl= && node.arguments != [
42
+ s(
43
+ :send,
44
+ s(
45
+ :send,
46
+ s(:const, nil, :ENV),
47
+ :[],
48
+ s(:str, "SKIP_FORCE_SSL")
49
+ ),
50
+ :blank?
51
+ ),
52
+ ]
44
53
  end
45
54
 
46
55
  def check_comment(comment)
47
56
  return unless force_ssl_commented?(comment.text)
48
57
 
49
58
  add_offense(comment.loc.expression, message: MSG) do |corrector|
50
- corrector.replace(comment.loc.expression, "config.force_ssl = true")
59
+ corrector.replace(comment.loc.expression, "config.force_ssl = #{GOOD_PRACTICE}")
51
60
  end
52
61
  end
53
62
 
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Captive
6
+ module Rails
7
+ ##
8
+ # This cop ensures the use `change` method when is possible.
9
+ #
10
+ # Il est possible d'utiliser la méthode `change` lors de l'utilisation de méthode de ActiveRecord::Migration tel que : `remove_column`, `add_column`, `add_index`, ...
11
+ # La méthode gère automatiquement le UP et le DOWN.
12
+ # Il n'est donc pas nécéssaire définir le `def up` et `def down` seulement lors d'une migration de donnée
13
+ #
14
+ # @example
15
+ # # bad
16
+ # def up
17
+ # remove_column :table, :column, :type
18
+ # end
19
+ #
20
+ # def down
21
+ # add_column :table, :column, :type
22
+ # end
23
+ #
24
+ # # good
25
+ # def change
26
+ # remove_column :table, :column, :type
27
+ # end
28
+ #
29
+ # @see https://git.captive.fr/captive/iris-galerie/iris-platform/-/merge_requests/676#note_186669
30
+ class MigrationMethods < Base
31
+ MSG = "Avoid using ActiveRecord::Migration methods in `up` and `down` methods. \
32
+ Use `change` instead."
33
+
34
+ BLACKLISTED_METHODS = %i(
35
+ add_column
36
+ add_foreign_key
37
+ add_index
38
+ add_reference
39
+ add_timestamps
40
+ change_column
41
+ change_table
42
+ create_table
43
+ create_join_table
44
+ drop_table
45
+ remove_column
46
+ remove_foreign_key
47
+ remove_index
48
+ remove_reference
49
+ remove_timestamps
50
+ rename_column
51
+ rename_index
52
+ rename_table
53
+ ).freeze
54
+
55
+ def_node_search :migration_method?, <<~PATTERN
56
+ (send nil? {#{BLACKLISTED_METHODS.map(&:inspect).join(" ")}} ...)
57
+ PATTERN
58
+
59
+ def on_def(node)
60
+ return unless %i(up down).include?(node.method_name)
61
+ return unless migration_method?(node)
62
+
63
+ add_offense(node, message: MSG)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ 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.9.7
4
+ version: 1.11.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: 2023-11-16 00:00:00.000000000 Z
13
+ date: 2024-02-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -185,6 +185,7 @@ files:
185
185
  - lib/rubocop/cop/captive/active_admin/active_admin_addons_presence.rb
186
186
  - lib/rubocop/cop/captive/no_app_env.rb
187
187
  - lib/rubocop/cop/captive/rails/force_ssl_enabled_in_production.rb
188
+ - lib/rubocop/cop/captive/rails/migration_methods.rb
188
189
  - lib/rubocop/cop/captive/rails/no_email_from_controller.rb
189
190
  - lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
190
191
  - lib/rubocop/cop/captive/string_where_in_scope.rb