leftovers 0.5.4 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -1
- data/README.md +21 -1
- data/docs/Configuration.md +188 -20
- data/leftovers.gemspec +8 -5
- data/lib/config/actionmailer.yml +11 -11
- data/lib/config/actionpack.yml +11 -0
- data/lib/config/activesupport.yml +1 -1
- data/lib/config/rails.yml +1 -1
- data/lib/config/railties.yml +11 -0
- data/lib/config/ruby.yml +79 -0
- data/lib/leftovers/ast/node.rb +16 -11
- data/lib/leftovers/collector.rb +3 -1
- data/lib/leftovers/config.rb +9 -28
- data/lib/leftovers/config_loader/argument_position_schema.rb +11 -0
- data/lib/leftovers/config_loader/argumentless_transform_schema.rb +21 -0
- data/lib/leftovers/config_loader/attribute.rb +30 -0
- data/lib/leftovers/config_loader/document_schema.rb +21 -0
- data/lib/leftovers/config_loader/dynamic_schema.rb +17 -0
- data/lib/leftovers/config_loader/has_argument_schema.rb +13 -0
- data/lib/leftovers/config_loader/has_value_schema.rb +18 -0
- data/lib/leftovers/config_loader/keep_test_only_schema.rb +13 -0
- data/lib/leftovers/config_loader/node.rb +106 -0
- data/lib/leftovers/config_loader/object_schema.rb +189 -0
- data/lib/leftovers/config_loader/privacy_processor_schema.rb +12 -0
- data/lib/leftovers/config_loader/privacy_schema.rb +15 -0
- data/lib/leftovers/config_loader/require_schema.rb +11 -0
- data/lib/leftovers/config_loader/rule_pattern_schema.rb +18 -0
- data/lib/leftovers/config_loader/scalar_argument_schema.rb +14 -0
- data/lib/leftovers/config_loader/scalar_value_schema.rb +14 -0
- data/lib/leftovers/config_loader/schema.rb +21 -0
- data/lib/leftovers/config_loader/string_enum_schema.rb +62 -0
- data/lib/leftovers/config_loader/string_pattern_schema.rb +14 -0
- data/lib/leftovers/config_loader/string_schema.rb +14 -0
- data/lib/leftovers/config_loader/string_value_processor_schema.rb +11 -0
- data/lib/leftovers/config_loader/suggester.rb +22 -0
- data/lib/leftovers/config_loader/transform_schema.rb +28 -0
- data/lib/leftovers/config_loader/true_schema.rb +18 -0
- data/lib/leftovers/config_loader/value_matcher_schema.rb +18 -0
- data/lib/leftovers/config_loader/value_or_array_schema.rb +64 -0
- data/lib/leftovers/config_loader/value_processor_schema.rb +14 -0
- data/lib/leftovers/config_loader/value_type_schema.rb +17 -0
- data/lib/leftovers/config_loader.rb +82 -0
- data/lib/leftovers/definition.rb +1 -1
- data/lib/leftovers/definition_node.rb +6 -17
- data/lib/leftovers/definition_node_set.rb +11 -0
- data/lib/leftovers/definition_to_add.rb +31 -0
- data/lib/leftovers/dynamic_processors/call.rb +4 -7
- data/lib/leftovers/dynamic_processors/call_definition.rb +14 -11
- data/lib/leftovers/dynamic_processors/definition.rb +8 -7
- data/lib/leftovers/dynamic_processors/set_default_privacy.rb +18 -0
- data/lib/leftovers/dynamic_processors/set_privacy.rb +23 -0
- data/lib/leftovers/dynamic_processors.rb +2 -0
- data/lib/leftovers/file.rb +57 -11
- data/lib/leftovers/file_collector.rb +77 -19
- data/lib/leftovers/json.rb +28 -0
- data/lib/leftovers/matcher_builders/document.rb +13 -0
- data/lib/leftovers/matcher_builders/node.rb +7 -1
- data/lib/leftovers/matcher_builders/node_has_argument.rb +3 -4
- data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +1 -1
- data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +1 -1
- data/lib/leftovers/matcher_builders/node_privacy.rb +13 -0
- data/lib/leftovers/matcher_builders/node_type.rb +4 -4
- data/lib/leftovers/matcher_builders/node_value.rb +1 -1
- data/lib/leftovers/matcher_builders/string_pattern.rb +14 -5
- data/lib/leftovers/matcher_builders.rb +2 -0
- data/lib/leftovers/matchers/all.rb +0 -4
- data/lib/leftovers/matchers/and.rb +0 -4
- data/lib/leftovers/matchers/any.rb +0 -4
- data/lib/leftovers/matchers/node_has_any_keyword_argument.rb +1 -7
- data/lib/leftovers/matchers/node_has_any_positional_argument_with_value.rb +1 -7
- data/lib/leftovers/matchers/node_has_positional_argument_with_value.rb +0 -4
- data/lib/leftovers/matchers/node_name.rb +0 -4
- data/lib/leftovers/matchers/node_pair_value.rb +0 -4
- data/lib/leftovers/matchers/node_path.rb +0 -4
- data/lib/leftovers/matchers/node_privacy.rb +19 -0
- data/lib/leftovers/matchers/node_scalar_value.rb +0 -4
- data/lib/leftovers/matchers/node_type.rb +0 -4
- data/lib/leftovers/matchers/not.rb +0 -4
- data/lib/leftovers/matchers/or.rb +0 -4
- data/lib/leftovers/matchers.rb +1 -0
- data/lib/leftovers/merged_config.rb +25 -23
- data/lib/leftovers/processor_builders/add_prefix.rb +1 -1
- data/lib/leftovers/processor_builders/add_suffix.rb +1 -1
- data/lib/leftovers/processor_builders/dynamic.rb +51 -16
- data/lib/leftovers/processor_builders/transform.rb +2 -2
- data/lib/leftovers/processor_builders/transform_set.rb +8 -8
- data/lib/leftovers/todo_reporter.rb +10 -35
- data/lib/leftovers/value_processors/delete_prefix.rb +0 -6
- data/lib/leftovers/value_processors/delete_suffix.rb +0 -6
- data/lib/leftovers/value_processors/each_for_definition_set.rb +2 -5
- data/lib/leftovers/value_processors/each_positional_argument.rb +1 -1
- data/lib/leftovers/value_processors/keyword.rb +0 -4
- data/lib/leftovers/value_processors/keyword_argument.rb +0 -4
- data/lib/leftovers/value_processors/return_definition_node.rb +14 -0
- data/lib/leftovers/value_processors/{return_string.rb → return_sym.rb} +1 -1
- data/lib/leftovers/value_processors.rb +2 -2
- data/lib/leftovers/version.rb +1 -1
- data/lib/leftovers/yaml.rb +73 -0
- data/lib/leftovers.rb +29 -21
- metadata +85 -36
- data/lib/config/actioncable.yml +0 -4
- data/lib/leftovers/backports.rb +0 -40
- data/lib/leftovers/config_validator/error_processor.rb +0 -196
- data/lib/leftovers/config_validator/schema_hash.rb +0 -530
- data/lib/leftovers/config_validator.rb +0 -60
- data/lib/leftovers/value_processors/return_definition.rb +0 -26
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
class ConfigLoader
|
5
|
+
class Schema
|
6
|
+
class << self
|
7
|
+
def error(node, requirement)
|
8
|
+
node.error = "#{node.name_}must #{requirement}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def validate(node)
|
12
|
+
node.valid?
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_ruby(node)
|
16
|
+
node.to_ruby
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
class ConfigLoader
|
5
|
+
class StringEnumSchema < Schema
|
6
|
+
class << self
|
7
|
+
def value(value, aliases: nil)
|
8
|
+
values << value
|
9
|
+
Leftovers.each_or_self(aliases) do |alias_name|
|
10
|
+
self.aliases[alias_name] = value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def aliases
|
15
|
+
@aliases ||= {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def aliases_for(value)
|
19
|
+
aliases.select { |_k, v| v == value }.keys
|
20
|
+
end
|
21
|
+
|
22
|
+
def values
|
23
|
+
@values ||= []
|
24
|
+
end
|
25
|
+
|
26
|
+
def each_value(&block)
|
27
|
+
@values.each(&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_ruby(node)
|
31
|
+
aliases[node.to_sym]&.to_s || node.to_ruby
|
32
|
+
end
|
33
|
+
|
34
|
+
def validate(node)
|
35
|
+
if node.string?
|
36
|
+
node.error = error_message_with_suggestions(node) unless valid_value?(node.to_sym)
|
37
|
+
else
|
38
|
+
error(node, 'be a string')
|
39
|
+
end
|
40
|
+
|
41
|
+
super
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def valid_value?(val)
|
47
|
+
values.include?(val) || aliases.key?(val)
|
48
|
+
end
|
49
|
+
|
50
|
+
def suggester
|
51
|
+
@suggester ||= Suggester.new(values)
|
52
|
+
end
|
53
|
+
|
54
|
+
def error_message_with_suggestions(node)
|
55
|
+
suggestions = suggester.suggest(node.to_ruby)
|
56
|
+
|
57
|
+
"unrecognized value #{node} for #{node.name}\nDid you mean: #{suggestions.join(', ')}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
class ConfigLoader
|
5
|
+
class StringPatternSchema < ObjectSchema
|
6
|
+
attribute :match, StringSchema, aliases: :matches, require_group: :matcher
|
7
|
+
attribute :has_prefix, StringSchema, require_group: :matcher
|
8
|
+
attribute :has_suffix, StringSchema, require_group: :matcher
|
9
|
+
attribute :unless, ValueOrArraySchema[StringPatternSchema], require_group: :matcher
|
10
|
+
|
11
|
+
self.or_schema = StringSchema
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
class ConfigLoader
|
5
|
+
class Suggester
|
6
|
+
def initialize(words)
|
7
|
+
@words = words
|
8
|
+
@did_you_mean = ::DidYouMean::SpellChecker.new(dictionary: words) if defined?(::DidYouMean)
|
9
|
+
end
|
10
|
+
|
11
|
+
def suggest(word)
|
12
|
+
suggestions = did_you_mean.correct(word) if did_you_mean
|
13
|
+
suggestions = words if !suggestions || suggestions.empty?
|
14
|
+
suggestions
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :words, :did_you_mean
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
class ConfigLoader
|
5
|
+
class TransformSchema < ObjectSchema
|
6
|
+
ArgumentlessTransformSchema.each_value do |transform|
|
7
|
+
attribute(
|
8
|
+
transform, TrueSchema,
|
9
|
+
aliases: ArgumentlessTransformSchema.aliases_for(transform),
|
10
|
+
require_group: :processor
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
attribute :add_prefix, ValueOrArraySchema[StringValueProcessorSchema],
|
15
|
+
require_group: :processor
|
16
|
+
attribute :add_suffix, ValueOrArraySchema[StringValueProcessorSchema],
|
17
|
+
require_group: :processor
|
18
|
+
|
19
|
+
attribute :split, StringSchema, require_group: :processor
|
20
|
+
attribute :delete_prefix, StringSchema, require_group: :processor
|
21
|
+
attribute :delete_suffix, StringSchema, require_group: :processor
|
22
|
+
attribute :delete_before, StringSchema, require_group: :processor
|
23
|
+
attribute :delete_after, StringSchema, require_group: :processor
|
24
|
+
|
25
|
+
self.or_schema = ArgumentlessTransformSchema
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
class ConfigLoader
|
5
|
+
class TrueSchema < Schema
|
6
|
+
class << self
|
7
|
+
def validate(node)
|
8
|
+
error(node, 'be true') unless to_ruby(node)
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_ruby(node)
|
13
|
+
node.to_ruby == true || node.to_ruby == 'true'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
class ConfigLoader
|
5
|
+
class ValueMatcherSchema < ObjectSchema
|
6
|
+
attribute :arguments, ValueOrArraySchema[ArgumentPositionSchema], aliases: :argument,
|
7
|
+
require_group: :matcher
|
8
|
+
attribute :keywords, ValueOrArraySchema[StringPatternSchema], aliases: :keyword,
|
9
|
+
require_group: :matcher
|
10
|
+
attribute :itself, TrueSchema, require_group: :matcher
|
11
|
+
attribute :nested, ValueOrArraySchema[ValueMatcherSchema]
|
12
|
+
attribute :value, StringSchema, require_group: :matcher
|
13
|
+
attribute :recursive, TrueSchema
|
14
|
+
|
15
|
+
self.or_schema = ScalarArgumentSchema
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
class ConfigLoader
|
5
|
+
class ValueOrArraySchema < Schema
|
6
|
+
class << self
|
7
|
+
def [](value_schema)
|
8
|
+
new(value_schema)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :value_schema
|
13
|
+
|
14
|
+
def initialize(value_schema)
|
15
|
+
@value_schema = value_schema
|
16
|
+
|
17
|
+
super()
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate(node)
|
21
|
+
if node.array?
|
22
|
+
validate_length(node) && validate_values(node)
|
23
|
+
else
|
24
|
+
validate_or_schema(node)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_ruby(node)
|
29
|
+
if node.array?
|
30
|
+
node.children.map do |value|
|
31
|
+
value_schema.to_ruby(value)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
value_schema.to_ruby(node)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def validate_or_schema(node)
|
41
|
+
value_schema.validate(node)
|
42
|
+
return true if node.valid?
|
43
|
+
|
44
|
+
node.error += ' or an array'
|
45
|
+
|
46
|
+
false
|
47
|
+
end
|
48
|
+
|
49
|
+
def validate_length(node)
|
50
|
+
self.class.error(node, 'not be empty') if node.children.empty?
|
51
|
+
|
52
|
+
node.valid?
|
53
|
+
end
|
54
|
+
|
55
|
+
def validate_values(node)
|
56
|
+
node.children.each do |value|
|
57
|
+
value_schema.validate(value)
|
58
|
+
end
|
59
|
+
|
60
|
+
node.children.all?(&:valid?)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
class ConfigLoader
|
5
|
+
class ValueProcessorSchema < ObjectSchema
|
6
|
+
inherit_attributes_from ValueMatcherSchema
|
7
|
+
|
8
|
+
attribute :transforms, ValueOrArraySchema[TransformSchema]
|
9
|
+
inherit_attributes_from TransformSchema, require_group: nil
|
10
|
+
|
11
|
+
self.or_schema = ScalarArgumentSchema
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
class ConfigLoader
|
5
|
+
class ValueTypeSchema < StringEnumSchema
|
6
|
+
value :String
|
7
|
+
value :Symbol
|
8
|
+
value :Integer
|
9
|
+
value :Float
|
10
|
+
value :Array
|
11
|
+
value :Hash
|
12
|
+
value :Proc
|
13
|
+
value :Method
|
14
|
+
value :Constant
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'leftovers'
|
5
|
+
|
6
|
+
module Leftovers
|
7
|
+
class ConfigLoader
|
8
|
+
autoload(:ArgumentPositionSchema, "#{__dir__}/config_loader/argument_position_schema")
|
9
|
+
autoload(:ArgumentlessTransformSchema, "#{__dir__}/config_loader/argumentless_transform_schema")
|
10
|
+
autoload(:Attribute, "#{__dir__}/config_loader/attribute")
|
11
|
+
autoload(:DocumentSchema, "#{__dir__}/config_loader/document_schema")
|
12
|
+
autoload(:DynamicSchema, "#{__dir__}/config_loader/dynamic_schema")
|
13
|
+
autoload(:HasArgumentSchema, "#{__dir__}/config_loader/has_argument_schema")
|
14
|
+
autoload(:HasValueSchema, "#{__dir__}/config_loader/has_value_schema")
|
15
|
+
autoload(:KeepTestOnlySchema, "#{__dir__}/config_loader/keep_test_only_schema")
|
16
|
+
autoload(:Node, "#{__dir__}/config_loader/node")
|
17
|
+
autoload(:ObjectSchema, "#{__dir__}/config_loader/object_schema")
|
18
|
+
autoload(:PrivacyProcessorSchema, "#{__dir__}/config_loader/privacy_processor_schema")
|
19
|
+
autoload(:PrivacySchema, "#{__dir__}/config_loader/privacy_schema")
|
20
|
+
autoload(:RequireSchema, "#{__dir__}/config_loader/require_schema")
|
21
|
+
autoload(:RulePatternSchema, "#{__dir__}/config_loader/rule_pattern_schema")
|
22
|
+
autoload(:ScalarArgumentSchema, "#{__dir__}/config_loader/scalar_argument_schema")
|
23
|
+
autoload(:ScalarValueSchema, "#{__dir__}/config_loader/scalar_value_schema")
|
24
|
+
autoload(:Schema, "#{__dir__}/config_loader/schema")
|
25
|
+
autoload(:Suggester, "#{__dir__}/config_loader/suggester")
|
26
|
+
autoload(:StringEnumSchema, "#{__dir__}/config_loader/string_enum_schema")
|
27
|
+
autoload(:StringPatternSchema, "#{__dir__}/config_loader/string_pattern_schema")
|
28
|
+
autoload(:StringSchema, "#{__dir__}/config_loader/string_schema")
|
29
|
+
autoload(:StringValueProcessorSchema, "#{__dir__}/config_loader/string_value_processor_schema")
|
30
|
+
autoload(:TransformSchema, "#{__dir__}/config_loader/transform_schema")
|
31
|
+
autoload(:TrueSchema, "#{__dir__}/config_loader/true_schema")
|
32
|
+
autoload(:ValueMatcherSchema, "#{__dir__}/config_loader/value_matcher_schema")
|
33
|
+
autoload(:ValueOrArraySchema, "#{__dir__}/config_loader/value_or_array_schema")
|
34
|
+
autoload(:ValueProcessorSchema, "#{__dir__}/config_loader/value_processor_schema")
|
35
|
+
autoload(:ValueTypeSchema, "#{__dir__}/config_loader/value_type_schema")
|
36
|
+
|
37
|
+
def self.load(name, path: nil, content: nil)
|
38
|
+
new(name, path: path, content: content).load
|
39
|
+
end
|
40
|
+
|
41
|
+
attr_reader :name
|
42
|
+
|
43
|
+
def initialize(name, path: nil, content: nil)
|
44
|
+
@name = name
|
45
|
+
@path = path
|
46
|
+
@content = content
|
47
|
+
end
|
48
|
+
|
49
|
+
def load
|
50
|
+
document = ::Leftovers::ConfigLoader::Node.new(parse, file)
|
51
|
+
DocumentSchema.validate(document)
|
52
|
+
|
53
|
+
all_errors = document.all_errors
|
54
|
+
return DocumentSchema.to_ruby(document) if all_errors.empty?
|
55
|
+
|
56
|
+
Leftovers.error(all_errors.join("\n"))
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def path
|
62
|
+
@path ||= ::File.expand_path("../config/#{name}.yml", __dir__)
|
63
|
+
end
|
64
|
+
|
65
|
+
def file
|
66
|
+
@file ||= ::Leftovers::File.new(path)
|
67
|
+
end
|
68
|
+
|
69
|
+
def content
|
70
|
+
@content ||= file.exist? ? file.read : ''
|
71
|
+
end
|
72
|
+
|
73
|
+
def parse
|
74
|
+
parsed = Psych.parse(content)
|
75
|
+
parsed ||= Psych.parse('{}')
|
76
|
+
parsed.children.first
|
77
|
+
rescue ::Psych::SyntaxError => e
|
78
|
+
message = [e.problem, e.context].compact.join(' ')
|
79
|
+
Leftovers.error "Config SyntaxError: #{file.relative_path}:#{e.line}:#{e.column} #{message}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/leftovers/definition.rb
CHANGED
@@ -10,7 +10,7 @@ module Leftovers
|
|
10
10
|
def initialize(
|
11
11
|
name,
|
12
12
|
location: method_node.loc.expression,
|
13
|
-
test: method_node.test_line?
|
13
|
+
test: method_node.test_line? || ::Leftovers.config.test_only === method_node
|
14
14
|
)
|
15
15
|
@name = name
|
16
16
|
@path = location.source_buffer.name.to_s
|
@@ -1,19 +1,15 @@
|
|
1
1
|
# frozen-string-literal: true
|
2
2
|
|
3
|
-
# To give to matchers before creating a Definition
|
4
|
-
|
5
3
|
module Leftovers
|
6
4
|
class DefinitionNode
|
7
|
-
attr_reader :
|
5
|
+
attr_reader :name, :loc, :node
|
8
6
|
|
9
|
-
def initialize(
|
7
|
+
def initialize(node, name:, location: node.loc.expression)
|
8
|
+
@node = node
|
10
9
|
@name = name
|
11
|
-
@
|
12
|
-
|
13
|
-
freeze
|
10
|
+
@loc = location
|
14
11
|
end
|
15
12
|
|
16
|
-
# these are the methods checked by things in lib/leftovers/matchers
|
17
13
|
def kwargs
|
18
14
|
nil
|
19
15
|
end
|
@@ -22,15 +18,8 @@ module Leftovers
|
|
22
18
|
nil
|
23
19
|
end
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
def scalar?
|
28
|
-
false
|
29
|
-
end
|
30
|
-
|
31
|
-
def type
|
32
|
-
:leftovers_definition
|
21
|
+
def path
|
22
|
+
node.path
|
33
23
|
end
|
34
|
-
# :nocov:
|
35
24
|
end
|
36
25
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
class DefinitionToAdd
|
5
|
+
attr_reader :node, :name, :location
|
6
|
+
|
7
|
+
def initialize(node, name: node.name, location: node.loc.name)
|
8
|
+
@node = node
|
9
|
+
@name = name
|
10
|
+
@location = location
|
11
|
+
end
|
12
|
+
|
13
|
+
def privacy=(value)
|
14
|
+
@node.privacy = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def keep?(file_collector)
|
18
|
+
@keep ||= file_collector.keep_line?(location.line) || ::Leftovers.config.keep === node
|
19
|
+
end
|
20
|
+
|
21
|
+
def test?(file_collector)
|
22
|
+
file_collector.test_line?(location.line) || ::Leftovers.config.test_only === node
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_definition(file_collector)
|
26
|
+
return if keep?(file_collector)
|
27
|
+
|
28
|
+
Leftovers::Definition.new(name, location: location, test: test?(file_collector))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -3,10 +3,6 @@
|
|
3
3
|
module Leftovers
|
4
4
|
module DynamicProcessors
|
5
5
|
class Call
|
6
|
-
# :nocov:
|
7
|
-
using ::Leftovers::Backports::SetCaseEq if defined?(::Leftovers::Backports::SetCaseEq)
|
8
|
-
# :nocov:
|
9
|
-
|
10
6
|
def initialize(matcher, processor)
|
11
7
|
@matcher = matcher
|
12
8
|
@processor = processor
|
@@ -15,10 +11,11 @@ module Leftovers
|
|
15
11
|
def process(node, file)
|
16
12
|
return unless @matcher === node
|
17
13
|
|
18
|
-
|
19
|
-
return unless call
|
14
|
+
calls = @processor.process(nil, node, node)
|
20
15
|
|
21
|
-
|
16
|
+
::Leftovers.each_or_self(calls) do |call|
|
17
|
+
file.calls << call
|
18
|
+
end
|
22
19
|
end
|
23
20
|
end
|
24
21
|
end
|
@@ -3,28 +3,31 @@
|
|
3
3
|
module Leftovers
|
4
4
|
module DynamicProcessors
|
5
5
|
class CallDefinition
|
6
|
-
# :nocov:
|
7
|
-
using ::Leftovers::Backports::SetCaseEq if defined?(::Leftovers::Backports::SetCaseEq)
|
8
|
-
# :nocov:
|
9
|
-
|
10
6
|
def initialize(matcher, call_processor, definition_processor)
|
11
7
|
@matcher = matcher
|
12
8
|
@call_processor = call_processor
|
13
9
|
@definition_processor = definition_processor
|
14
10
|
end
|
15
11
|
|
16
|
-
def process(node, file)
|
12
|
+
def process(node, file) # rubocop:disable Metrics/MethodLength
|
17
13
|
return unless @matcher === node
|
18
14
|
|
19
|
-
|
20
|
-
(file.calls << call) if call
|
15
|
+
calls = @call_processor.process(nil, node, node)
|
21
16
|
|
22
|
-
|
17
|
+
::Leftovers.each_or_self(calls) do |call|
|
18
|
+
file.calls << call
|
19
|
+
end
|
23
20
|
|
24
|
-
|
25
|
-
return unless definition
|
21
|
+
return if node.keep_line?
|
26
22
|
|
27
|
-
|
23
|
+
definitions = @definition_processor.process(nil, node, node)
|
24
|
+
::Leftovers.each_or_self(definitions) do |definition|
|
25
|
+
if definition.is_a?(DefinitionNodeSet)
|
26
|
+
file.add_definition_set(definition)
|
27
|
+
else
|
28
|
+
file.add_definition(definition, loc: definition.loc)
|
29
|
+
end
|
30
|
+
end
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
@@ -3,10 +3,6 @@
|
|
3
3
|
module Leftovers
|
4
4
|
module DynamicProcessors
|
5
5
|
class Definition
|
6
|
-
# :nocov:
|
7
|
-
using ::Leftovers::Backports::SetCaseEq if defined?(::Leftovers::Backports::SetCaseEq)
|
8
|
-
# :nocov:
|
9
|
-
|
10
6
|
def initialize(matcher, processor)
|
11
7
|
@matcher = matcher
|
12
8
|
@processor = processor
|
@@ -16,10 +12,15 @@ module Leftovers
|
|
16
12
|
return if node.keep_line?
|
17
13
|
return unless @matcher === node
|
18
14
|
|
19
|
-
|
20
|
-
return unless definition
|
15
|
+
definitions = @processor.process(nil, node, node)
|
21
16
|
|
22
|
-
|
17
|
+
::Leftovers.each_or_self(definitions) do |definition|
|
18
|
+
if definition.is_a?(DefinitionNodeSet)
|
19
|
+
file.add_definition_set(definition)
|
20
|
+
else
|
21
|
+
file.add_definition(definition, loc: definition.loc)
|
22
|
+
end
|
23
|
+
end
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module DynamicProcessors
|
5
|
+
class SetDefaultPrivacy
|
6
|
+
def initialize(matcher, to)
|
7
|
+
@matcher = matcher
|
8
|
+
@to = to
|
9
|
+
end
|
10
|
+
|
11
|
+
def process(node, file)
|
12
|
+
return unless @matcher === node
|
13
|
+
|
14
|
+
file.default_method_privacy = @to
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
module DynamicProcessors
|
5
|
+
class SetPrivacy
|
6
|
+
def initialize(matcher, processor, to)
|
7
|
+
@matcher = matcher
|
8
|
+
@processor = processor
|
9
|
+
@to = to
|
10
|
+
end
|
11
|
+
|
12
|
+
def process(node, file)
|
13
|
+
return unless @matcher === node
|
14
|
+
|
15
|
+
set_privacy = @processor.process(nil, node, node)
|
16
|
+
|
17
|
+
::Leftovers.each_or_self(set_privacy) do |name|
|
18
|
+
file.set_privacy(name, @to)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -7,5 +7,7 @@ module Leftovers
|
|
7
7
|
autoload(:Definition, "#{__dir__}/dynamic_processors/definition")
|
8
8
|
autoload(:Each, "#{__dir__}/dynamic_processors/each")
|
9
9
|
autoload(:Null, "#{__dir__}/dynamic_processors/null")
|
10
|
+
autoload(:SetDefaultPrivacy, "#{__dir__}/dynamic_processors/set_default_privacy")
|
11
|
+
autoload(:SetPrivacy, "#{__dir__}/dynamic_processors/set_privacy")
|
10
12
|
end
|
11
13
|
end
|