leftovers 0.7.0 → 0.8.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.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +1 -0
  4. data/docs/Configuration.md +20 -57
  5. data/docs/Custom-Precompilers.md +38 -0
  6. data/lib/config/actionpack.yml +5 -3
  7. data/lib/config/haml.yml +4 -2
  8. data/lib/config/ruby.yml +4 -15
  9. data/lib/config/slim.yml +4 -2
  10. data/lib/leftovers/cli.rb +5 -0
  11. data/lib/leftovers/collector.rb +2 -1
  12. data/lib/leftovers/config.rb +2 -18
  13. data/lib/leftovers/config_loader/argument_position_schema.rb +2 -2
  14. data/lib/leftovers/config_loader/attribute.rb +36 -10
  15. data/lib/leftovers/config_loader/built_in_precompiler_schema.rb +13 -0
  16. data/lib/leftovers/config_loader/document_schema.rb +32 -5
  17. data/lib/leftovers/config_loader/has_argument_schema.rb +2 -2
  18. data/lib/leftovers/config_loader/has_value_schema.rb +2 -2
  19. data/lib/leftovers/config_loader/inherit_schema_attributes.rb +22 -0
  20. data/lib/leftovers/config_loader/keep_test_only_schema.rb +2 -2
  21. data/lib/leftovers/config_loader/object_schema.rb +33 -105
  22. data/lib/leftovers/config_loader/precompile_schema.rb +12 -0
  23. data/lib/leftovers/config_loader/precompiler_schema.rb +11 -0
  24. data/lib/leftovers/config_loader/privacy_processor_schema.rb +0 -2
  25. data/lib/leftovers/config_loader/require_schema.rb +3 -3
  26. data/lib/leftovers/config_loader/schema.rb +2 -0
  27. data/lib/leftovers/config_loader/string_pattern_schema.rb +2 -2
  28. data/lib/leftovers/config_loader/string_value_processor_schema.rb +2 -2
  29. data/lib/leftovers/config_loader/transform_schema.rb +4 -6
  30. data/lib/leftovers/config_loader/value_matcher_schema.rb +2 -2
  31. data/lib/leftovers/config_loader/value_or_array_schema.rb +5 -3
  32. data/lib/leftovers/config_loader/value_or_object_schema.rb +40 -0
  33. data/lib/leftovers/config_loader/value_processor_schema.rb +2 -2
  34. data/lib/leftovers/config_loader.rb +5 -1
  35. data/lib/leftovers/file.rb +7 -53
  36. data/lib/leftovers/file_collector/comments_processor.rb +57 -0
  37. data/lib/leftovers/file_collector/node_processor.rb +131 -0
  38. data/lib/leftovers/file_collector.rb +42 -203
  39. data/lib/leftovers/matcher_builders/and_not.rb +7 -5
  40. data/lib/leftovers/matcher_builders/name.rb +18 -17
  41. data/lib/leftovers/matcher_builders/node.rb +48 -34
  42. data/lib/leftovers/matcher_builders/node_has_argument.rb +48 -52
  43. data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +13 -10
  44. data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +29 -15
  45. data/lib/leftovers/matcher_builders/node_type.rb +1 -1
  46. data/lib/leftovers/matcher_builders/node_value.rb +27 -22
  47. data/lib/leftovers/matcher_builders/or.rb +50 -50
  48. data/lib/leftovers/matcher_builders/string_pattern.rb +1 -1
  49. data/lib/leftovers/merged_config.rb +3 -23
  50. data/lib/leftovers/precompilers/erb.rb +22 -0
  51. data/lib/leftovers/precompilers/haml.rb +15 -0
  52. data/lib/leftovers/precompilers/json.rb +27 -0
  53. data/lib/leftovers/precompilers/precompiler.rb +28 -0
  54. data/lib/leftovers/precompilers/slim.rb +15 -0
  55. data/lib/leftovers/precompilers/yaml.rb +75 -0
  56. data/lib/leftovers/precompilers.rb +50 -0
  57. data/lib/leftovers/processor_builders/action.rb +48 -39
  58. data/lib/leftovers/processor_builders/add_prefix.rb +1 -1
  59. data/lib/leftovers/processor_builders/add_suffix.rb +1 -1
  60. data/lib/leftovers/processor_builders/argument.rb +8 -11
  61. data/lib/leftovers/processor_builders/dynamic.rb +5 -5
  62. data/lib/leftovers/processor_builders/each.rb +2 -2
  63. data/lib/leftovers/processor_builders/each_action.rb +33 -33
  64. data/lib/leftovers/processor_builders/each_dynamic.rb +4 -8
  65. data/lib/leftovers/processor_builders/each_for_definition_set.rb +25 -21
  66. data/lib/leftovers/processor_builders/keyword.rb +3 -4
  67. data/lib/leftovers/processor_builders/transform.rb +2 -2
  68. data/lib/leftovers/processor_builders/transform_chain.rb +16 -8
  69. data/lib/leftovers/processor_builders/transform_set.rb +32 -28
  70. data/lib/leftovers/rake_task.rb +1 -1
  71. data/lib/leftovers/value_processors/add_dynamic_prefix.rb +3 -10
  72. data/lib/leftovers/value_processors/add_dynamic_suffix.rb +3 -10
  73. data/lib/leftovers/value_processors/each.rb +1 -1
  74. data/lib/leftovers/value_processors/each_for_definition_set.rb +2 -5
  75. data/lib/leftovers/value_processors/each_keyword.rb +1 -1
  76. data/lib/leftovers/value_processors/each_keyword_argument.rb +1 -1
  77. data/lib/leftovers/value_processors/each_positional_argument.rb +2 -1
  78. data/lib/leftovers/value_processors/keyword.rb +3 -7
  79. data/lib/leftovers/value_processors/keyword_argument.rb +2 -6
  80. data/lib/leftovers/value_processors/split.rb +2 -2
  81. data/lib/leftovers/version.rb +1 -1
  82. data/lib/leftovers.rb +41 -6
  83. metadata +17 -7
  84. data/lib/leftovers/erb.rb +0 -20
  85. data/lib/leftovers/haml.rb +0 -21
  86. data/lib/leftovers/json.rb +0 -28
  87. data/lib/leftovers/slim.rb +0 -21
  88. data/lib/leftovers/yaml.rb +0 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f27830ef42bcbcec33a78126a3b47582fa394714e1d137e802cd5ab166e35df5
4
- data.tar.gz: a111ed33a8345fe8dc5d43cb92206d52cbc47a03bc8e961baee8558d677542b6
3
+ metadata.gz: c2e0c74dad85b7b571608a7207f006fe14d5748e1a155470185112b80a7b80a3
4
+ data.tar.gz: 68f3d83b310f640e127b961e6ac2ece795a7b9e2a6de961a1b42498916e092d7
5
5
  SHA512:
6
- metadata.gz: e14c6c1b74d4c13ebcbb4d1184d50257d6aacaf05e8e6708282633f61ea1988374156880d66bb26a037bf4b67b58381246f12357bdaa99ff9248db620d94c152
7
- data.tar.gz: 34e766e6ca2374858ee6da35e924287641bc4441d8f642e4d08285a0066185aa865724567b90f91de34b17f340f3f182e9b3f326c5fc63bf6abc414c0dc058b3
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)
@@ -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
- - [`haml_paths:`](#haml_paths)
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
- ## `haml_paths:`
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
- haml_paths:
98
- - '*.haml'
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
- Arrays are not necessary for single values. `*.haml` is recognized by default
98
+ Define any precompilers and the paths they affect.
102
99
 
103
- ## `slim_paths:`
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
- Arrays are not necessary for single values. `*.erb` is recognized by default
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
- ## `yaml_paths:`
105
+ See [Custom precompilers]('../Custom-Precompilers.md) for more details on the custom precompiler class
128
106
 
129
- list filenames/paths of test directories that are in the yaml format
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
- ```yml
133
- include:
134
- - 'config/*.yml'
135
- yaml_paths:
136
- - '*.yml'
137
- ```
109
+ ### `format: yaml`
138
110
 
139
- These documents will consider yaml tags like `!ruby/class 'MyClass'` to be a call to `MyClass` and render the structure of the yaml as arguments for the [`document:true`](#document-true) rule.
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
- ## `json_paths:`
135
+ ### `format: json`
163
136
 
164
- list filenames/paths of test directories that are in the json format
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
- ```yml
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
@@ -7,9 +7,11 @@ include_paths:
7
7
  - '*.rjs'
8
8
  - '*.rhtml'
9
9
 
10
- erb_paths:
11
- - '*.rjs'
12
- - '*.rhtml'
10
+ precompile:
11
+ - paths:
12
+ - '*.rjs'
13
+ - '*.rhtml'
14
+ format: erb
13
15
 
14
16
  keep:
15
17
  - ssl_configured? # ApplicationController
data/lib/config/haml.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  include_paths:
2
2
  - '*.haml'
3
- haml_paths:
4
- - '*.haml'
3
+ requires: 'haml'
4
+ precompile:
5
+ format: haml
6
+ paths: '*.haml'
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
- erb_paths:
25
- - '*.erb'
26
-
27
- haml_paths:
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
@@ -1,4 +1,6 @@
1
1
  include_paths:
2
2
  - '*.slim'
3
- slim_paths:
4
- - '*.slim'
3
+ requires: 'slim'
4
+ precompile:
5
+ paths: '*.slim'
6
+ format: slim
data/lib/leftovers/cli.rb CHANGED
@@ -57,6 +57,11 @@ module Leftovers
57
57
  end
58
58
 
59
59
  opts.parse(argv)
60
+ rescue OptionParser::InvalidOption => e
61
+ stderr.puts("\e[31mCLI Error: #{e.message}\e[0m")
62
+ stderr.puts ''
63
+ stderr.puts(opts.help)
64
+ Leftovers.exit 1
60
65
  end
61
66
  end
62
67
  end
@@ -45,7 +45,8 @@ module Leftovers
45
45
 
46
46
  def print_progress
47
47
  Leftovers.print(
48
- "\e[2Kchecked #{@count} files, collected #{@count_calls} calls, #{@count_definitions} definitions\r" # rubocop:disable Layout/LineLength
48
+ "\e[2Kchecked #{@count} files, " \
49
+ "collected #{@count_calls} calls, #{@count_definitions} definitions\r"
49
50
  )
50
51
  end
51
52
 
@@ -26,24 +26,8 @@ module Leftovers
26
26
  @test_paths ||= Array(yaml[:test_paths])
27
27
  end
28
28
 
29
- def haml_paths
30
- @haml_paths ||= Array(yaml[:haml_paths])
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 < ObjectSchema
5
+ class ArgumentPositionSchema < ValueOrObjectSchema
6
6
  inherit_attributes_from StringPatternSchema
7
7
 
8
- self.or_schema = ScalarArgumentSchema
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
- def initialize(name, value_schema, aliases: nil, require_group: nil)
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
- @value_schema = value_schema
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
- { @name => @value_schema }
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 aliases
18
- ::Leftovers.each_or_self(@aliases).map do |aka|
19
- [aka, @name]
20
- end.to_h
45
+ def validate_value(value)
46
+ @schema.validate(value)
21
47
  end
22
48
 
23
- def require_groups
24
- return {} unless @require_group
49
+ private
25
50
 
26
- { @require_group => [@name, *::Leftovers.each_or_self(@aliases)] }
51
+ def key_to_ruby
52
+ name == :unless ? :unless_arg : name
27
53
  end
28
54
  end
29
55
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leftovers
4
+ class ConfigLoader
5
+ class BuiltInPrecompilerSchema < StringEnumSchema
6
+ value :erb
7
+ value :yaml
8
+ value :json
9
+ value :slim
10
+ value :haml
11
+ end
12
+ end
13
+ 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 < ObjectSchema
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.or_schema = ScalarArgumentSchema
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 < ObjectSchema
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.or_schema = ScalarValueSchema
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 < ObjectSchema
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.or_schema = StringSchema
10
+ self.or_value_schema = StringSchema
11
11
  end
12
12
  end
13
13
  end