leftovers 0.9.0 → 0.10.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 +9 -0
- data/docs/Configuration.md +28 -6
- data/lib/config/activerecord.yml +28 -6
- data/lib/leftovers/config_loader/has_receiver_schema.rb +15 -0
- data/lib/leftovers/config_loader/has_value_schema.rb +1 -1
- data/lib/leftovers/config_loader/rule_pattern_schema.rb +1 -1
- data/lib/leftovers/config_loader/value_matcher_condition_schema.rb +1 -1
- data/lib/leftovers/config_loader.rb +1 -0
- data/lib/leftovers/definition_node.rb +8 -14
- data/lib/leftovers/matcher_builders/node_has_receiver.rb +12 -3
- data/lib/leftovers/matcher_builders/node_value.rb +2 -0
- data/lib/leftovers/matchers/node_has_any_receiver.rb +13 -0
- data/lib/leftovers/matchers.rb +1 -0
- data/lib/leftovers/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2cb691dc74d8b0d43765f899ea718a4d06c1ba8fa36ea3a68c44ece27531920
|
4
|
+
data.tar.gz: e24ade3f01a888de2e9438736d71b0e4f2d159a6783b3278e8ec7e58e7c8c626
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a734ec1916762c5bc51fc212bfc254eb3d4083c968e6bcd128aa0c10ee9085762c6edbd86eb8afd3dd17ac5fa8b883d343bf34df3a3caaea1b84db5bc720bfaa
|
7
|
+
data.tar.gz: 7b80b90518a6a3e45aa3739394c18f4c7884ea07d75021dc919c62d23d6d110714c9969ab78b8078d6c219bfd9289a821bb4b828bc4e248a82a63f235cb7758f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# v0.10.0
|
2
|
+
- Fixed an issue with t.belongs_to (within the migration generated by rails active_storage:install - thanks @veganstraightedge)
|
3
|
+
- this was two issues:
|
4
|
+
1. it was raising an error because the DefinitionNode didn't act enough like an AST::Node, now it does
|
5
|
+
2. this should never have been defining anything anyway as the activerecord method was being assumed to be used, now if there's an explicit receiver for belongs_to/has_many etc, don't consider them the active record association methods.
|
6
|
+
|
7
|
+
- now `has_receiver: true` and `has_receiver: false/nil` act differently, they refer to the presence or absence of any receiver, instead of the receiver being literally true or false or nil.
|
8
|
+
- to have the previous behaviour, use the new `has_receiver: { literal: true }` or `literal: false` or `literal: null`
|
9
|
+
|
1
10
|
# v0.9.0
|
2
11
|
- Automatically test the config examples in the documentation, and fix the errors
|
3
12
|
- simplify the `type: Proc` matcher
|
data/docs/Configuration.md
CHANGED
@@ -504,7 +504,7 @@ and when used in:
|
|
504
504
|
|
505
505
|
It can have any of these properties:
|
506
506
|
- [`at:`](#at)
|
507
|
-
- [`has_value:`](#
|
507
|
+
- [`has_value:`](#has_value)
|
508
508
|
|
509
509
|
Arrays are not necessary for single values and if the rule contains only `at:` it can be omitted, and the values moved up a level.
|
510
510
|
|
@@ -522,7 +522,7 @@ The method call/constant variable/assignment will be considered matching if it h
|
|
522
522
|
|
523
523
|
It can have any of these properties:
|
524
524
|
- [`at:`](#at)
|
525
|
-
- [`has_value:`](#
|
525
|
+
- [`has_value:`](#has_value)
|
526
526
|
|
527
527
|
Arrays are not necessary for single values and if the rule contains only `at:` it can be omitted, and the values moved up a level
|
528
528
|
|
@@ -603,9 +603,9 @@ dynamic:
|
|
603
603
|
will match the first argument of anything named my_method or with the receiver MyReceiver, that have both the keyword arguments part_a and part_b
|
604
604
|
|
605
605
|
|
606
|
-
## `has_value
|
606
|
+
## `has_value:`
|
607
607
|
|
608
|
-
filter [`arguments:`](#arguments), [`has_arguments:`](#has_arguments), and [`keywords:`](#keywords), by the argument/assigned
|
608
|
+
filter [`arguments:`](#arguments), [`has_arguments:`](#has_arguments), and [`keywords:`](#keywords), by the argument/assigned value
|
609
609
|
|
610
610
|
Each entry can be one of
|
611
611
|
- `true`, `false`, `nil`, or an Integer. matches the literal value
|
@@ -616,11 +616,33 @@ Each entry can be one of
|
|
616
616
|
- [`matches:`](#matches)
|
617
617
|
- or have at least one of the following properties to match within an array or hash:
|
618
618
|
- [`at`](#at)
|
619
|
-
- [`has_value`](#
|
619
|
+
- [`has_value`](#has_value)
|
620
620
|
- or have the following property to match the value type
|
621
621
|
- [`type`](#type)
|
622
622
|
- or have the following property to match the receiver
|
623
|
-
- [`has_receiver`](#
|
623
|
+
- [`has_receiver`](#has_receiver)
|
624
|
+
|
625
|
+
## `has_receiver:`
|
626
|
+
|
627
|
+
filter [`dynamic:`](#dynamic), and [`keep:`](#keep), by the receiver presence or value
|
628
|
+
|
629
|
+
Each entry can be one of
|
630
|
+
- `true`, `false`, matches the presence of any receiver or not
|
631
|
+
- an Integer. matches the literal value
|
632
|
+
- a String. matches the literal string or symbol value
|
633
|
+
- or have at least one of the following properties to match the name:
|
634
|
+
- [`has_prefix:`](#has_prefix)
|
635
|
+
- [`has_suffix:`](#has_suffix)
|
636
|
+
- [`matches:`](#matches)
|
637
|
+
- or have at least one of the following properties to match the literal value or match within an array or hash:
|
638
|
+
- [`at`](#at)
|
639
|
+
- [`has_value`](#has_value)
|
640
|
+
- or have the following property to match the value type
|
641
|
+
- [`type`](#type)
|
642
|
+
- or have the following property to match the receiver of the receiver
|
643
|
+
- [`has_receiver`](#has_receiver)
|
644
|
+
- or have the following property to match a literal true, false, or nil value:
|
645
|
+
- `literal: true`, or `literal: false`, or `literal: nil`
|
624
646
|
|
625
647
|
## `privacy:`
|
626
648
|
|
data/lib/config/activerecord.yml
CHANGED
@@ -88,6 +88,8 @@ dynamic:
|
|
88
88
|
|
89
89
|
# https://edgeapi.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html
|
90
90
|
- name: has_one
|
91
|
+
unless:
|
92
|
+
has_receiver: true
|
91
93
|
defines:
|
92
94
|
argument: 0
|
93
95
|
transforms:
|
@@ -100,6 +102,8 @@ dynamic:
|
|
100
102
|
|
101
103
|
- name: belongs_to
|
102
104
|
has_argument: polymorphic
|
105
|
+
unless:
|
106
|
+
has_receiver: true
|
103
107
|
defines:
|
104
108
|
argument: 0
|
105
109
|
transforms:
|
@@ -111,7 +115,9 @@ dynamic:
|
|
111
115
|
|
112
116
|
- name: belongs_to
|
113
117
|
unless:
|
114
|
-
|
118
|
+
any:
|
119
|
+
- has_argument: polymorphic
|
120
|
+
- has_receiver: true
|
115
121
|
defines:
|
116
122
|
argument: 0
|
117
123
|
transforms:
|
@@ -125,6 +131,8 @@ dynamic:
|
|
125
131
|
- add_suffix: _previously_changed?
|
126
132
|
|
127
133
|
- name: [has_and_belongs_to_many, has_many]
|
134
|
+
unless:
|
135
|
+
has_receiver: true
|
128
136
|
defines:
|
129
137
|
argument: 0
|
130
138
|
transforms:
|
@@ -139,7 +147,9 @@ dynamic:
|
|
139
147
|
- has_one
|
140
148
|
- belongs_to
|
141
149
|
unless:
|
142
|
-
|
150
|
+
any:
|
151
|
+
- has_argument: [class_name, polymorphic]
|
152
|
+
- has_receiver: true
|
143
153
|
calls:
|
144
154
|
argument: 0
|
145
155
|
camelize: true
|
@@ -149,7 +159,9 @@ dynamic:
|
|
149
159
|
- has_many
|
150
160
|
- has_and_belongs_to_many
|
151
161
|
unless:
|
152
|
-
|
162
|
+
any:
|
163
|
+
- has_argument: [class_name, polymorphic]
|
164
|
+
- has_receiver: true
|
153
165
|
calls:
|
154
166
|
- argument: 0
|
155
167
|
camelize: true
|
@@ -174,9 +186,11 @@ dynamic:
|
|
174
186
|
|
175
187
|
- name: belongs_to
|
176
188
|
unless:
|
177
|
-
|
178
|
-
|
179
|
-
|
189
|
+
any:
|
190
|
+
- has_argument:
|
191
|
+
at: optional
|
192
|
+
has_value: true
|
193
|
+
- has_receiver: true
|
180
194
|
calls:
|
181
195
|
argument: 0
|
182
196
|
|
@@ -185,6 +199,8 @@ dynamic:
|
|
185
199
|
- has_many
|
186
200
|
- belongs_to
|
187
201
|
- has_and_belongs_to_many
|
202
|
+
unless:
|
203
|
+
has_receiver: true
|
188
204
|
calls:
|
189
205
|
- argument: class_name
|
190
206
|
split: '::'
|
@@ -193,6 +209,8 @@ dynamic:
|
|
193
209
|
add_suffix: '='
|
194
210
|
|
195
211
|
- name: belongs_to
|
212
|
+
unless:
|
213
|
+
has_receiver: true
|
196
214
|
calls:
|
197
215
|
argument: ensuring_owner_was
|
198
216
|
|
@@ -202,6 +220,8 @@ dynamic:
|
|
202
220
|
- has_many
|
203
221
|
- belongs_to
|
204
222
|
- has_and_belongs_to_many
|
223
|
+
unless:
|
224
|
+
has_receiver: true
|
205
225
|
has_argument:
|
206
226
|
at:
|
207
227
|
- dependent
|
@@ -219,6 +239,8 @@ dynamic:
|
|
219
239
|
argument: 0
|
220
240
|
|
221
241
|
- name: [has_one, has_many, belongs_to, has_and_belongs_to_many]
|
242
|
+
unless:
|
243
|
+
has_receiver: true
|
222
244
|
calls:
|
223
245
|
argument: [before_add, after_add, before_remove, after_remove]
|
224
246
|
nested: '*'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
class ConfigLoader
|
5
|
+
class HasReceiverSchema < ValueOrObjectSchema
|
6
|
+
inherit_attributes_from HasValueSchema, except: :unless
|
7
|
+
|
8
|
+
attribute :literal, ValueOrArraySchema[ScalarValueSchema],
|
9
|
+
require_group: :matcher
|
10
|
+
attribute :unless, ValueOrArraySchema[HasReceiverSchema], require_group: :matcher
|
11
|
+
|
12
|
+
self.or_value_schema = ScalarValueSchema
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -12,7 +12,7 @@ module Leftovers
|
|
12
12
|
attribute :at, ValueOrArraySchema[ArgumentPositionSchema], require_group: :matcher
|
13
13
|
attribute :has_value, ValueOrArraySchema[HasValueSchema], require_group: :matcher
|
14
14
|
|
15
|
-
attribute :has_receiver, ValueOrArraySchema[
|
15
|
+
attribute :has_receiver, ValueOrArraySchema[HasReceiverSchema], require_group: :matcher
|
16
16
|
attribute :type, ValueOrArraySchema[ValueTypeSchema], require_group: :matcher
|
17
17
|
attribute :unless, ValueOrArraySchema[HasValueSchema], require_group: :matcher
|
18
18
|
|
@@ -9,7 +9,7 @@ module Leftovers
|
|
9
9
|
attribute :document, TrueSchema, require_group: :matcher
|
10
10
|
attribute :has_arguments, ValueOrArraySchema[HasArgumentSchema], aliases: :has_argument,
|
11
11
|
require_group: :matcher
|
12
|
-
attribute :has_receiver, ValueOrArraySchema[
|
12
|
+
attribute :has_receiver, ValueOrArraySchema[HasReceiverSchema], require_group: :matcher
|
13
13
|
attribute :type, ValueOrArraySchema[ValueTypeSchema], require_group: :matcher
|
14
14
|
attribute :privacy, ValueOrArraySchema[PrivacySchema], require_group: :matcher
|
15
15
|
attribute :unless, ValueOrArraySchema[RulePatternSchema], require_group: :matcher
|
@@ -4,7 +4,7 @@ module Leftovers
|
|
4
4
|
class ConfigLoader
|
5
5
|
class ValueMatcherConditionSchema < ObjectSchema
|
6
6
|
attribute :has_arguments, ValueOrArraySchema[HasArgumentSchema], aliases: :has_argument
|
7
|
-
attribute :has_receiver, ValueOrArraySchema[
|
7
|
+
attribute :has_receiver, ValueOrArraySchema[HasReceiverSchema]
|
8
8
|
attribute :unless, ValueOrArraySchema[ValueMatcherConditionSchema]
|
9
9
|
attribute :all, ArraySchema[ValueMatcherConditionSchema]
|
10
10
|
attribute :any, ArraySchema[ValueMatcherConditionSchema]
|
@@ -13,6 +13,7 @@ module Leftovers
|
|
13
13
|
autoload(:DynamicSchema, "#{__dir__}/config_loader/dynamic_schema")
|
14
14
|
autoload(:HasArgumentSchema, "#{__dir__}/config_loader/has_argument_schema")
|
15
15
|
autoload(:HasValueSchema, "#{__dir__}/config_loader/has_value_schema")
|
16
|
+
autoload(:HasReceiverSchema, "#{__dir__}/config_loader/has_receiver_schema")
|
16
17
|
autoload(:InheritSchemaAttributes, "#{__dir__}/config_loader/inherit_schema_attributes")
|
17
18
|
autoload(:KeepTestOnlySchema, "#{__dir__}/config_loader/keep_test_only_schema")
|
18
19
|
autoload(:KeywordArgumentSchema, "#{__dir__}/config_loader/keyword_argument_schema")
|
@@ -1,25 +1,19 @@
|
|
1
1
|
# frozen-string-literal: true
|
2
2
|
|
3
3
|
module Leftovers
|
4
|
-
class DefinitionNode
|
5
|
-
attr_reader :name, :
|
4
|
+
class DefinitionNode < ::Leftovers::AST::Node
|
5
|
+
attr_reader :name, :path
|
6
|
+
alias_method :to_sym, :name
|
6
7
|
|
7
8
|
def initialize(node, name:, location: node.loc.expression)
|
8
|
-
@node = node
|
9
9
|
@name = name
|
10
|
-
@
|
10
|
+
@path = node.path
|
11
|
+
@location = location
|
12
|
+
super(:leftovers_definition)
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def positional_arguments
|
18
|
-
nil
|
19
|
-
end
|
20
|
-
|
21
|
-
def path
|
22
|
-
node.path
|
15
|
+
def to_s
|
16
|
+
name.to_s
|
23
17
|
end
|
24
18
|
end
|
25
19
|
end
|
@@ -4,10 +4,19 @@ module Leftovers
|
|
4
4
|
module MatcherBuilders
|
5
5
|
module NodeHasReceiver
|
6
6
|
class << self
|
7
|
-
def build(pattern)
|
8
|
-
|
7
|
+
def build(pattern) # rubocop:disable Metrics/MethodLength
|
8
|
+
case pattern
|
9
|
+
when true
|
10
|
+
::Leftovers::Matchers::NodeHasAnyReceiver
|
11
|
+
when false, :_leftovers_nil_value
|
12
|
+
::Leftovers::Matchers::Not.new(
|
13
|
+
::Leftovers::Matchers::NodeHasAnyReceiver
|
14
|
+
)
|
15
|
+
else
|
16
|
+
matcher = ::Leftovers::MatcherBuilders::NodeValue.build(pattern)
|
9
17
|
|
10
|
-
|
18
|
+
::Leftovers::Matchers::NodeHasReceiver.new(matcher) if matcher
|
19
|
+
end
|
11
20
|
end
|
12
21
|
end
|
13
22
|
end
|
@@ -53,6 +53,7 @@ module Leftovers
|
|
53
53
|
names: nil, match: nil, has_prefix: nil, has_suffix: nil,
|
54
54
|
type: nil,
|
55
55
|
has_receiver: nil,
|
56
|
+
literal: nil,
|
56
57
|
unless_arg: nil
|
57
58
|
)
|
58
59
|
::Leftovers::MatcherBuilders::And.build([
|
@@ -60,6 +61,7 @@ module Leftovers
|
|
60
61
|
build_node_name_matcher(names, match, has_prefix, has_suffix),
|
61
62
|
::Leftovers::MatcherBuilders::NodeType.build(type),
|
62
63
|
::Leftovers::MatcherBuilders::NodeHasReceiver.build(has_receiver),
|
64
|
+
::Leftovers::MatcherBuilders::NodeValue.build(literal),
|
63
65
|
build_unless(unless_arg)
|
64
66
|
])
|
65
67
|
end
|
data/lib/leftovers/matchers.rb
CHANGED
@@ -10,6 +10,7 @@ module Leftovers
|
|
10
10
|
:NodeHasAnyPositionalArgumentWithValue,
|
11
11
|
"#{__dir__}/matchers/node_has_any_positional_argument_with_value"
|
12
12
|
)
|
13
|
+
autoload(:NodeHasAnyReceiver, "#{__dir__}/matchers/node_has_any_receiver")
|
13
14
|
autoload(
|
14
15
|
:NodeHasPositionalArgumentWithValue,
|
15
16
|
"#{__dir__}/matchers/node_has_positional_argument_with_value"
|
data/lib/leftovers/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leftovers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dana Sherson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -409,6 +409,7 @@ files:
|
|
409
409
|
- lib/leftovers/config_loader/document_schema.rb
|
410
410
|
- lib/leftovers/config_loader/dynamic_schema.rb
|
411
411
|
- lib/leftovers/config_loader/has_argument_schema.rb
|
412
|
+
- lib/leftovers/config_loader/has_receiver_schema.rb
|
412
413
|
- lib/leftovers/config_loader/has_value_schema.rb
|
413
414
|
- lib/leftovers/config_loader/inherit_schema_attributes.rb
|
414
415
|
- lib/leftovers/config_loader/keep_test_only_schema.rb
|
@@ -477,6 +478,7 @@ files:
|
|
477
478
|
- lib/leftovers/matchers/any.rb
|
478
479
|
- lib/leftovers/matchers/node_has_any_keyword_argument.rb
|
479
480
|
- lib/leftovers/matchers/node_has_any_positional_argument_with_value.rb
|
481
|
+
- lib/leftovers/matchers/node_has_any_receiver.rb
|
480
482
|
- lib/leftovers/matchers/node_has_positional_argument.rb
|
481
483
|
- lib/leftovers/matchers/node_has_positional_argument_with_value.rb
|
482
484
|
- lib/leftovers/matchers/node_has_receiver.rb
|
@@ -586,7 +588,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
586
588
|
- !ruby/object:Gem::Version
|
587
589
|
version: '0'
|
588
590
|
requirements: []
|
589
|
-
|
591
|
+
rubyforge_project:
|
592
|
+
rubygems_version: 2.7.6
|
590
593
|
signing_key:
|
591
594
|
specification_version: 4
|
592
595
|
summary: Find unused methods and classes/modules
|