deprecool 0.1.1 → 0.1.2

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: e52876064a919fd936c1ce856a936497321260b30bb28d4af9583f1c4f408b2f
4
- data.tar.gz: e2f181b5779334b951ab52f209533608d565764a09d9633c22bcc282ff604b04
3
+ metadata.gz: 959b5cdb23ec0d5eef80f87185fb7a31a5646cf991cced0030d4d839fb835906
4
+ data.tar.gz: 87eac39b80c35af2e3bc868ab99b03d534f46f06e0f6ef6945381e5d00e8798b
5
5
  SHA512:
6
- metadata.gz: 2054d49032593500337f9f406c298852b0fb11b03e745217c0ebdda4d5e26aa89ea06ed9d84855269a7c1079d38c09a6bb27fd5ac5a35b9138ac626f2fc0db72
7
- data.tar.gz: f5014e5d52b173c5071f5622d892fc72783cbf61585cbed8d8a6845994ec704db0f3152055d2ae1074988b8be0331cac04134c73d797b6b8bc05c4dcdab7af34
6
+ metadata.gz: d6da4e681409697beeaad714e669ad6854000a66a9086a8bf593ded61016e3741beb5147d616a42d99c3e19b3d51ad886f432d056ba58db2e56a559b0188ae87
7
+ data.tar.gz: cd41a34a6787fb74f7985e9180893d46a765a19d369b90c09d23738a378ee645bce9d02109fda4e7806195f82bc94f9b0d2ac300ec6c69bf6d0ccb65c9e41e9a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Deprecool
2
2
 
3
- ## [0.1.0] - 2026-08-13
3
+ ## [0.1.2] - 2026-08-14
4
+
5
+ - Add Finder for Rails's deprecation of `write_attribute(:id, value)`
6
+
7
+ ## [0.1.0], [0.1.1] - 2026-08-13
4
8
 
5
9
  - Initial Release
data/README.md CHANGED
@@ -6,7 +6,8 @@ A helpful tool for any developer who has ever ignored a gem's warning and then r
6
6
 
7
7
  ## Usage
8
8
 
9
- Add to your Gemfile: `gem 'deprecool'`
9
+ Add to your Gemfile: `gem 'deprecool'`, and `bundle install`
10
+
10
11
  Or directly `gem install deprecool`
11
12
 
12
13
  Then you can run `deprecool` in the command line to get:
@@ -25,11 +25,10 @@ module Deprecool
25
25
 
26
26
  def on_call_node(node)
27
27
  return unless node.name == :serialize
28
+ return unless arguments_are_length(node.arguments, 2)
29
+ return unless unwrap_arguments(node.arguments)[1].is_a?(Prism::ConstantReadNode)
28
30
 
29
- arguments_array = unwrap_arguments(node.arguments)
30
- return unless arguments_array && arguments_array[1]
31
-
32
- add_offense(node, confidence: :high) if arguments_array[1].is_a?(Prism::ConstantReadNode)
31
+ add_offense(node, confidence: :high)
33
32
  end
34
33
  end
35
34
  end
@@ -7,7 +7,7 @@ module Deprecool
7
7
  class ToSqlBinds < Deprecool::Finder
8
8
  gem :rails
9
9
  deprecated_in '8.2.0'
10
- removed_in '8.3.0'
10
+ removed_in '9.0.0'
11
11
  title 'Passing "binds" into "to_sql" is deprecated'
12
12
  summary 'Since Rails 5.2, bind parameters live on the Arel AST ' \
13
13
  'to_sql_and_binds no longer uses binds for SQL construction, ' \
@@ -26,9 +26,7 @@ module Deprecool
26
26
  # if a method called 'to_sql' is passed two arguments and the second is an
27
27
  # array that's probably good enough
28
28
  return unless node.name == :to_sql
29
-
30
- arguments_array = unwrap_arguments(node.arguments)
31
- return unless arguments_array && arguments_array[1]
29
+ return unless arguments_are_length(node.arguments, 2)
32
30
 
33
31
  add_offense(node, confidence: :high)
34
32
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Deprecool
4
+ module Finders
5
+ module Rails
6
+ module V8_2_0
7
+ class WriteAttributeId < Deprecool::Finder
8
+ gem :rails
9
+ deprecated_in '8.2.0'
10
+ removed_in '9.0.0'
11
+ title 'Using "write_attribute" for the primary key is deprecated'
12
+ summary 'Just like Rails 7.1\'s deprecation of calling "read_attribute(:id)", '\
13
+ '"write_attribute(:id)" is now deprecated and will be removed in the next version of Rails. ' \
14
+ 'making :id refer only to the id column, not the primary key.'
15
+ suggestion 'Use "#id=" on a model whose primary key is not named "id"'
16
+ reference 'Original Rails Commit: https://github.com/rails/rails/commit/1a90632bbe62dae2626de7a058bc18c29f77aea6'
17
+ effort :low
18
+
19
+ def on_call_node(node)
20
+ return unless node.name == :write_attribute
21
+ return unless arguments_are_length(node.arguments, 2)
22
+ return unless arguments_contain(node.arguments, "id", position: 0)
23
+
24
+ add_offense(node, confidence: :high)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -36,4 +36,28 @@ module PrismHelpers
36
36
 
37
37
  node.child_nodes
38
38
  end
39
+
40
+ def arguments_are_length(node, length)
41
+ return false unless node.is_a?(Prism::ArgumentsNode)
42
+
43
+ unwrap_arguments(node.arguments).length == length
44
+ end
45
+
46
+ def arguments_contain(node, value, position: -1, kwarg: nil)
47
+ return false unless node.is_a?(Prism::ArgumentsNode)
48
+
49
+ arguments = unwrap_arguments(node)
50
+
51
+ return (value_from_argument(arguments[position]) == value) if position >= 0
52
+
53
+ arguments.any? do |arg|
54
+ value_from_argument(arg) == value
55
+ end
56
+ end
57
+
58
+ def value_from_argument(node)
59
+ case node
60
+ when Prism::SymbolNode, Prism::StringNode then node.unescaped
61
+ end
62
+ end
39
63
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deprecool
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deprecool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zac Radford
@@ -58,6 +58,7 @@ files:
58
58
  - lib/deprecool/finders/rails/v7.1.0/serializer_positional_class_argument.rb
59
59
  - lib/deprecool/finders/rails/v8.2.0/redis_cache_store_default_redis_options.rb
60
60
  - lib/deprecool/finders/rails/v8.2.0/to_sql_binds.rb
61
+ - lib/deprecool/finders/rails/v8.2.0/write_attribute_id.rb
61
62
  - lib/deprecool/finders/ruby/v4.0.0/object_space_id2ref.rb
62
63
  - lib/deprecool/finders/ruby/v4.0.0/to_set_arguments.rb
63
64
  - lib/deprecool/helpers/prism_helpers.rb