rubocop-rails_deprecation 0.5.0 → 0.6.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/lib/rubocop/cop/rails_deprecation/base.rb +12 -2
- data/lib/rubocop/cop/rails_deprecation/where_not.rb +50 -0
- data/lib/rubocop/cop/rails_deprecation_cops.rb +1 -0
- data/lib/rubocop/rails_deprecation/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cd931c5484f2340724c62e6027b6b9cb42fb5a66556a73a8b9776510f5bef53
|
4
|
+
data.tar.gz: 6aa4dcb475684c260b069c098dfab8fe9f59ec644ba4f0a883b2a63105cd21e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b221fc6c392b527f86c59eac7841781fe3c9fe94815451596c3b2134f01709accb3fae86befc3c92fd53fe2b3df106718fe2d8b435a737bfc4f06d328b6d9eb
|
7
|
+
data.tar.gz: 954e9a81b8c16d01ea55412123c9a8b72254379c01331ebd4309b9dd0e6e9c9a937a44ec3e6bf0417cbf5ca9dfc36456c710a689e52fd7fe63af4e4121d6990f
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -4,10 +4,20 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module RailsDeprecation
|
6
6
|
class Base < ::RuboCop::Cop::Base
|
7
|
+
DEFAULT_MAXIMUM_TARGET_RAILS_VERSION = ::Float::INFINITY
|
8
|
+
|
7
9
|
DEFAULT_MINIMUM_TARGET_RAILS_VERSION = 5.0
|
8
10
|
|
9
11
|
class << self
|
10
|
-
attr_writer
|
12
|
+
attr_writer(
|
13
|
+
:maximum_target_rails_version,
|
14
|
+
:minimum_target_rails_version
|
15
|
+
)
|
16
|
+
|
17
|
+
# @return [Float]
|
18
|
+
def maximum_target_rails_version
|
19
|
+
@maximum_target_rails_version ||= DEFAULT_MAXIMUM_TARGET_RAILS_VERSION
|
20
|
+
end
|
11
21
|
|
12
22
|
# @return [Float]
|
13
23
|
def minimum_target_rails_version
|
@@ -18,7 +28,7 @@ module RuboCop
|
|
18
28
|
# @param [Float] version
|
19
29
|
# @return [Boolean]
|
20
30
|
def support_target_rails_version?(version)
|
21
|
-
minimum_target_rails_version
|
31
|
+
(minimum_target_rails_version..maximum_target_rails_version).include?(version)
|
22
32
|
end
|
23
33
|
end
|
24
34
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RailsDeprecation
|
6
|
+
# This cop identifies passing Hash with multiple elements to `where.not`.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# where.not(key1: value1, key2: value2)
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# where.not(key1: value1).where.not(key2: value2)
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# where.not(key1: value1)
|
18
|
+
#
|
19
|
+
class WhereNot < Base
|
20
|
+
extend AutoCorrector
|
21
|
+
|
22
|
+
self.maximum_target_rails_version = 6.0
|
23
|
+
|
24
|
+
MSG = 'Use `where.not(key1: value1).where.not(key2: value2)` instead of `where.not(key1: value1, key2: value2)`.'
|
25
|
+
|
26
|
+
def_node_matcher :where_not_with_multiple_elements_hash?, <<~PATTERN
|
27
|
+
(send
|
28
|
+
(send _ :where) :not
|
29
|
+
({ hash | kwargs }
|
30
|
+
(pair _ _)
|
31
|
+
(pair _ _)+))
|
32
|
+
PATTERN
|
33
|
+
|
34
|
+
def on_send(node)
|
35
|
+
return unless where_not_with_multiple_elements_hash?(node)
|
36
|
+
|
37
|
+
add_offense(node) do |corrector|
|
38
|
+
pairs = node.children[2].children
|
39
|
+
last_end_pos = pairs[0].location.expression.end_pos
|
40
|
+
pairs[1..].each do |pair|
|
41
|
+
corrector.remove(pair.location.expression.with(begin_pos: last_end_pos))
|
42
|
+
last_end_pos = pair.location.expression.end_pos
|
43
|
+
corrector.insert_after(node.location.expression, ".where.not(#{pair.source})")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rails_deprecation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/rubocop-rails_deprecation.rb
|
45
45
|
- lib/rubocop/cop/rails_deprecation/base.rb
|
46
46
|
- lib/rubocop/cop/rails_deprecation/to_formatted_s.rb
|
47
|
+
- lib/rubocop/cop/rails_deprecation/where_not.rb
|
47
48
|
- lib/rubocop/cop/rails_deprecation_cops.rb
|
48
49
|
- lib/rubocop/rails_deprecation.rb
|
49
50
|
- lib/rubocop/rails_deprecation/inject.rb
|