leftovers 0.11.1 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +1 -0
  4. data/docs/Configuration.md +7 -0
  5. data/exe/leftovers +3 -1
  6. data/leftovers.gemspec +3 -4
  7. data/lib/config/activesupport.yml +1 -1
  8. data/lib/config/rspec.yml +21 -0
  9. data/lib/leftovers/ast/array_node.rb +2 -2
  10. data/lib/leftovers/ast/block_node.rb +1 -1
  11. data/lib/leftovers/ast/builder.rb +19 -18
  12. data/lib/leftovers/ast/casgn_node.rb +2 -2
  13. data/lib/leftovers/ast/const_node.rb +1 -1
  14. data/lib/leftovers/ast/def_node.rb +1 -1
  15. data/lib/leftovers/ast/defs_node.rb +1 -1
  16. data/lib/leftovers/ast/false_node.rb +1 -1
  17. data/lib/leftovers/ast/hash_node.rb +2 -2
  18. data/lib/leftovers/ast/module_node.rb +1 -1
  19. data/lib/leftovers/ast/nil_node.rb +1 -1
  20. data/lib/leftovers/ast/node.rb +13 -1
  21. data/lib/leftovers/ast/numeric_node.rb +1 -1
  22. data/lib/leftovers/ast/send_node.rb +16 -3
  23. data/lib/leftovers/ast/str_node.rb +1 -1
  24. data/lib/leftovers/ast/sym_node.rb +1 -1
  25. data/lib/leftovers/ast/true_node.rb +1 -1
  26. data/lib/leftovers/ast/var_node.rb +1 -1
  27. data/lib/leftovers/ast/vasgn_node.rb +2 -2
  28. data/lib/leftovers/ast.rb +2 -21
  29. data/lib/leftovers/autoloader.rb +36 -0
  30. data/lib/leftovers/cli.rb +58 -42
  31. data/lib/leftovers/collection.rb +66 -0
  32. data/lib/leftovers/collector.rb +17 -27
  33. data/lib/leftovers/config.rb +17 -5
  34. data/lib/leftovers/config_loader/attribute.rb +2 -2
  35. data/lib/leftovers/config_loader/bool_schema.rb +21 -0
  36. data/lib/leftovers/config_loader/document_schema.rb +2 -2
  37. data/lib/leftovers/config_loader/inherit_schema_attributes.rb +1 -1
  38. data/lib/leftovers/config_loader/node.rb +8 -8
  39. data/lib/leftovers/config_loader/regexp_schema.rb +1 -1
  40. data/lib/leftovers/config_loader/rule_pattern_schema.rb +1 -0
  41. data/lib/leftovers/config_loader/schema.rb +1 -1
  42. data/lib/leftovers/config_loader/string_enum_schema.rb +1 -1
  43. data/lib/leftovers/config_loader/value_or_array_schema.rb +1 -1
  44. data/lib/leftovers/config_loader.rb +8 -48
  45. data/lib/leftovers/definition.rb +4 -4
  46. data/lib/leftovers/definition_collection.rb +3 -3
  47. data/lib/leftovers/definition_node.rb +2 -2
  48. data/lib/leftovers/definition_node_set.rb +1 -1
  49. data/lib/leftovers/definition_set.rb +4 -4
  50. data/lib/leftovers/definition_to_add.rb +2 -2
  51. data/lib/leftovers/error.rb +6 -0
  52. data/lib/leftovers/file.rb +4 -4
  53. data/lib/leftovers/file_collector/comments_processor.rb +23 -18
  54. data/lib/leftovers/file_collector/node_processor.rb +8 -1
  55. data/lib/leftovers/file_collector.rb +12 -15
  56. data/lib/leftovers/file_list.rb +4 -6
  57. data/lib/leftovers/matcher_builders/and.rb +5 -5
  58. data/lib/leftovers/matcher_builders/document.rb +1 -3
  59. data/lib/leftovers/matcher_builders/name.rb +4 -7
  60. data/lib/leftovers/matcher_builders/node.rb +21 -35
  61. data/lib/leftovers/matcher_builders/node_has_argument.rb +17 -29
  62. data/lib/leftovers/matcher_builders/node_has_block.rb +17 -0
  63. data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +7 -9
  64. data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +10 -10
  65. data/lib/leftovers/matcher_builders/node_has_receiver.rb +6 -8
  66. data/lib/leftovers/matcher_builders/node_name.rb +3 -5
  67. data/lib/leftovers/matcher_builders/node_pair_key.rb +4 -4
  68. data/lib/leftovers/matcher_builders/node_pair_value.rb +4 -4
  69. data/lib/leftovers/matcher_builders/node_path.rb +3 -4
  70. data/lib/leftovers/matcher_builders/node_privacy.rb +3 -3
  71. data/lib/leftovers/matcher_builders/node_type.rb +13 -14
  72. data/lib/leftovers/matcher_builders/node_value.rb +18 -31
  73. data/lib/leftovers/matcher_builders/or.rb +10 -10
  74. data/lib/leftovers/matcher_builders/path.rb +3 -3
  75. data/lib/leftovers/matcher_builders/string_pattern.rb +2 -0
  76. data/lib/leftovers/matcher_builders/unless.rb +1 -3
  77. data/lib/leftovers/matcher_builders.rb +2 -22
  78. data/lib/leftovers/matchers/node_has_block.rb +13 -0
  79. data/lib/leftovers/matchers/node_scalar_value.rb +1 -1
  80. data/lib/leftovers/matchers.rb +2 -27
  81. data/lib/leftovers/merged_config.rb +16 -17
  82. data/lib/leftovers/parser.rb +1 -1
  83. data/lib/leftovers/precompile_error.rb +31 -0
  84. data/lib/leftovers/precompilers/haml.rb +23 -3
  85. data/lib/leftovers/precompilers/json.rb +1 -1
  86. data/lib/leftovers/precompilers/precompiler.rb +3 -3
  87. data/lib/leftovers/precompilers/slim.rb +1 -1
  88. data/lib/leftovers/precompilers/yaml/builder.rb +62 -0
  89. data/lib/leftovers/precompilers/yaml.rb +3 -56
  90. data/lib/leftovers/precompilers.rb +11 -16
  91. data/lib/leftovers/processor_builders/action.rb +15 -19
  92. data/lib/leftovers/processor_builders/add_prefix.rb +4 -6
  93. data/lib/leftovers/processor_builders/add_suffix.rb +4 -6
  94. data/lib/leftovers/processor_builders/argument.rb +10 -15
  95. data/lib/leftovers/processor_builders/dynamic.rb +12 -30
  96. data/lib/leftovers/processor_builders/each.rb +63 -76
  97. data/lib/leftovers/processor_builders/each_for_definition_set.rb +15 -0
  98. data/lib/leftovers/processor_builders/itself.rb +2 -4
  99. data/lib/leftovers/processor_builders/keyword.rb +4 -4
  100. data/lib/leftovers/processor_builders/keyword_argument.rb +4 -4
  101. data/lib/leftovers/processor_builders/receiver.rb +2 -4
  102. data/lib/leftovers/processor_builders/transform.rb +26 -49
  103. data/lib/leftovers/processor_builders/transform_chain.rb +4 -7
  104. data/lib/leftovers/processor_builders/transform_set.rb +6 -7
  105. data/lib/leftovers/processor_builders/value.rb +2 -2
  106. data/lib/leftovers/processor_builders.rb +2 -15
  107. data/lib/leftovers/processors/add_definition_node.rb +2 -2
  108. data/lib/leftovers/processors/camelize.rb +3 -3
  109. data/lib/leftovers/processors/deconstantize.rb +3 -3
  110. data/lib/leftovers/processors/demodulize.rb +3 -3
  111. data/lib/leftovers/processors/each_for_definition_set.rb +2 -2
  112. data/lib/leftovers/processors/eval.rb +1 -1
  113. data/lib/leftovers/processors/parameterize.rb +3 -3
  114. data/lib/leftovers/processors/placeholder.rb +1 -1
  115. data/lib/leftovers/processors/pluralize.rb +3 -3
  116. data/lib/leftovers/processors/set_default_privacy.rb +1 -1
  117. data/lib/leftovers/processors/set_privacy.rb +1 -1
  118. data/lib/leftovers/processors/singularize.rb +3 -3
  119. data/lib/leftovers/processors/titleize.rb +3 -3
  120. data/lib/leftovers/processors/underscore.rb +3 -3
  121. data/lib/leftovers/processors.rb +2 -44
  122. data/lib/leftovers/rake_task.rb +2 -2
  123. data/lib/leftovers/reporter.rb +44 -42
  124. data/lib/leftovers/runner.rb +40 -0
  125. data/lib/leftovers/todo_reporter.rb +96 -94
  126. data/lib/leftovers/unexpected_case.rb +8 -0
  127. data/lib/leftovers/version.rb +1 -1
  128. data/lib/leftovers.rb +17 -110
  129. metadata +13 -17
  130. data/lib/leftovers/matcher_builders/and_not.rb +0 -16
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+
5
+ module Leftovers
6
+ class Collection
7
+ attr_reader :calls, :test_calls, :definitions
8
+
9
+ def initialize
10
+ @calls = []
11
+ @test_calls = []
12
+ @definitions = []
13
+ end
14
+
15
+ def leftovers
16
+ @leftovers ||= begin
17
+ freeze_calls
18
+
19
+ @definitions
20
+ .reject { |definition| definition.in_collection?(self) }
21
+ .sort_by(&:location_s).freeze
22
+ end
23
+ end
24
+
25
+ def with_tests
26
+ split_leftovers.first
27
+ end
28
+
29
+ def without_tests
30
+ split_leftovers[1]
31
+ end
32
+
33
+ def empty?
34
+ leftovers.empty?
35
+ end
36
+
37
+ def concat(calls:, definitions:, test:)
38
+ if test
39
+ @test_calls.concat(calls)
40
+ else
41
+ @calls.concat(calls)
42
+ end
43
+
44
+ @definitions.concat(definitions)
45
+ end
46
+
47
+ private
48
+
49
+ def split_leftovers
50
+ return @split_leftovers if defined?(@split_leftovers)
51
+
52
+ @split_leftovers = leftovers.partition do |definition|
53
+ !definition.test? && definition.in_test_collection?(self)
54
+ end.each(&:freeze).freeze
55
+
56
+ freeze
57
+
58
+ @split_leftovers
59
+ end
60
+
61
+ def freeze_calls
62
+ @calls = @calls.to_set.freeze
63
+ @test_calls = @test_calls.to_set.freeze
64
+ end
65
+ end
66
+ end
@@ -1,34 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fast_ignore'
4
- require 'set'
5
3
  require 'parallel'
6
4
 
5
+ require 'parser'
6
+ require 'parser/current' # to get the error message early and once before we parallel things
7
+
7
8
  module Leftovers
8
9
  class Collector
9
- attr_reader :calls, :test_calls, :definitions
10
+ attr_writer :progress, :parallel
11
+ attr_reader :collection
10
12
 
11
13
  def initialize
12
- @calls = []
13
- @test_calls = []
14
- @definitions = []
15
14
  @count = 0
16
15
  @count_calls = 0
17
16
  @count_definitions = 0
17
+ @progress = true
18
+ @parallel = true
19
+ @collection ||= Collection.new
18
20
  end
19
21
 
20
22
  def collect
21
- Leftovers.reporter.prepare
22
- collect_file_list(Leftovers::FileList.new)
23
- print_progress
24
- Leftovers.newline
25
- @calls = @calls.to_set.freeze
26
- @test_calls = @test_calls.to_set.freeze
23
+ collect_file_list(FileList.new)
24
+ ::Leftovers.puts progress_message
27
25
  end
28
26
 
29
27
  def collect_file_list(list)
30
- if Leftovers.parallel?
31
- Parallel.each(list, finish: method(:finish_file)) do |file|
28
+ if @parallel
29
+ ::Parallel.each(list, finish: method(:finish_file)) do |file|
32
30
  collect_file(file)
33
31
  end
34
32
  else
@@ -37,31 +35,23 @@ module Leftovers
37
35
  end
38
36
 
39
37
  def collect_file(file)
40
- file_collector = ::Leftovers::FileCollector.new(file.ruby, file)
38
+ file_collector = FileCollector.new(file.ruby, file)
41
39
  file_collector.collect
42
40
 
43
41
  file_collector.to_h
44
42
  end
45
43
 
46
- def print_progress
47
- Leftovers.print(
48
- "\e[2Kchecked #{@count} files, " \
49
- "collected #{@count_calls} calls, #{@count_definitions} definitions\r"
50
- )
44
+ def progress_message
45
+ "checked #{@count} files, collected #{@count_calls} calls, #{@count_definitions} definitions"
51
46
  end
52
47
 
53
48
  def finish_file(_item, _index, result)
54
49
  @count += 1
55
50
  @count_calls += result[:calls].length
56
51
  @count_definitions += result[:definitions].length
57
- print_progress if Leftovers.progress?
58
- if result[:test?]
59
- @test_calls.concat(result[:calls])
60
- else
61
- @calls.concat(result[:calls])
62
- end
52
+ ::Leftovers.print(progress_message) if @progress
63
53
 
64
- @definitions.concat(result[:definitions])
54
+ @collection.concat(**result)
65
55
  end
66
56
  end
67
57
  end
@@ -3,6 +3,18 @@
3
3
  module Leftovers
4
4
  class Config
5
5
  attr_reader :name
6
+ alias_method :to_sym, :name
7
+
8
+ def self.[](name_or_config)
9
+ return name_or_config if name_or_config.is_a?(self)
10
+
11
+ @loaded_configs ||= {}
12
+ @loaded_configs[name_or_config] ||= new(name_or_config)
13
+ end
14
+
15
+ def self.reset
16
+ @loaded_configs = {}
17
+ end
6
18
 
7
19
  def initialize(name, path: nil, content: nil)
8
20
  @name = name.to_sym
@@ -27,19 +39,19 @@ module Leftovers
27
39
  end
28
40
 
29
41
  def precompile
30
- @precompile ||= Leftovers.each_or_self(yaml[:precompile]).to_a
42
+ @precompile ||= ::Leftovers.wrap_array(yaml[:precompile])
31
43
  end
32
44
 
33
45
  def dynamic
34
- @dynamic ||= ::Leftovers::ProcessorBuilders::Dynamic.build(yaml[:dynamic])
46
+ @dynamic ||= ProcessorBuilders::Dynamic.build(yaml[:dynamic])
35
47
  end
36
48
 
37
49
  def keep
38
- @keep ||= ::Leftovers::MatcherBuilders::Node.build(yaml[:keep])
50
+ @keep ||= MatcherBuilders::Node.build(yaml[:keep])
39
51
  end
40
52
 
41
53
  def test_only
42
- @test_only ||= ::Leftovers::MatcherBuilders::Node.build(yaml[:test_only])
54
+ @test_only ||= MatcherBuilders::Node.build(yaml[:test_only])
43
55
  end
44
56
 
45
57
  def requires
@@ -49,7 +61,7 @@ module Leftovers
49
61
  private
50
62
 
51
63
  def yaml
52
- @yaml ||= ::Leftovers::ConfigLoader.load(name, path: @path, content: @content)
64
+ @yaml ||= ConfigLoader.load(name, path: @path, content: @content)
53
65
  end
54
66
  end
55
67
  end
@@ -13,7 +13,7 @@ module Leftovers
13
13
  def initialize(name, schema, aliases: nil, require_group: nil, suggest: true)
14
14
  @name = name
15
15
  @schema = schema
16
- @aliases = aliases
16
+ @aliases = Array(aliases)
17
17
  @require_group = require_group
18
18
  @suggest = suggest
19
19
  end
@@ -35,7 +35,7 @@ module Leftovers
35
35
  def name?(name)
36
36
  name = name.to_sym
37
37
 
38
- @name == name || Leftovers.each_or_self(@aliases).include?(name)
38
+ @name == name || @aliases.include?(name)
39
39
  end
40
40
 
41
41
  def to_ruby(value)
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leftovers
4
+ class ConfigLoader
5
+ class BoolSchema < Schema
6
+ class << self
7
+ def validate(node)
8
+ error(node, 'be true or false') if to_ruby(node).nil?
9
+ super
10
+ end
11
+
12
+ def to_ruby(node)
13
+ case node.to_ruby
14
+ when true, 'true' then true
15
+ when false, 'false' then false
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -31,13 +31,13 @@ module Leftovers
31
31
  yaml = { 'precompile' => [value.transform_keys(&:to_s).transform_values(&:to_s)] }
32
32
  .to_yaml.delete_prefix("---\n")
33
33
 
34
- Leftovers.warn(<<~MESSAGE)
34
+ ::Leftovers.warn(<<~MESSAGE)
35
35
  \e[33m`#{key}:` is deprecated\e[0m
36
36
  Replace with:
37
37
  \e[32m#{yaml}\e[0m
38
38
  MESSAGE
39
39
 
40
- write_hash[:precompile] = Leftovers.each_or_self(write_hash[:precompile]).to_a
40
+ write_hash[:precompile] = ::Leftovers.wrap_array(write_hash[:precompile])
41
41
  write_hash[:precompile] << value
42
42
  write_hash.delete(key)
43
43
  end
@@ -6,7 +6,7 @@ module Leftovers
6
6
  def initialize(schema, require_group: true, except: nil)
7
7
  @schema = schema
8
8
  @use_require_groups = require_group
9
- @except = Leftovers.each_or_self(except)
9
+ @except = Array(except)
10
10
  end
11
11
 
12
12
  def attributes
@@ -3,9 +3,9 @@
3
3
  module Leftovers
4
4
  class ConfigLoader
5
5
  class Node
6
- class_loader = Psych::ClassLoader::Restricted.new([], [])
7
- ToRuby = Psych::Visitors::ToRuby.new(
8
- Psych::ScalarScanner.new(class_loader),
6
+ class_loader = ::Psych::ClassLoader::Restricted.new([], [])
7
+ TO_RUBY_INSTANCE = ::Psych::Visitors::ToRuby.new(
8
+ ::Psych::ScalarScanner.new(class_loader),
9
9
  class_loader
10
10
  )
11
11
 
@@ -39,7 +39,7 @@ module Leftovers
39
39
  end
40
40
 
41
41
  def hash?
42
- node.is_a?(Psych::Nodes::Mapping)
42
+ node.is_a?(::Psych::Nodes::Mapping)
43
43
  end
44
44
 
45
45
  def location
@@ -69,7 +69,7 @@ module Leftovers
69
69
  end
70
70
 
71
71
  def to_ruby
72
- @to_ruby ||= ToRuby.accept(node)
72
+ @to_ruby ||= TO_RUBY_INSTANCE.accept(node)
73
73
  end
74
74
 
75
75
  def to_sym
@@ -77,7 +77,7 @@ module Leftovers
77
77
  end
78
78
 
79
79
  def string?
80
- to_ruby.is_a?(String)
80
+ to_ruby.is_a?(::String)
81
81
  end
82
82
 
83
83
  def scalar?
@@ -85,11 +85,11 @@ module Leftovers
85
85
  end
86
86
 
87
87
  def array?
88
- node.is_a?(Psych::Nodes::Sequence)
88
+ node.is_a?(::Psych::Nodes::Sequence)
89
89
  end
90
90
 
91
91
  def integer?
92
- to_ruby.is_a?(Integer)
92
+ to_ruby.is_a?(::Integer)
93
93
  end
94
94
 
95
95
  private
@@ -16,7 +16,7 @@ module Leftovers
16
16
 
17
17
  def validate_regexp(node)
18
18
  /#{node.to_ruby}/
19
- rescue RegexpError, ArgumentError => e
19
+ rescue ::RegexpError, ::ArgumentError => e
20
20
  error(node, "be a string with a valid ruby regexp (#{e.message})")
21
21
  else
22
22
  true
@@ -10,6 +10,7 @@ module Leftovers
10
10
  attribute :has_arguments, ValueOrArraySchema[HasArgumentSchema], aliases: :has_argument,
11
11
  require_group: :matcher
12
12
  attribute :has_receiver, ValueOrArraySchema[HasReceiverSchema], require_group: :matcher
13
+ attribute :has_block, BoolSchema, require_group: :matcher
13
14
  attribute :type, ValueOrArraySchema[ValueTypeSchema], require_group: :matcher
14
15
  attribute :privacy, ValueOrArraySchema[PrivacySchema], require_group: :matcher
15
16
  attribute :unless, ValueOrArraySchema[RulePatternSchema], require_group: :matcher
@@ -20,7 +20,7 @@ module Leftovers
20
20
 
21
21
  def ===(other) # leftovers:test_only
22
22
  # :nocov:
23
- if other.is_a?(Module)
23
+ if other.is_a?(::Module)
24
24
  self >= other
25
25
  else
26
26
  other.is_a?(self)
@@ -6,7 +6,7 @@ module Leftovers
6
6
  class << self
7
7
  def value(value, aliases: nil)
8
8
  values << value
9
- Leftovers.each_or_self(aliases) do |alias_name|
9
+ Array(aliases).each do |alias_name|
10
10
  self.aliases[alias_name] = value
11
11
  end
12
12
  end
@@ -13,7 +13,7 @@ module Leftovers
13
13
 
14
14
  def to_ruby(node)
15
15
  if node.array?
16
- Leftovers.unwrap_array(super)
16
+ ::Leftovers.unwrap_array(super)
17
17
  else
18
18
  value_schema.to_ruby(node)
19
19
  end
@@ -1,50 +1,10 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'yaml'
4
4
 
5
5
  module Leftovers
6
6
  class ConfigLoader
7
- autoload(:ArgumentlessTransformSchema, "#{__dir__}/config_loader/argumentless_transform_schema")
8
- autoload(:ArgumentPositionSchema, "#{__dir__}/config_loader/argument_position_schema")
9
- autoload(:ArraySchema, "#{__dir__}/config_loader/array_schema")
10
- autoload(:Attribute, "#{__dir__}/config_loader/attribute")
11
- autoload(:BuiltInPrecompilerSchema, "#{__dir__}/config_loader/built_in_precompiler_schema")
12
- autoload(:DocumentSchema, "#{__dir__}/config_loader/document_schema")
13
- autoload(:DynamicSchema, "#{__dir__}/config_loader/dynamic_schema")
14
- autoload(:HasArgumentSchema, "#{__dir__}/config_loader/has_argument_schema")
15
- autoload(:HasValueSchema, "#{__dir__}/config_loader/has_value_schema")
16
- autoload(:HasReceiverSchema, "#{__dir__}/config_loader/has_receiver_schema")
17
- autoload(:InheritSchemaAttributes, "#{__dir__}/config_loader/inherit_schema_attributes")
18
- autoload(:KeepTestOnlySchema, "#{__dir__}/config_loader/keep_test_only_schema")
19
- autoload(:KeywordArgumentSchema, "#{__dir__}/config_loader/keyword_argument_schema")
20
- autoload(:Node, "#{__dir__}/config_loader/node")
21
- autoload(:ObjectSchema, "#{__dir__}/config_loader/object_schema")
22
- autoload(:PrecompilerSchema, "#{__dir__}/config_loader/precompiler_schema")
23
- autoload(:PrecompileSchema, "#{__dir__}/config_loader/precompile_schema")
24
- autoload(:PrivacyProcessorSchema, "#{__dir__}/config_loader/privacy_processor_schema")
25
- autoload(:PrivacySchema, "#{__dir__}/config_loader/privacy_schema")
26
- autoload(:RegexpSchema, "#{__dir__}/config_loader/regexp_schema")
27
- autoload(:RequireSchema, "#{__dir__}/config_loader/require_schema")
28
- autoload(:RulePatternSchema, "#{__dir__}/config_loader/rule_pattern_schema")
29
- autoload(:ScalarArgumentSchema, "#{__dir__}/config_loader/scalar_argument_schema")
30
- autoload(:ScalarValueSchema, "#{__dir__}/config_loader/scalar_value_schema")
31
- autoload(:Schema, "#{__dir__}/config_loader/schema")
32
- autoload(:StringEnumSchema, "#{__dir__}/config_loader/string_enum_schema")
33
- autoload(:StringPatternSchema, "#{__dir__}/config_loader/string_pattern_schema")
34
- autoload(:StringSchema, "#{__dir__}/config_loader/string_schema")
35
- autoload(:StringValueProcessorSchema, "#{__dir__}/config_loader/string_value_processor_schema")
36
- autoload(:Suggester, "#{__dir__}/config_loader/suggester")
37
- autoload(:TransformSchema, "#{__dir__}/config_loader/transform_schema")
38
- autoload(:TrueSchema, "#{__dir__}/config_loader/true_schema")
39
- autoload(
40
- :ValueMatcherConditionSchema,
41
- "#{__dir__}/config_loader/value_matcher_condition_schema"
42
- )
43
- autoload(:ValueMatcherSchema, "#{__dir__}/config_loader/value_matcher_schema")
44
- autoload(:ValueOrArraySchema, "#{__dir__}/config_loader/value_or_array_schema")
45
- autoload(:ValueOrObjectSchema, "#{__dir__}/config_loader/value_or_object_schema")
46
- autoload(:ValueProcessorSchema, "#{__dir__}/config_loader/value_processor_schema")
47
- autoload(:ValueTypeSchema, "#{__dir__}/config_loader/value_type_schema")
7
+ include Autoloader
48
8
 
49
9
  def self.load(name, path: nil, content: nil)
50
10
  new(name, path: path, content: content).load
@@ -59,13 +19,13 @@ module Leftovers
59
19
  end
60
20
 
61
21
  def load
62
- document = ::Leftovers::ConfigLoader::Node.new(parse, file)
22
+ document = Node.new(parse, file)
63
23
  DocumentSchema.validate(document)
64
24
 
65
25
  all_errors = document.all_errors
66
26
  return DocumentSchema.to_ruby(document) if all_errors.empty?
67
27
 
68
- Leftovers.error(all_errors.join("\n"))
28
+ ::Leftovers.error(all_errors.join("\n"))
69
29
  end
70
30
 
71
31
  private
@@ -75,7 +35,7 @@ module Leftovers
75
35
  end
76
36
 
77
37
  def file
78
- @file ||= ::Leftovers::File.new(path)
38
+ @file ||= File.new(path)
79
39
  end
80
40
 
81
41
  def content
@@ -83,12 +43,12 @@ module Leftovers
83
43
  end
84
44
 
85
45
  def parse
86
- parsed = Psych.parse(content)
87
- parsed ||= Psych.parse('{}')
46
+ parsed = ::Psych.parse(content)
47
+ parsed ||= ::Psych.parse('{}')
88
48
  parsed.children.first
89
49
  rescue ::Psych::SyntaxError => e
90
50
  message = [e.problem, e.context].compact.join(' ')
91
- Leftovers.error "Config SyntaxError: #{file.relative_path}:#{e.line}:#{e.column} #{message}"
51
+ ::Leftovers.error "Config SyntaxError: #{file.relative_path}:#{e.line}:#{e.column} #{message}"
92
52
  end
93
53
  end
94
54
  end
@@ -34,12 +34,12 @@ module Leftovers
34
34
  @source_line[@location_column_range_end..-1].rstrip
35
35
  end
36
36
 
37
- def in_collection?
38
- Leftovers.collector.calls.include?(@name) || (@test && in_test_collection?)
37
+ def in_collection?(collection)
38
+ collection.calls.include?(@name) || (@test && in_test_collection?(collection))
39
39
  end
40
40
 
41
- def in_test_collection?
42
- Leftovers.collector.test_calls.include?(@name)
41
+ def in_test_collection?(collection)
42
+ collection.test_calls.include?(@name)
43
43
  end
44
44
  end
45
45
  end
@@ -12,12 +12,12 @@ module Leftovers
12
12
  end
13
13
 
14
14
  def add(node, name: node.name, loc: node.loc.name)
15
- @definitions_to_add[name] = ::Leftovers::DefinitionToAdd.new(node, name: name, location: loc)
15
+ @definitions_to_add[name] = DefinitionToAdd.new(node, name: name, location: loc)
16
16
  end
17
17
 
18
18
  def add_definition_set(definition_node_set)
19
19
  @definition_sets_to_add << definition_node_set.definitions.map do |definition_node|
20
- ::Leftovers::DefinitionToAdd.new(definition_node, location: definition_node.loc)
20
+ DefinitionToAdd.new(definition_node, location: definition_node.loc)
21
21
  end
22
22
  end
23
23
 
@@ -30,7 +30,7 @@ module Leftovers
30
30
  @definition_sets_to_add.map do |definition_set|
31
31
  next if definition_set.any? { |d| d.keep?(file_collector) }
32
32
 
33
- ::Leftovers::DefinitionSet.new(definition_set.map { |d| d.to_definition(file_collector) })
33
+ DefinitionSet.new(definition_set.map { |d| d.to_definition(file_collector) })
34
34
  end
35
35
  end
36
36
  end
@@ -1,7 +1,7 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
- class DefinitionNode < ::Leftovers::AST::Node
4
+ class DefinitionNode < AST::Node
5
5
  attr_reader :name, :path
6
6
  alias_method :to_sym, :name
7
7
 
@@ -1,4 +1,4 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  class DefinitionNodeSet
@@ -26,16 +26,16 @@ module Leftovers
26
26
  @definitions.first.highlighted_source(*args)
27
27
  end
28
28
 
29
- def in_collection?
30
- @definitions.any?(&:in_collection?)
29
+ def in_collection?(collection)
30
+ @definitions.any? { |d| d.in_collection?(collection) }
31
31
  end
32
32
 
33
33
  def test?
34
34
  @definitions.any?(&:test?)
35
35
  end
36
36
 
37
- def in_test_collection?
38
- @definitions.any?(&:in_test_collection?)
37
+ def in_test_collection?(collection)
38
+ @definitions.any? { |d| d.in_test_collection?(collection) }
39
39
  end
40
40
  end
41
41
  end
@@ -1,4 +1,4 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  class DefinitionToAdd
@@ -25,7 +25,7 @@ module Leftovers
25
25
  def to_definition(file_collector)
26
26
  return if keep?(file_collector)
27
27
 
28
- Leftovers::Definition.new(name, location: location, test: test?(file_collector))
28
+ Definition.new(name, location: location, test: test?(file_collector))
29
29
  end
30
30
  end
31
31
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leftovers
4
+ class Error < ::StandardError
5
+ end
6
+ end
@@ -3,11 +3,11 @@
3
3
  require 'pathname'
4
4
 
5
5
  module Leftovers
6
- class File < Pathname
6
+ class File < ::Pathname
7
7
  def relative_path
8
8
  @relative_path ||= begin
9
- relative_path_from(Leftovers.pwd)
10
- rescue ArgumentError
9
+ relative_path_from(::Leftovers.pwd)
10
+ rescue ::ArgumentError
11
11
  self
12
12
  end
13
13
  end
@@ -15,7 +15,7 @@ module Leftovers
15
15
  def test?
16
16
  return @test if defined?(@test)
17
17
 
18
- @test = Leftovers.config.test_paths === relative_path
18
+ @test = ::Leftovers.config.test_paths === relative_path
19
19
  end
20
20
 
21
21
  def ruby
@@ -1,21 +1,8 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  class FileCollector
5
5
  module CommentsProcessor
6
- METHOD_NAME_RE = /[[:alpha:]_][[:alnum:]_]*\b[?!=]?/.freeze
7
- NON_ALNUM_METHOD_NAME_RE = Regexp.union(%w{
8
- []= [] ** ~ +@ -@ * / % + - >> << &
9
- ^ | <=> <= >= < > === == != =~ !~ !
10
- }.map { |op| /#{Regexp.escape(op)}/ })
11
- CONSTANT_NAME_RE = /[[:upper:]][[:alnum:]_]*\b/.freeze
12
- NAME_RE = Regexp.union(METHOD_NAME_RE, NON_ALNUM_METHOD_NAME_RE, CONSTANT_NAME_RE)
13
- NAME_LIST_RE = /#{NAME_RE}(?:[, :]+#{NAME_RE})*/.freeze
14
- LEFTOVERS_CALL_RE = /\bleftovers:call(?:s|e(?:d|rs?))? (#{NAME_LIST_RE})/.freeze
15
- LEFTOVERS_ALLOW_RE = /\bleftovers:(?:keeps?|skip(?:s|ped|)|allow(?:s|ed|))\b/.freeze
16
- LEFTOVERS_TEST_RE = /\bleftovers:(?:for_tests?|tests?|testing|test_only)\b/.freeze
17
- LEFTOVERS_DYNAMIC_RE = /\bleftovers:dynamic[: ](#{NAME_LIST_RE})/.freeze
18
-
19
6
  class << self
20
7
  def process(comments, collector)
21
8
  comments.each do |comment|
@@ -26,27 +13,45 @@ module Leftovers
26
13
  end
27
14
  end
28
15
 
16
+ private
17
+
18
+ method_name_re = /[[:alpha:]_][[:alnum:]_]*\b[?!=]?/.freeze
19
+ non_alnum_method_name_re = ::Regexp.union(%w{
20
+ []= [] ** ~ +@ -@ * / % + - >> << &
21
+ ^ | <=> <= >= < > === == != =~ !~ !
22
+ }.map { |op| /#{::Regexp.escape(op)}/ })
23
+ constant_name_re = /[[:upper:]][[:alnum:]_]*\b/.freeze
24
+ NAME_RE = ::Regexp.union(method_name_re, non_alnum_method_name_re, constant_name_re)
25
+ name_list_re = /#{NAME_RE}(?:[, :]+#{NAME_RE})*/o.freeze
26
+
27
+ CALL_RE = /\bleftovers:call(?:s|e(?:d|rs?))? (#{name_list_re})/.freeze
28
+ ALLOW_RE = /\bleftovers:(?:keeps?|skip(?:s|ped|)|allow(?:s|ed|))\b/.freeze
29
+ TEST_ONLY_RE = /\bleftovers:(?:for_tests?|tests?|testing|test_only)\b/.freeze
30
+ DYNAMIC_RE = /\bleftovers:dynamic[: ](#{name_list_re})/.freeze
31
+
32
+ private_constant :NAME_RE, :CALL_RE, :ALLOW_RE, :TEST_ONLY_RE, :DYNAMIC_RE
33
+
29
34
  def process_leftovers_keep_comment(comment, collector)
30
- return unless comment.text.match?(LEFTOVERS_ALLOW_RE)
35
+ return unless comment.text.match?(ALLOW_RE)
31
36
 
32
37
  collector.allow_lines << comment.loc.line
33
38
  end
34
39
 
35
40
  def process_leftovers_test_comment(comment, collector)
36
- return unless comment.text.match?(LEFTOVERS_TEST_RE)
41
+ return unless comment.text.match?(TEST_ONLY_RE)
37
42
 
38
43
  collector.test_lines << comment.loc.line
39
44
  end
40
45
 
41
46
  def process_leftovers_dynamic_comment(comment, collector)
42
- match = comment.text.match(LEFTOVERS_DYNAMIC_RE)
47
+ match = comment.text.match(DYNAMIC_RE)
43
48
  return unless match
44
49
 
45
50
  collector.dynamic_lines[comment.loc.line] = match[1].scan(NAME_RE)
46
51
  end
47
52
 
48
53
  def process_leftovers_call_comment(comment, collector)
49
- match = comment.text.match(LEFTOVERS_CALL_RE)
54
+ match = comment.text.match(CALL_RE)
50
55
  return unless match
51
56
 
52
57
  match[1].scan(NAME_RE).each { |s| collector.calls << s.to_sym }