rubocop-rails_deprecation 0.3.0 → 0.6.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: d83f59fd0e86b57e1f9007ddcd710071091255333a97c4d58da168769f62b882
4
- data.tar.gz: 83824a404a65eb8d6d05d4946d1747823dab4d70fdcc5cd5a589e09c8cfdb67a
3
+ metadata.gz: 8cd931c5484f2340724c62e6027b6b9cb42fb5a66556a73a8b9776510f5bef53
4
+ data.tar.gz: 6aa4dcb475684c260b069c098dfab8fe9f59ec644ba4f0a883b2a63105cd21e0
5
5
  SHA512:
6
- metadata.gz: 8dddc57f6cc13086ff9b84d400156726fa06bd3c5468298cdf324088bad93e18c83f275bd17a01628a58f7ec06cfbd95f85bbebfd51a987c9ed426b3f839beba
7
- data.tar.gz: e5599be38bde11643bb4fe83edbf9a3722fee7e6139a8368acb3ee545dc58711b6784b63b3989f0412f7ecc9164150f7b61bb6fdc90092aa5c0a8341e43d84b5
6
+ metadata.gz: 0b221fc6c392b527f86c59eac7841781fe3c9fe94815451596c3b2134f01709accb3fae86befc3c92fd53fe2b3df106718fe2d8b435a737bfc4f06d328b6d9eb
7
+ data.tar.gz: 954e9a81b8c16d01ea55412123c9a8b72254379c01331ebd4309b9dd0e6e9c9a937a44ec3e6bf0417cbf5ca9dfc36456c710a689e52fd7fe63af4e4121d6990f
data/CHANGELOG.md CHANGED
@@ -2,7 +2,25 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
- ## 0.3.0
5
+ ## 0.6.0 - 2022-04-10
6
+
7
+ ### Added
8
+
9
+ - Add RailsDeprecation/WhereNot cop.
10
+
11
+ ## 0.5.0 - 2022-04-10
12
+
13
+ ### Changed
14
+
15
+ - Rename Deprecation/ToFormattedS with RailsDeprecation/ToFormattedS.
16
+
17
+ ## 0.4.0 - 2022-03-14
18
+
19
+ ### Added
20
+
21
+ - Support csend on RailsDeprecation/ToFormattedS.
22
+
23
+ ## 0.3.0 - 2022-03-14
6
24
 
7
25
  ### Changed
8
26
 
@@ -15,7 +33,7 @@
15
33
 
16
34
  - Make #to_fs the default replacement for #to_s(:format).
17
35
 
18
- ## 0.1.0
36
+ ## 0.1.0 - 2022-02-23
19
37
 
20
38
  ### Added
21
39
 
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-rails_deprecation (0.3.0)
5
- rubocop
4
+ rubocop-rails_deprecation (0.6.0)
5
+ rubocop (>= 1.27)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -29,13 +29,13 @@ GEM
29
29
  diff-lcs (>= 1.2.0, < 2.0)
30
30
  rspec-support (~> 3.11.0)
31
31
  rspec-support (3.11.0)
32
- rubocop (1.25.1)
32
+ rubocop (1.27.0)
33
33
  parallel (~> 1.10)
34
34
  parser (>= 3.1.0.0)
35
35
  rainbow (>= 2.2.2, < 4.0)
36
36
  regexp_parser (>= 1.8, < 3.0)
37
37
  rexml
38
- rubocop-ast (>= 1.15.1, < 2.0)
38
+ rubocop-ast (>= 1.16.0, < 2.0)
39
39
  ruby-progressbar (~> 1.7)
40
40
  unicode-display_width (>= 1.4.0, < 3.0)
41
41
  rubocop-ast (1.16.0)
data/config/default.yml CHANGED
@@ -1,4 +1,4 @@
1
- Deprecation/ToFormattedS:
1
+ RailsDeprecation/ToFormattedS:
2
2
  Description: Use `to_fs(...)` instead of `to_s(...)`.
3
3
  Enabled: true
4
4
  VersionAdded: '0.1'
@@ -2,12 +2,22 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Deprecation
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 :minimum_target_rails_version
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 <= version
31
+ (minimum_target_rails_version..maximum_target_rails_version).include?(version)
22
32
  end
23
33
  end
24
34
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Deprecation
5
+ module RailsDeprecation
6
6
  # This cop identifies passing a format to `#to_s`.
7
7
  #
8
8
  # @safety
@@ -30,7 +30,7 @@ module RuboCop
30
30
  MSG = 'Use `to_fs(...)` instead of `to_s(...)`.'
31
31
 
32
32
  def_node_matcher :to_s_with_any_argument?, <<~PATTERN
33
- (send _ :to_s _ ...)
33
+ ({csend | send} _ :to_s _ ...)
34
34
  PATTERN
35
35
 
36
36
  def on_send(node)
@@ -43,6 +43,7 @@ module RuboCop
43
43
  )
44
44
  end
45
45
  end
46
+ alias on_csend on_send
46
47
  end
47
48
  end
48
49
  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
@@ -2,3 +2,4 @@
2
2
 
3
3
  require_relative 'rails_deprecation/base'
4
4
  require_relative 'rails_deprecation/to_formatted_s'
5
+ require_relative 'rails_deprecation/where_not'
@@ -3,7 +3,7 @@
3
3
  # The original code is from https://github.com/rubocop/rubocop-rspec/blob/main/lib/rubocop/rspec/inject.rb
4
4
  # See https://github.com/rubocop/rubocop-rspec/blob/main/MIT-LICENSE.md
5
5
  module RuboCop
6
- module Deprecation
6
+ module RailsDeprecation
7
7
  # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
8
8
  # bit of our configuration.
9
9
  module Inject
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RuboCop
4
- module Deprecation
5
- VERSION = '0.3.0'
4
+ module RailsDeprecation
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
@@ -3,7 +3,7 @@
3
3
  require_relative 'rails_deprecation/version'
4
4
 
5
5
  module RuboCop
6
- module Deprecation
6
+ module RailsDeprecation
7
7
  class Error < StandardError; end
8
8
  # Your code goes here...
9
9
  PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
@@ -6,6 +6,6 @@ require_relative 'rubocop/rails_deprecation'
6
6
  require_relative 'rubocop/rails_deprecation/version'
7
7
  require_relative 'rubocop/rails_deprecation/inject'
8
8
 
9
- RuboCop::Deprecation::Inject.defaults!
9
+ RuboCop::RailsDeprecation::Inject.defaults!
10
10
 
11
11
  require_relative 'rubocop/cop/rails_deprecation_cops'
@@ -4,7 +4,7 @@ require_relative 'lib/rubocop/rails_deprecation/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'rubocop-rails_deprecation'
7
- spec.version = RuboCop::Deprecation::VERSION
7
+ spec.version = RuboCop::RailsDeprecation::VERSION
8
8
  spec.authors = ['Ryo Nakamura']
9
9
  spec.email = ['r7kamura@gmail.com']
10
10
 
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ['lib']
31
31
 
32
- spec.add_runtime_dependency 'rubocop'
32
+ spec.add_runtime_dependency 'rubocop', '>= 1.27'
33
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rails_deprecation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-14 00:00:00.000000000 Z
11
+ date: 2022-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1.27'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1.27'
27
27
  description:
28
28
  email:
29
29
  - r7kamura@gmail.com
@@ -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