rubocop-rails 2.35.4 → 2.35.5
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 +4 -4
- data/lib/rubocop/cop/rails/env.rb +15 -2
- data/lib/rubocop/cop/rails/save_bang.rb +10 -1
- data/lib/rubocop/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5620166bbbdcac74d58be7dec4ea307fc841d7cd31ffd9684f422009d00b8754
|
|
4
|
+
data.tar.gz: 7c156916d1a363419097086b305baf6010361473443602ea477ff03894c5e350
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fccc029e306ebaf72e1809005110005d18416b9d314c347b24b2381bdd84fa70c9e2d175633501618881c883e205ae0e79ed9aef3dcee4d4b16f6b02fce51818
|
|
7
|
+
data.tar.gz: 704f46a2a6c8b53eeeb8ac8ac60bfb25c39aa096e3b99516b132405f604729f48a877066b0531697e6ab8f1f65a9638435013c6610c5be5767e0b955d7d17300
|
|
@@ -5,22 +5,34 @@ module RuboCop
|
|
|
5
5
|
module Rails
|
|
6
6
|
# Checks for usage of `Rails.env` which can be replaced with Feature Flags
|
|
7
7
|
#
|
|
8
|
+
# The cop does not flag `Rails.env.local?`, the built-in alias for
|
|
9
|
+
# "development or test" introduced in Rails 7.1. Unlike per-environment
|
|
10
|
+
# predicates such as `development?` or `production?`, `local?` expresses
|
|
11
|
+
# the intent of guarding code that must only ever run in development or
|
|
12
|
+
# test (sanity checks, devtools, seed data) rather than gating an
|
|
13
|
+
# environment rollout, so a Feature Flag is not a suitable replacement.
|
|
14
|
+
#
|
|
8
15
|
# @example
|
|
9
16
|
#
|
|
10
17
|
# # bad
|
|
11
|
-
# Rails.env.production? || Rails.env.
|
|
18
|
+
# Rails.env.production? || Rails.env.development?
|
|
12
19
|
#
|
|
13
20
|
# # good
|
|
14
21
|
# if FeatureFlag.enabled?(:new_feature)
|
|
15
22
|
# # new feature code
|
|
16
23
|
# end
|
|
17
24
|
#
|
|
25
|
+
# # good
|
|
26
|
+
# raise 'This should never run in production' unless Rails.env.local?
|
|
27
|
+
#
|
|
18
28
|
class Env < Base
|
|
19
29
|
MSG = 'Use Feature Flags or config instead of `Rails.env`.'
|
|
20
30
|
RESTRICT_ON_SEND = %i[env].freeze
|
|
21
31
|
# This allow list is derived from:
|
|
22
32
|
# (Rails.env.methods - Object.instance_methods).select { |m| m.to_s.end_with?('?') }
|
|
23
|
-
# and then removing the environment specific methods like development?, test?, production
|
|
33
|
+
# and then removing the environment specific methods like development?, test?, and production?.
|
|
34
|
+
# `local?` is kept on the allow list because it intentionally expresses
|
|
35
|
+
# "development or test" rather than a single environment rollout.
|
|
24
36
|
ALLOWED_LIST = Set.new(
|
|
25
37
|
%i[
|
|
26
38
|
unicode_normalized?
|
|
@@ -38,6 +50,7 @@ module RuboCop
|
|
|
38
50
|
valid_encoding?
|
|
39
51
|
ascii_only?
|
|
40
52
|
between?
|
|
53
|
+
local?
|
|
41
54
|
]
|
|
42
55
|
).freeze
|
|
43
56
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# rubocop:disable Metrics/ClassLength
|
|
3
4
|
module RuboCop
|
|
4
5
|
module Cop
|
|
5
6
|
module Rails
|
|
@@ -303,13 +304,20 @@ module RuboCop
|
|
|
303
304
|
def implicit_return?(node)
|
|
304
305
|
return false unless cop_config['AllowImplicitReturn']
|
|
305
306
|
|
|
306
|
-
node = assignable_node(node)
|
|
307
|
+
node = last_expression_in_begin(assignable_node(node))
|
|
307
308
|
method, sibling_index = find_method_with_sibling_index(node.parent)
|
|
308
309
|
return false unless method&.type?(:def, :any_block)
|
|
309
310
|
|
|
310
311
|
method.children.size == node.sibling_index + sibling_index
|
|
311
312
|
end
|
|
312
313
|
|
|
314
|
+
# A multiline method or block body is wrapped in a `begin` node, so climb
|
|
315
|
+
# to it when the node is the last expression, to detect the implicit return.
|
|
316
|
+
def last_expression_in_begin(node)
|
|
317
|
+
node = node.parent while node.parent&.begin_type? && node.right_sibling.nil?
|
|
318
|
+
node
|
|
319
|
+
end
|
|
320
|
+
|
|
313
321
|
def find_method_with_sibling_index(node, sibling_index = 1)
|
|
314
322
|
return node, sibling_index unless node&.or_type?
|
|
315
323
|
|
|
@@ -348,3 +356,4 @@ module RuboCop
|
|
|
348
356
|
end
|
|
349
357
|
end
|
|
350
358
|
end
|
|
359
|
+
# rubocop:enable Metrics/ClassLength
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.35.
|
|
4
|
+
version: 2.35.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bozhidar Batsov
|
|
@@ -287,7 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
287
287
|
- !ruby/object:Gem::Version
|
|
288
288
|
version: '0'
|
|
289
289
|
requirements: []
|
|
290
|
-
rubygems_version: 4.0.
|
|
290
|
+
rubygems_version: 4.0.10
|
|
291
291
|
specification_version: 4
|
|
292
292
|
summary: Automatic Rails code style checking tool.
|
|
293
293
|
test_files: []
|