leftovers 0.7.0 → 0.8.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 +13 -0
- data/README.md +1 -0
- data/docs/Configuration.md +20 -57
- data/docs/Custom-Precompilers.md +38 -0
- data/lib/config/actionpack.yml +5 -3
- data/lib/config/haml.yml +4 -2
- data/lib/config/ruby.yml +4 -15
- data/lib/config/slim.yml +4 -2
- data/lib/leftovers/cli.rb +5 -0
- data/lib/leftovers/collector.rb +2 -1
- data/lib/leftovers/config.rb +2 -18
- data/lib/leftovers/config_loader/argument_position_schema.rb +2 -2
- data/lib/leftovers/config_loader/attribute.rb +36 -10
- data/lib/leftovers/config_loader/built_in_precompiler_schema.rb +13 -0
- data/lib/leftovers/config_loader/document_schema.rb +32 -5
- data/lib/leftovers/config_loader/has_argument_schema.rb +2 -2
- data/lib/leftovers/config_loader/has_value_schema.rb +2 -2
- data/lib/leftovers/config_loader/inherit_schema_attributes.rb +22 -0
- data/lib/leftovers/config_loader/keep_test_only_schema.rb +2 -2
- data/lib/leftovers/config_loader/object_schema.rb +33 -105
- data/lib/leftovers/config_loader/precompile_schema.rb +12 -0
- data/lib/leftovers/config_loader/precompiler_schema.rb +11 -0
- data/lib/leftovers/config_loader/privacy_processor_schema.rb +0 -2
- data/lib/leftovers/config_loader/require_schema.rb +3 -3
- data/lib/leftovers/config_loader/schema.rb +2 -0
- data/lib/leftovers/config_loader/string_pattern_schema.rb +2 -2
- data/lib/leftovers/config_loader/string_value_processor_schema.rb +2 -2
- data/lib/leftovers/config_loader/transform_schema.rb +4 -6
- data/lib/leftovers/config_loader/value_matcher_schema.rb +2 -2
- data/lib/leftovers/config_loader/value_or_array_schema.rb +5 -3
- data/lib/leftovers/config_loader/value_or_object_schema.rb +40 -0
- data/lib/leftovers/config_loader/value_processor_schema.rb +2 -2
- data/lib/leftovers/config_loader.rb +5 -1
- data/lib/leftovers/file.rb +7 -53
- data/lib/leftovers/file_collector/comments_processor.rb +57 -0
- data/lib/leftovers/file_collector/node_processor.rb +131 -0
- data/lib/leftovers/file_collector.rb +42 -203
- data/lib/leftovers/matcher_builders/and_not.rb +7 -5
- data/lib/leftovers/matcher_builders/name.rb +18 -17
- data/lib/leftovers/matcher_builders/node.rb +48 -34
- data/lib/leftovers/matcher_builders/node_has_argument.rb +48 -52
- data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +13 -10
- data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +29 -15
- data/lib/leftovers/matcher_builders/node_type.rb +1 -1
- data/lib/leftovers/matcher_builders/node_value.rb +27 -22
- data/lib/leftovers/matcher_builders/or.rb +50 -50
- data/lib/leftovers/matcher_builders/string_pattern.rb +1 -1
- data/lib/leftovers/merged_config.rb +3 -23
- data/lib/leftovers/precompilers/erb.rb +22 -0
- data/lib/leftovers/precompilers/haml.rb +15 -0
- data/lib/leftovers/precompilers/json.rb +27 -0
- data/lib/leftovers/precompilers/precompiler.rb +28 -0
- data/lib/leftovers/precompilers/slim.rb +15 -0
- data/lib/leftovers/precompilers/yaml.rb +75 -0
- data/lib/leftovers/precompilers.rb +50 -0
- data/lib/leftovers/processor_builders/action.rb +48 -39
- 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/argument.rb +8 -11
- data/lib/leftovers/processor_builders/dynamic.rb +5 -5
- data/lib/leftovers/processor_builders/each.rb +2 -2
- data/lib/leftovers/processor_builders/each_action.rb +33 -33
- data/lib/leftovers/processor_builders/each_dynamic.rb +4 -8
- data/lib/leftovers/processor_builders/each_for_definition_set.rb +25 -21
- data/lib/leftovers/processor_builders/keyword.rb +3 -4
- data/lib/leftovers/processor_builders/transform.rb +2 -2
- data/lib/leftovers/processor_builders/transform_chain.rb +16 -8
- data/lib/leftovers/processor_builders/transform_set.rb +32 -28
- data/lib/leftovers/rake_task.rb +1 -1
- data/lib/leftovers/value_processors/add_dynamic_prefix.rb +3 -10
- data/lib/leftovers/value_processors/add_dynamic_suffix.rb +3 -10
- data/lib/leftovers/value_processors/each.rb +1 -1
- data/lib/leftovers/value_processors/each_for_definition_set.rb +2 -5
- data/lib/leftovers/value_processors/each_keyword.rb +1 -1
- data/lib/leftovers/value_processors/each_keyword_argument.rb +1 -1
- data/lib/leftovers/value_processors/each_positional_argument.rb +2 -1
- data/lib/leftovers/value_processors/keyword.rb +3 -7
- data/lib/leftovers/value_processors/keyword_argument.rb +2 -6
- data/lib/leftovers/value_processors/split.rb +2 -2
- data/lib/leftovers/version.rb +1 -1
- data/lib/leftovers.rb +41 -6
- metadata +17 -7
- data/lib/leftovers/erb.rb +0 -20
- data/lib/leftovers/haml.rb +0 -21
- data/lib/leftovers/json.rb +0 -28
- data/lib/leftovers/slim.rb +0 -21
- data/lib/leftovers/yaml.rb +0 -73
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2e0c74dad85b7b571608a7207f006fe14d5748e1a155470185112b80a7b80a3
|
4
|
+
data.tar.gz: 68f3d83b310f640e127b961e6ac2ece795a7b9e2a6de961a1b42498916e092d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c57c64254cc2092e38b8decfd7bde0a021d66a7c3f563dc3e1f5a68b91c4bfc7b16a8490e5437b3da942071d41d2c35c247e1e51739064e14fdfcc6653b192b3
|
7
|
+
data.tar.gz: b129119436c793987c89b032d5936b10ca935c7fc5398e7a2843665bbfec28ccaacd0a0090c8cd37c5172b6892f4291455aef40df6bae67727d25ac47fd871a3
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
# v0.8.0
|
2
|
+
- Allow custom precompilers
|
3
|
+
```yml
|
4
|
+
require: './path/to/my_precompiler'
|
5
|
+
precompile:
|
6
|
+
- paths: '*.myCustomFormat'
|
7
|
+
format: { custom: 'MyPrecompiler' }
|
8
|
+
```
|
9
|
+
the built in precompilers have moved into this system too, with `format: haml` etc. `haml_paths` etc are now deprecated
|
10
|
+
- a lot of refactoring, which revealed some edge cases i was handling
|
11
|
+
- collect a call to :my_method= with receiver&.my_method ||= (and += etc)
|
12
|
+
- if `add_prefix:` or `add_suffix:` points to another argument for a name that we can't use because it's a variable, it now just don't return the value, rather than returning the value but without the affix
|
13
|
+
|
1
14
|
# v0.7.0
|
2
15
|
- Rewrite the config parser/validation
|
3
16
|
- to provide clearer error messages with line numbers and everything
|
data/README.md
CHANGED
@@ -166,6 +166,7 @@ Its presence is optional and all of these settings are optional.
|
|
166
166
|
- [`exclude_paths:`](https://github.com/robotdana/leftovers/tree/main/docs/Configuration.md#exclude_paths)
|
167
167
|
- [`test_paths:`](https://github.com/robotdana/leftovers/tree/main/docs/Configuration.md#test_paths)
|
168
168
|
- [`requires:`](https://github.com/robotdana/leftovers/tree/main/docs/Configuration.md#requires)
|
169
|
+
- [`precompile:`](https://github.com/robotdana/leftovers/tree/main/docs/Configuration.md#precompile)
|
169
170
|
- [`gems:`](https://github.com/robotdana/leftovers/tree/main/docs/Configuration.md#gems)
|
170
171
|
- [`keep:`](https://github.com/robotdana/leftovers/tree/main/docs/Configuration.md#keep)
|
171
172
|
- [`test_only:`](https://github.com/robotdana/leftovers/tree/main/docs/Configuration.md#test_only)
|
data/docs/Configuration.md
CHANGED
@@ -6,11 +6,7 @@ Its presence is optional and all of these settings are optional.
|
|
6
6
|
- [`include_paths:`](#include_paths)
|
7
7
|
- [`exclude_paths:`](#exclude_paths)
|
8
8
|
- [`test_paths:`](#test_paths)
|
9
|
-
- [`
|
10
|
-
- [`slim_paths:`](#slim_paths)
|
11
|
-
- [`erb_paths:`](#erb_paths)
|
12
|
-
- [`yaml_paths:`](#yaml_paths)
|
13
|
-
- [`json_paths:`](#json_paths)
|
9
|
+
- [`precompile:`](#precompile)
|
14
10
|
- [`requires:`](#requires)
|
15
11
|
- [`gems:`](#gems)
|
16
12
|
- [`keep:`](#keep)
|
@@ -88,55 +84,32 @@ test_paths:
|
|
88
84
|
|
89
85
|
Arrays are not necessary for single values
|
90
86
|
|
91
|
-
## `
|
92
|
-
|
93
|
-
list filenames/paths of test directories that are in the haml format
|
94
|
-
Defined using the [.gitignore pattern format](https://git-scm.com/docs/gitignore#_pattern_format)
|
87
|
+
## `precompile:`
|
95
88
|
|
96
89
|
```yml
|
97
|
-
|
98
|
-
|
90
|
+
require: './path/my_project/my_precompiler'
|
91
|
+
precompile:
|
92
|
+
- paths: '*.myCustomFormat'
|
93
|
+
format: { custom: 'MyProject::MyPrecompiler' }
|
94
|
+
- paths: '*.my.json'
|
95
|
+
format: json
|
99
96
|
```
|
100
97
|
|
101
|
-
|
98
|
+
Define any precompilers and the paths they affect.
|
102
99
|
|
103
|
-
|
104
|
-
|
105
|
-
list filenames/paths of test directories that are in the slim format
|
106
|
-
Defined using the [.gitignore pattern format](https://git-scm.com/docs/gitignore#_pattern_format)
|
107
|
-
|
108
|
-
```yml
|
109
|
-
slim_paths:
|
110
|
-
- '*.slim'
|
111
|
-
```
|
112
|
-
|
113
|
-
Arrays are not necessary for single values. `*.slim` is recognized by default
|
114
|
-
|
115
|
-
## `erb_paths:`
|
116
|
-
|
117
|
-
list filenames/paths of test directories that are in the erb format
|
118
|
-
Defined using the [.gitignore pattern format](https://git-scm.com/docs/gitignore#_pattern_format)
|
119
|
-
|
120
|
-
```yml
|
121
|
-
erb_paths:
|
122
|
-
- '*.erb'
|
123
|
-
```
|
100
|
+
`paths:` are defined using the [.gitignore pattern format](https://git-scm.com/docs/gitignore#_pattern_format)
|
124
101
|
|
125
|
-
|
102
|
+
`format:` must be one of the predefined precompilers (erb, haml, [json](#format-json), slim, [yaml](#format-yaml)), or `custom:` with the name of a [custom precompiler]('../Custom-Precompilers.md) module.
|
103
|
+
(use [`require:`](#requires) to have leftovers load its file)
|
126
104
|
|
127
|
-
|
105
|
+
See [Custom precompilers]('../Custom-Precompilers.md) for more details on the custom precompiler class
|
128
106
|
|
129
|
-
|
130
|
-
Defined using the [.gitignore pattern format](https://git-scm.com/docs/gitignore#_pattern_format)
|
107
|
+
Arrays are not necessary for single values.
|
131
108
|
|
132
|
-
|
133
|
-
include:
|
134
|
-
- 'config/*.yml'
|
135
|
-
yaml_paths:
|
136
|
-
- '*.yml'
|
137
|
-
```
|
109
|
+
### `format: yaml`
|
138
110
|
|
139
|
-
|
111
|
+
The yaml precompiler considers yaml tags like `!ruby/class 'MyClass'` to be a call to `MyClass`.
|
112
|
+
and renders the structure of the yaml document as arguments for the [`document:true`](#document-true) rule.
|
140
113
|
|
141
114
|
so you could, e.g. read the class name out of a yaml document like:
|
142
115
|
|
@@ -159,21 +132,11 @@ dynamic:
|
|
159
132
|
|
160
133
|
[`nested:`](#nested) may be useful for more complex yaml structures
|
161
134
|
|
162
|
-
|
135
|
+
### `format: json`
|
163
136
|
|
164
|
-
|
165
|
-
Defined using the [.gitignore pattern format](https://git-scm.com/docs/gitignore#_pattern_format)
|
137
|
+
The json precompiler renders the structure of the json document as arguments for the [`document:true`](#document-true) rule.
|
166
138
|
|
167
|
-
|
168
|
-
include:
|
169
|
-
- 'config/*.json'
|
170
|
-
json_paths:
|
171
|
-
- '*.json'
|
172
|
-
```
|
173
|
-
|
174
|
-
These documents render the structure of the yaml as arguments for the [`document:true`](#document-true) rule.
|
175
|
-
|
176
|
-
so you could, e.g. read the class name out of a yaml document like:
|
139
|
+
so you could, e.g. read the class name out of a json document like:
|
177
140
|
|
178
141
|
```json
|
179
142
|
{ "class_name": "MyClass" }
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Custom Precompilers
|
2
|
+
|
3
|
+
In addition to the built in precompilers, it's possible to add a custom precompiler
|
4
|
+
|
5
|
+
It must be a class or module with a singleton method `precompile`. take a string of whatever code it likes, and return a string of valid ruby.
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require 'not_ruby' # require the gem that does the actual transformation
|
9
|
+
|
10
|
+
module MyNotRubyPrecompiler
|
11
|
+
def self.precompile(not_ruby_content)
|
12
|
+
# not_ruby_content is a string of (hopefully) valid precompilable code
|
13
|
+
NotRuby::Parser.parse(not_ruby_content).to_ruby # output a string of valid ruby
|
14
|
+
end
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
See the [build in precompilers](https://github.com/robotdana/leftovers/tree/main/lib/precompilers) for other examples.
|
19
|
+
|
20
|
+
To configure the precompiler to be used by leftovers, add something similar to this to the `.leftovers.yml` file
|
21
|
+
|
22
|
+
```yml
|
23
|
+
include_paths:
|
24
|
+
- 'lib/**/*.not_rb'
|
25
|
+
require: './path/to/my_not_ruby_precompiler'
|
26
|
+
precompile:
|
27
|
+
- paths: '*.not_rb'
|
28
|
+
format: { custom: MyNotRubyPrecompiler }
|
29
|
+
```
|
30
|
+
|
31
|
+
Ensure any necessary extension patterns are added to to [`include_paths:`](https://github.com/robotdana/leftovers/tree/main/docs/Configuration.md#include_paths) for those particular files you wish to check.
|
32
|
+
|
33
|
+
Require the custom precompiler using [`require:`](https://github.com/robotdana/leftovers/tree/main/docs/Configuration.md#requires)
|
34
|
+
|
35
|
+
Define which paths use the custom precompiler using [`precompile:`](https://github.com/robotdana/leftovers/tree/main/docs/Configuration.md#precompile),
|
36
|
+
reference the name of the precompiler with `format: { custom: MyNotRubyPrecompiler }`
|
37
|
+
|
38
|
+
If the `precompile` method raises any errors while precompiling, a warning will be printed to stderr and the file will be skipped
|
data/lib/config/actionpack.yml
CHANGED
data/lib/config/haml.yml
CHANGED
data/lib/config/ruby.yml
CHANGED
@@ -10,25 +10,14 @@ include_paths:
|
|
10
10
|
- '*.erb'
|
11
11
|
- '*.rb'
|
12
12
|
|
13
|
-
yaml_paths:
|
14
|
-
- '*.yml'
|
15
|
-
- '*.yaml'
|
16
|
-
|
17
|
-
json_paths:
|
18
|
-
- '*.json'
|
19
|
-
|
20
13
|
test_paths:
|
21
14
|
- /tests/
|
22
15
|
- /test/
|
23
16
|
|
24
|
-
|
25
|
-
- '*.erb'
|
26
|
-
|
27
|
-
|
28
|
-
- '*.haml'
|
29
|
-
|
30
|
-
slim_paths:
|
31
|
-
- '*.slim'
|
17
|
+
precompile:
|
18
|
+
- { paths: '*.erb', format: 'erb' }
|
19
|
+
- { paths: ['*.yml', '*.yaml'], format: 'yaml' }
|
20
|
+
- { paths: '*.json', format: 'json' }
|
32
21
|
|
33
22
|
keep:
|
34
23
|
- initialize # called by new
|
data/lib/config/slim.yml
CHANGED
data/lib/leftovers/cli.rb
CHANGED
data/lib/leftovers/collector.rb
CHANGED
@@ -45,7 +45,8 @@ module Leftovers
|
|
45
45
|
|
46
46
|
def print_progress
|
47
47
|
Leftovers.print(
|
48
|
-
"\e[2Kchecked #{@count} files,
|
48
|
+
"\e[2Kchecked #{@count} files, " \
|
49
|
+
"collected #{@count_calls} calls, #{@count_definitions} definitions\r"
|
49
50
|
)
|
50
51
|
end
|
51
52
|
|
data/lib/leftovers/config.rb
CHANGED
@@ -26,24 +26,8 @@ module Leftovers
|
|
26
26
|
@test_paths ||= Array(yaml[:test_paths])
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
@
|
31
|
-
end
|
32
|
-
|
33
|
-
def slim_paths
|
34
|
-
@slim_paths ||= Array(yaml[:slim_paths])
|
35
|
-
end
|
36
|
-
|
37
|
-
def yaml_paths
|
38
|
-
@yaml_paths ||= Array(yaml[:yaml_paths])
|
39
|
-
end
|
40
|
-
|
41
|
-
def json_paths
|
42
|
-
@json_paths ||= Array(yaml[:json_paths])
|
43
|
-
end
|
44
|
-
|
45
|
-
def erb_paths
|
46
|
-
@erb_paths ||= Array(yaml[:erb_paths])
|
29
|
+
def precompile
|
30
|
+
@precompile ||= Leftovers.each_or_self(yaml[:precompile]).to_a
|
47
31
|
end
|
48
32
|
|
49
33
|
def dynamic
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
module Leftovers
|
4
4
|
class ConfigLoader
|
5
|
-
class ArgumentPositionSchema <
|
5
|
+
class ArgumentPositionSchema < ValueOrObjectSchema
|
6
6
|
inherit_attributes_from StringPatternSchema
|
7
7
|
|
8
|
-
self.
|
8
|
+
self.or_value_schema = ScalarArgumentSchema
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -3,27 +3,53 @@
|
|
3
3
|
module Leftovers
|
4
4
|
class ConfigLoader
|
5
5
|
class Attribute
|
6
|
-
|
6
|
+
attr_reader(
|
7
|
+
:name,
|
8
|
+
:aliases, :schema # leftovers:test_only
|
9
|
+
)
|
10
|
+
|
11
|
+
attr_accessor :require_group
|
12
|
+
|
13
|
+
def initialize(name, schema, aliases: nil, require_group: nil, suggest: true)
|
7
14
|
@name = name
|
8
|
-
@
|
15
|
+
@schema = schema
|
9
16
|
@aliases = aliases
|
10
17
|
@require_group = require_group
|
18
|
+
@suggest = suggest
|
19
|
+
end
|
20
|
+
|
21
|
+
def without_require_group
|
22
|
+
new = dup
|
23
|
+
new.require_group = nil
|
24
|
+
new
|
25
|
+
end
|
26
|
+
|
27
|
+
def suggest?
|
28
|
+
@suggest
|
11
29
|
end
|
12
30
|
|
13
31
|
def attributes
|
14
|
-
|
32
|
+
[self]
|
33
|
+
end
|
34
|
+
|
35
|
+
def name?(name)
|
36
|
+
name = name.to_sym
|
37
|
+
|
38
|
+
@name == name || Leftovers.each_or_self(@aliases).include?(name)
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_ruby(value)
|
42
|
+
[key_to_ruby, @schema.to_ruby(value)]
|
15
43
|
end
|
16
44
|
|
17
|
-
def
|
18
|
-
|
19
|
-
[aka, @name]
|
20
|
-
end.to_h
|
45
|
+
def validate_value(value)
|
46
|
+
@schema.validate(value)
|
21
47
|
end
|
22
48
|
|
23
|
-
|
24
|
-
return {} unless @require_group
|
49
|
+
private
|
25
50
|
|
26
|
-
|
51
|
+
def key_to_ruby
|
52
|
+
name == :unless ? :unless_arg : name
|
27
53
|
end
|
28
54
|
end
|
29
55
|
end
|
@@ -6,16 +6,43 @@ module Leftovers
|
|
6
6
|
attribute :include_paths, ValueOrArraySchema[StringSchema], aliases: :include_path
|
7
7
|
attribute :exclude_paths, ValueOrArraySchema[StringSchema], aliases: :exclude_path
|
8
8
|
attribute :test_paths, ValueOrArraySchema[StringSchema], aliases: :test_path
|
9
|
-
attribute :haml_paths, ValueOrArraySchema[StringSchema], aliases: :haml_path
|
10
|
-
attribute :slim_paths, ValueOrArraySchema[StringSchema], aliases: :slim_path
|
11
|
-
attribute :yaml_paths, ValueOrArraySchema[StringSchema], aliases: :yaml_path
|
12
|
-
attribute :json_paths, ValueOrArraySchema[StringSchema], aliases: :json_path
|
13
|
-
attribute :erb_paths, ValueOrArraySchema[StringSchema], aliases: :erb_path
|
9
|
+
attribute :haml_paths, ValueOrArraySchema[StringSchema], aliases: :haml_path, suggest: false
|
10
|
+
attribute :slim_paths, ValueOrArraySchema[StringSchema], aliases: :slim_path, suggest: false
|
11
|
+
attribute :yaml_paths, ValueOrArraySchema[StringSchema], aliases: :yaml_path, suggest: false
|
12
|
+
attribute :json_paths, ValueOrArraySchema[StringSchema], aliases: :json_path, suggest: false
|
13
|
+
attribute :erb_paths, ValueOrArraySchema[StringSchema], aliases: :erb_path, suggest: false
|
14
|
+
attribute :precompile, ValueOrArraySchema[PrecompileSchema]
|
14
15
|
attribute :requires, ValueOrArraySchema[RequireSchema], aliases: :require
|
15
16
|
attribute :gems, ValueOrArraySchema[StringSchema], aliases: :gem
|
16
17
|
attribute :keep, ValueOrArraySchema[KeepTestOnlySchema]
|
17
18
|
attribute :test_only, ValueOrArraySchema[KeepTestOnlySchema]
|
18
19
|
attribute :dynamic, ValueOrArraySchema[DynamicSchema]
|
20
|
+
|
21
|
+
PRECOMPILERS = %i{haml_paths slim_paths json_paths yaml_paths erb_paths}.freeze
|
22
|
+
|
23
|
+
def self.to_ruby(node) # rubocop:disable Metrics
|
24
|
+
read_hash = super
|
25
|
+
write_hash = read_hash.dup
|
26
|
+
|
27
|
+
read_hash.each do |key, value|
|
28
|
+
next unless PRECOMPILERS.include?(key)
|
29
|
+
|
30
|
+
value = { paths: value, format: key.to_s.delete_suffix('_paths') }
|
31
|
+
yaml = { 'precompile' => [value.transform_keys(&:to_s)] }.to_yaml.delete_prefix("---\n")
|
32
|
+
|
33
|
+
Leftovers.warn(<<~MESSAGE)
|
34
|
+
\e[33m`#{key}:` is deprecated\e[0m
|
35
|
+
Replace with:
|
36
|
+
\e[32m#{yaml}\e[0m
|
37
|
+
MESSAGE
|
38
|
+
|
39
|
+
write_hash[:precompile] = Leftovers.each_or_self(write_hash[:precompile]).to_a
|
40
|
+
write_hash[:precompile] << value
|
41
|
+
write_hash.delete(key)
|
42
|
+
end
|
43
|
+
|
44
|
+
write_hash
|
45
|
+
end
|
19
46
|
end
|
20
47
|
end
|
21
48
|
end
|
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
module Leftovers
|
4
4
|
class ConfigLoader
|
5
|
-
class HasArgumentSchema <
|
5
|
+
class HasArgumentSchema < ValueOrObjectSchema
|
6
6
|
attribute :at, ValueOrArraySchema[ArgumentPositionSchema], require_group: :matcher
|
7
7
|
attribute :has_value, ValueOrArraySchema[HasValueSchema], require_group: :matcher
|
8
8
|
attribute :unless, ValueOrArraySchema[HasArgumentSchema], require_group: :matcher
|
9
9
|
|
10
|
-
self.
|
10
|
+
self.or_value_schema = ScalarArgumentSchema
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Leftovers
|
4
4
|
class ConfigLoader
|
5
|
-
class HasValueSchema <
|
5
|
+
class HasValueSchema < ValueOrObjectSchema
|
6
6
|
inherit_attributes_from StringPatternSchema, except: :unless
|
7
7
|
|
8
8
|
attribute :at, ValueOrArraySchema[ArgumentPositionSchema], require_group: :matcher
|
@@ -12,7 +12,7 @@ module Leftovers
|
|
12
12
|
attribute :type, ValueOrArraySchema[ValueTypeSchema], require_group: :matcher
|
13
13
|
attribute :unless, ValueOrArraySchema[HasValueSchema], require_group: :matcher
|
14
14
|
|
15
|
-
self.
|
15
|
+
self.or_value_schema = ScalarValueSchema
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
class ConfigLoader
|
5
|
+
class InheritSchemaAttributes
|
6
|
+
def initialize(schema, require_group: true, except: nil)
|
7
|
+
@schema = schema
|
8
|
+
@use_require_groups = require_group
|
9
|
+
@except = Leftovers.each_or_self(except)
|
10
|
+
end
|
11
|
+
|
12
|
+
def attributes
|
13
|
+
@schema.attributes.map do |attr|
|
14
|
+
next if @except.include?(attr.name)
|
15
|
+
next attr.without_require_group unless @use_require_groups
|
16
|
+
|
17
|
+
attr
|
18
|
+
end.compact
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
module Leftovers
|
4
4
|
class ConfigLoader
|
5
|
-
class KeepTestOnlySchema <
|
5
|
+
class KeepTestOnlySchema < ValueOrObjectSchema
|
6
6
|
inherit_attributes_from StringPatternSchema, except: :unless
|
7
7
|
inherit_attributes_from RulePatternSchema, except: :unless
|
8
8
|
attribute :unless, ValueOrArraySchema[KeepTestOnlySchema], require_group: :matcher
|
9
9
|
|
10
|
-
self.
|
10
|
+
self.or_value_schema = StringSchema
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|