leftovers 0.3.0 → 0.4.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 +23 -0
- data/README.md +28 -45
- data/docs/Configuration.md +598 -0
- data/exe/leftovers +1 -1
- data/leftovers.gemspec +9 -6
- data/lib/config/attr_encrypted.yml +3 -4
- data/lib/config/audited.yml +9 -4
- data/lib/config/datagrid.yml +1 -1
- data/lib/config/flipper.yml +1 -3
- data/lib/config/graphql.yml +15 -13
- data/lib/config/okcomputer.yml +1 -3
- data/lib/config/parser.yml +89 -91
- data/lib/config/rails.yml +125 -107
- data/lib/config/redcarpet.yml +35 -38
- data/lib/config/rollbar.yml +1 -3
- data/lib/config/rspec.yml +18 -10
- data/lib/config/ruby.yml +40 -50
- data/lib/config/selenium-webdriver.yml +19 -21
- data/lib/config/sidekiq.yml +4 -8
- data/lib/config/will_paginate.yml +12 -14
- data/lib/leftovers.rb +38 -26
- data/lib/leftovers/ast.rb +8 -0
- data/lib/leftovers/ast/builder.rb +4 -4
- data/lib/leftovers/ast/node.rb +50 -77
- data/lib/leftovers/backports.rb +27 -23
- data/lib/leftovers/cli.rb +0 -3
- data/lib/leftovers/collector.rb +4 -8
- data/lib/leftovers/config.rb +19 -25
- data/lib/leftovers/config_validator.rb +60 -0
- data/lib/leftovers/config_validator/error_processor.rb +196 -0
- data/lib/leftovers/config_validator/schema_hash.rb +495 -0
- data/lib/leftovers/definition.rb +11 -36
- data/lib/leftovers/definition_set.rb +7 -17
- data/lib/leftovers/dynamic_processors.rb +11 -0
- data/lib/leftovers/dynamic_processors/call.rb +25 -0
- data/lib/leftovers/dynamic_processors/call_definition.rb +31 -0
- data/lib/leftovers/dynamic_processors/definition.rb +26 -0
- data/lib/leftovers/dynamic_processors/each.rb +19 -0
- data/lib/leftovers/dynamic_processors/null.rb +9 -0
- data/lib/leftovers/erb.rb +2 -2
- data/lib/leftovers/file.rb +3 -5
- data/lib/leftovers/file_collector.rb +65 -49
- data/lib/leftovers/file_list.rb +0 -1
- data/lib/leftovers/haml.rb +1 -1
- data/lib/leftovers/matcher_builders.rb +24 -0
- data/lib/leftovers/matcher_builders/and.rb +19 -0
- data/lib/leftovers/matcher_builders/and_not.rb +14 -0
- data/lib/leftovers/matcher_builders/argument_node_value.rb +21 -0
- data/lib/leftovers/matcher_builders/name.rb +29 -0
- data/lib/leftovers/matcher_builders/node.rb +40 -0
- data/lib/leftovers/matcher_builders/node_has_argument.rb +71 -0
- data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +22 -0
- data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +24 -0
- data/lib/leftovers/matcher_builders/node_name.rb +15 -0
- data/lib/leftovers/matcher_builders/node_pair_name.rb +18 -0
- data/lib/leftovers/matcher_builders/node_pair_value.rb +16 -0
- data/lib/leftovers/matcher_builders/node_path.rb +14 -0
- data/lib/leftovers/matcher_builders/node_type.rb +28 -0
- data/lib/leftovers/matcher_builders/or.rb +73 -0
- data/lib/leftovers/matcher_builders/path.rb +15 -0
- data/lib/leftovers/matcher_builders/string.rb +11 -0
- data/lib/leftovers/matcher_builders/string_pattern.rb +19 -0
- data/lib/leftovers/matcher_builders/unless.rb +13 -0
- data/lib/leftovers/matchers.rb +26 -0
- data/lib/leftovers/matchers/all.rb +25 -0
- data/lib/leftovers/matchers/and.rb +24 -0
- data/lib/leftovers/matchers/any.rb +27 -0
- data/lib/leftovers/matchers/node_has_any_keyword_argument.rb +28 -0
- data/lib/leftovers/matchers/node_has_any_positional_argument_with_value.rb +25 -0
- data/lib/leftovers/matchers/node_has_positional_argument.rb +23 -0
- data/lib/leftovers/matchers/node_has_positional_argument_with_value.rb +25 -0
- data/lib/leftovers/matchers/node_name.rb +23 -0
- data/lib/leftovers/matchers/node_pair_value.rb +23 -0
- data/lib/leftovers/matchers/node_path.rb +23 -0
- data/lib/leftovers/matchers/node_scalar_value.rb +25 -0
- data/lib/leftovers/matchers/node_type.rb +23 -0
- data/lib/leftovers/matchers/not.rb +23 -0
- data/lib/leftovers/matchers/or.rb +26 -0
- data/lib/leftovers/merged_config.rb +13 -8
- data/lib/leftovers/parser.rb +1 -4
- data/lib/leftovers/processor_builders.rb +22 -0
- data/lib/leftovers/processor_builders/action.rb +63 -0
- data/lib/leftovers/processor_builders/add_prefix.rb +20 -0
- data/lib/leftovers/processor_builders/add_suffix.rb +20 -0
- data/lib/leftovers/processor_builders/argument.rb +25 -0
- data/lib/leftovers/processor_builders/dynamic.rb +27 -0
- data/lib/leftovers/processor_builders/each.rb +36 -0
- data/lib/leftovers/processor_builders/each_action.rb +51 -0
- data/lib/leftovers/processor_builders/each_dynamic.rb +54 -0
- data/lib/leftovers/processor_builders/each_for_definition_set.rb +36 -0
- data/lib/leftovers/processor_builders/itself.rb +13 -0
- data/lib/leftovers/processor_builders/keyword.rb +24 -0
- data/lib/leftovers/processor_builders/keyword_argument.rb +14 -0
- data/lib/leftovers/processor_builders/transform.rb +55 -0
- data/lib/leftovers/processor_builders/transform_chain.rb +24 -0
- data/lib/leftovers/processor_builders/transform_set.rb +47 -0
- data/lib/leftovers/processor_builders/value.rb +13 -0
- data/lib/leftovers/rake_task.rb +1 -1
- data/lib/leftovers/reporter.rb +1 -1
- data/lib/leftovers/value_processors.rb +40 -0
- data/lib/leftovers/value_processors/add_dynamic_prefix.rb +31 -0
- data/lib/leftovers/value_processors/add_dynamic_suffix.rb +31 -0
- data/lib/leftovers/value_processors/add_prefix.rb +20 -0
- data/lib/leftovers/value_processors/add_suffix.rb +20 -0
- data/lib/leftovers/value_processors/camelize.rb +24 -0
- data/lib/leftovers/value_processors/capitalize.rb +19 -0
- data/lib/leftovers/value_processors/deconstantize.rb +24 -0
- data/lib/leftovers/value_processors/delete_after.rb +22 -0
- data/lib/leftovers/value_processors/delete_before.rb +22 -0
- data/lib/leftovers/value_processors/delete_prefix.rb +26 -0
- data/lib/leftovers/value_processors/delete_suffix.rb +26 -0
- data/lib/leftovers/value_processors/demodulize.rb +24 -0
- data/lib/leftovers/value_processors/downcase.rb +19 -0
- data/lib/leftovers/value_processors/each.rb +21 -0
- data/lib/leftovers/value_processors/each_for_definition_set.rb +33 -0
- data/lib/leftovers/value_processors/each_keyword.rb +27 -0
- data/lib/leftovers/value_processors/each_keyword_argument.rb +27 -0
- data/lib/leftovers/value_processors/each_positional_argument.rb +24 -0
- data/lib/leftovers/value_processors/itself.rb +17 -0
- data/lib/leftovers/value_processors/keyword.rb +36 -0
- data/lib/leftovers/value_processors/keyword_argument.rb +36 -0
- data/lib/leftovers/value_processors/parameterize.rb +24 -0
- data/lib/leftovers/value_processors/placeholder.rb +18 -0
- data/lib/leftovers/value_processors/pluralize.rb +24 -0
- data/lib/leftovers/value_processors/positional_argument.rb +26 -0
- data/lib/leftovers/value_processors/replace_value.rb +18 -0
- data/lib/leftovers/value_processors/return_definition.rb +24 -0
- data/lib/leftovers/value_processors/return_string.rb +14 -0
- data/lib/leftovers/value_processors/singularize.rb +24 -0
- data/lib/leftovers/value_processors/split.rb +22 -0
- data/lib/leftovers/value_processors/swapcase.rb +19 -0
- data/lib/leftovers/value_processors/titleize.rb +24 -0
- data/lib/leftovers/value_processors/underscore.rb +24 -0
- data/lib/leftovers/value_processors/upcase.rb +19 -0
- data/lib/leftovers/version.rb +1 -1
- metadata +143 -24
- data/lib/leftovers/argument_rule.rb +0 -229
- data/lib/leftovers/core_ext.rb +0 -15
- data/lib/leftovers/hash_rule.rb +0 -42
- data/lib/leftovers/name_rule.rb +0 -98
- data/lib/leftovers/rule.rb +0 -82
- data/lib/leftovers/transform_rule.rb +0 -169
- data/lib/leftovers/value_rule.rb +0 -57
@@ -1,169 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Leftovers
|
4
|
-
class TransformRule # rubocop:disable Metrics/ClassLength
|
5
|
-
# :nocov:
|
6
|
-
using ::Leftovers::StringDeletePrefixSuffix if defined?(::Leftovers::StringDeletePrefixSuffix)
|
7
|
-
# :nocov:
|
8
|
-
|
9
|
-
RUBY_STRING_METHODS = %i{
|
10
|
-
downcase
|
11
|
-
upcase
|
12
|
-
capitalize
|
13
|
-
swapcase
|
14
|
-
}.freeze
|
15
|
-
|
16
|
-
ACTIVESUPPORT_STRING_METHODS = %i{
|
17
|
-
pluralize
|
18
|
-
singularize
|
19
|
-
camelize
|
20
|
-
camelcase
|
21
|
-
underscore
|
22
|
-
titleize
|
23
|
-
titlecase
|
24
|
-
demodulize
|
25
|
-
deconstantize
|
26
|
-
parameterize
|
27
|
-
}.freeze
|
28
|
-
|
29
|
-
CUSTOM_TRANSFORMS = %i{
|
30
|
-
original
|
31
|
-
delete_before
|
32
|
-
delete_after
|
33
|
-
add_prefix
|
34
|
-
add_suffix
|
35
|
-
delete_prefix
|
36
|
-
delete_suffix
|
37
|
-
replace_with
|
38
|
-
}.freeze
|
39
|
-
|
40
|
-
VALID_TRANSFORMS = CUSTOM_TRANSFORMS + RUBY_STRING_METHODS + ACTIVESUPPORT_STRING_METHODS
|
41
|
-
def initialize(transforms)
|
42
|
-
@transforms = prepare_transforms(transforms)
|
43
|
-
|
44
|
-
freeze
|
45
|
-
end
|
46
|
-
|
47
|
-
def transform(original_string, method_node)
|
48
|
-
string = original_string
|
49
|
-
@transforms.each { |proc| string = proc.call(string, method_node) }
|
50
|
-
|
51
|
-
string.to_sym
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def prepare_transforms(transforms) # rubocop:disable Metrics/MethodLength
|
57
|
-
transforms.map do |key, value|
|
58
|
-
unless VALID_TRANSFORMS.include?(key)
|
59
|
-
raise Leftovers::ConfigError, <<~MESSAGE
|
60
|
-
invalid transform key: (#{key}: #{value})
|
61
|
-
Valid transform keys are #{VALID_TRANSFORMS.join(', ')}
|
62
|
-
MESSAGE
|
63
|
-
end
|
64
|
-
|
65
|
-
key, value = prepare_hash_value(key, value) if value.is_a?(Hash)
|
66
|
-
|
67
|
-
instance_variable_set(:"@#{key}", value.freeze)
|
68
|
-
method(key)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
HASH_VALUE_TRANSFORMS = %i{add_prefix add_suffix}.freeze
|
73
|
-
HASH_VALUE_KEYS = %i{from_argument joiner}.freeze
|
74
|
-
def prepare_hash_value(method, hash) # rubocop:disable Metrics/MethodLength
|
75
|
-
raise Leftovers::ConfigError, <<~MESSAGE unless HASH_VALUE_TRANSFORMS.include?(method)
|
76
|
-
invalid transform value (#{method}: #{hash.inspect}).
|
77
|
-
Hash values are only valid for #{HASH_VALUE_TRANSFORMS.join(', ')}
|
78
|
-
MESSAGE
|
79
|
-
|
80
|
-
hash = hash.map do |k, v|
|
81
|
-
raise Leftovers::ConfigError, <<~MESSAGE unless HASH_VALUE_KEYS.include?(k)
|
82
|
-
invalid transform value argument (#{method}: { #{k}: #{v} }).
|
83
|
-
Valid keys are #{HASH_VALUE_KEYS.join(', ')}
|
84
|
-
MESSAGE
|
85
|
-
|
86
|
-
[k, (v.respond_to?(:to_sym) ? v.to_sym : v)]
|
87
|
-
end.to_h
|
88
|
-
|
89
|
-
["#{method}_dynamic", hash]
|
90
|
-
end
|
91
|
-
|
92
|
-
RUBY_STRING_METHODS.each do |method|
|
93
|
-
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
94
|
-
def #{method}(string, _method_node)
|
95
|
-
string.#{method}
|
96
|
-
end
|
97
|
-
RUBY
|
98
|
-
end
|
99
|
-
|
100
|
-
# leftovers:call activesupport_available?
|
101
|
-
ACTIVESUPPORT_STRING_METHODS.each do |method|
|
102
|
-
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
103
|
-
def #{method}(string, _method_node)
|
104
|
-
return string unless activesupport_available?(:#{method})
|
105
|
-
|
106
|
-
string.#{method}
|
107
|
-
end
|
108
|
-
RUBY
|
109
|
-
end
|
110
|
-
|
111
|
-
def original(string, _method_node)
|
112
|
-
string
|
113
|
-
end
|
114
|
-
|
115
|
-
def delete_prefix(string, _method_node)
|
116
|
-
string.delete_prefix(@delete_prefix)
|
117
|
-
end
|
118
|
-
|
119
|
-
def delete_suffix(string, _method_node)
|
120
|
-
string.delete_suffix(@delete_suffix)
|
121
|
-
end
|
122
|
-
|
123
|
-
def delete_before(string, _method_node)
|
124
|
-
string.split(@delete_before, 2)[1] || string
|
125
|
-
end
|
126
|
-
|
127
|
-
def delete_after(string, _method_node)
|
128
|
-
string.split(@delete_after, 2).first || string
|
129
|
-
end
|
130
|
-
|
131
|
-
def replace_with(_string, _method_node)
|
132
|
-
@replace_with
|
133
|
-
end
|
134
|
-
|
135
|
-
def add_prefix(string, _method_node)
|
136
|
-
"#{@add_prefix}#{string}"
|
137
|
-
end
|
138
|
-
|
139
|
-
def add_suffix(string, _method_node)
|
140
|
-
"#{string}#{@add_suffix}"
|
141
|
-
end
|
142
|
-
|
143
|
-
def add_prefix_dynamic(string, method_node)
|
144
|
-
prefix = dynamic_value(@add_prefix_dynamic, method_node)
|
145
|
-
"#{prefix}#{@add_prefix_dynamic[:joiner] if prefix}#{string}"
|
146
|
-
end
|
147
|
-
|
148
|
-
def add_suffix_dynamic(string, method_node)
|
149
|
-
suffix = dynamic_value(@add_suffix_dynamic, method_node)
|
150
|
-
"#{string}#{@add_suffix_dynamic[:joiner] if suffix}#{suffix}"
|
151
|
-
end
|
152
|
-
|
153
|
-
def dynamic_value(value, method_node)
|
154
|
-
method_node[value[:from_argument]] if value[:from_argument]
|
155
|
-
end
|
156
|
-
|
157
|
-
def activesupport_available?(method) # rubocop:disable Metrics/MethodLength
|
158
|
-
message = <<~MESSAGE
|
159
|
-
Tried transforming a string using an activesupport method (#{method}), but the activesupport gem was not available
|
160
|
-
`gem install activesupport`
|
161
|
-
MESSAGE
|
162
|
-
Leftovers.try_require('active_support/core_ext/string', message: message)
|
163
|
-
Leftovers.try_require('active_support/inflections', message: message)
|
164
|
-
Leftovers.try_require(::File.join(Leftovers.pwd, 'config', 'initializers', 'inflections.rb'))
|
165
|
-
|
166
|
-
defined?(ActiveSupport)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
data/lib/leftovers/value_rule.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Leftovers
|
4
|
-
class ValueRule
|
5
|
-
def initialize(values) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
|
6
|
-
literal_values = Set.new
|
7
|
-
value_types = Set.new
|
8
|
-
|
9
|
-
Leftovers.each_or_self(values) do |value|
|
10
|
-
case value
|
11
|
-
when Hash
|
12
|
-
raise Leftovers::ConfigError, "invalid value #{value.inspect}" unless value[:type]
|
13
|
-
|
14
|
-
value_types.merge(
|
15
|
-
Array(value[:type]).map do |v|
|
16
|
-
case v
|
17
|
-
when 'String' then :str
|
18
|
-
when 'Symbol' then :sym
|
19
|
-
when 'Integer' then :int
|
20
|
-
else v.to_s.downcase.to_sym
|
21
|
-
end
|
22
|
-
end
|
23
|
-
)
|
24
|
-
else
|
25
|
-
literal_values << value
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
if literal_values.length <= 1
|
30
|
-
@literal_value = literal_values.first
|
31
|
-
@literal_values = nil
|
32
|
-
else
|
33
|
-
@literal_value = nil
|
34
|
-
@literal_values = literal_values
|
35
|
-
end
|
36
|
-
|
37
|
-
if value_types.length <= 1
|
38
|
-
@value_type = value_types.first
|
39
|
-
@value_types = nil
|
40
|
-
else
|
41
|
-
@value_type = nil
|
42
|
-
@value_types = value_types
|
43
|
-
end
|
44
|
-
|
45
|
-
freeze
|
46
|
-
end
|
47
|
-
|
48
|
-
def match?(value_node) # rubocop:disable Metrics/CyclomaticComplexity
|
49
|
-
return true if @value_type&.== value_node.type
|
50
|
-
return true if @value_types&.include?(value_node.type)
|
51
|
-
return false unless (@literal_value || @literal_values) && value_node.scalar?
|
52
|
-
return true if @literal_value&.== value_node.to_scalar_value
|
53
|
-
|
54
|
-
@literal_values&.include?(value_node.to_scalar_value)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|