leftovers 0.11.0 → 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 +11 -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 +9 -1
  55. data/lib/leftovers/file_collector.rb +15 -17
  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
@@ -1,20 +1,7 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  module ProcessorBuilders
5
- autoload(:Action, "#{__dir__}/processor_builders/action")
6
- autoload(:AddPrefix, "#{__dir__}/processor_builders/add_prefix")
7
- autoload(:AddSuffix, "#{__dir__}/processor_builders/add_suffix")
8
- autoload(:Argument, "#{__dir__}/processor_builders/argument")
9
- autoload(:Dynamic, "#{__dir__}/processor_builders/dynamic")
10
- autoload(:Each, "#{__dir__}/processor_builders/each")
11
- autoload(:Itself, "#{__dir__}/processor_builders/itself")
12
- autoload(:Keyword, "#{__dir__}/processor_builders/keyword")
13
- autoload(:KeywordArgument, "#{__dir__}/processor_builders/keyword_argument")
14
- autoload(:Receiver, "#{__dir__}/processor_builders/receiver")
15
- autoload(:TransformChain, "#{__dir__}/processor_builders/transform_chain")
16
- autoload(:TransformSet, "#{__dir__}/processor_builders/transform_set")
17
- autoload(:Transform, "#{__dir__}/processor_builders/transform")
18
- autoload(:Value, "#{__dir__}/processor_builders/value")
5
+ include Autoloader
19
6
  end
20
7
  end
@@ -1,4 +1,4 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  module Processors
@@ -7,7 +7,7 @@ module Leftovers
7
7
  return unless str
8
8
  return if str.empty?
9
9
 
10
- acc.add_definition_node Leftovers::DefinitionNode.new(current_node, name: str.to_sym)
10
+ acc.add_definition_node DefinitionNode.new(current_node, name: str.to_sym)
11
11
  end
12
12
 
13
13
  freeze
@@ -15,9 +15,9 @@ module Leftovers
15
15
  return unless str
16
16
 
17
17
  @then_processor.process(str.camelize, current_node, matched_node, acc)
18
- rescue NoMethodError
19
- Leftovers.error <<~MESSAGE
20
- Tried using the String#camelize method, but the activesupport gem was not available and/or not required
18
+ rescue ::NoMethodError
19
+ ::Leftovers.error <<~MESSAGE
20
+ Tried using the ::String#camelize method, but the activesupport gem was not available and/or not required
21
21
  `gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
22
22
  MESSAGE
23
23
  end
@@ -15,9 +15,9 @@ module Leftovers
15
15
  return unless str
16
16
 
17
17
  @then_processor.process(str.deconstantize, current_node, matched_node, acc)
18
- rescue NoMethodError
19
- Leftovers.error <<~MESSAGE
20
- Tried using the String#deconstantize method, but the activesupport gem was not available and/or not required
18
+ rescue ::NoMethodError
19
+ ::Leftovers.error <<~MESSAGE
20
+ Tried using the ::String#deconstantize method, but the activesupport gem was not available and/or not required
21
21
  `gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
22
22
  MESSAGE
23
23
  end
@@ -15,9 +15,9 @@ module Leftovers
15
15
  return unless str
16
16
 
17
17
  @then_processor.process(str.demodulize, current_node, matched_node, acc)
18
- rescue NoMethodError
19
- Leftovers.error <<~MESSAGE
20
- Tried using the String#demodulize method, but the activesupport gem was not available and/or not required
18
+ rescue ::NoMethodError
19
+ ::Leftovers.error <<~MESSAGE
20
+ Tried using the ::String#demodulize method, but the activesupport gem was not available and/or not required
21
21
  `gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
22
22
  MESSAGE
23
23
  end
@@ -1,4 +1,4 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  module Processors
@@ -14,7 +14,7 @@ module Leftovers
14
14
  end
15
15
 
16
16
  def process(str, current_node, matched_node, acc)
17
- set = ::Leftovers::DefinitionNodeSet.new
17
+ set = DefinitionNodeSet.new
18
18
 
19
19
  @processors.each do |processor|
20
20
  processor.process(str, current_node, matched_node, set)
@@ -1,4 +1,4 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  module Processors
@@ -15,9 +15,9 @@ module Leftovers
15
15
  return unless str
16
16
 
17
17
  @then_processor.process(str.parameterize, current_node, matched_node, acc)
18
- rescue NoMethodError
19
- Leftovers.error <<~MESSAGE
20
- Tried using the String#parameterize method, but the activesupport gem was not available and/or not required
18
+ rescue ::NoMethodError
19
+ ::Leftovers.error <<~MESSAGE
20
+ Tried using the ::String#parameterize method, but the activesupport gem was not available and/or not required
21
21
  `gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
22
22
  MESSAGE
23
23
  end
@@ -1,4 +1,4 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  module Processors
@@ -15,9 +15,9 @@ module Leftovers
15
15
  return unless str
16
16
 
17
17
  @then_processor.process(str.pluralize, current_node, matched_node, acc)
18
- rescue NoMethodError
19
- Leftovers.error <<~MESSAGE
20
- Tried using the String#pluralize method, but the activesupport gem was not available and/or not required
18
+ rescue ::NoMethodError
19
+ ::Leftovers.error <<~MESSAGE
20
+ Tried using the ::String#pluralize method, but the activesupport gem was not available and/or not required
21
21
  `gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
22
22
  MESSAGE
23
23
  end
@@ -1,4 +1,4 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  module Processors
@@ -1,4 +1,4 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  module Processors
@@ -15,9 +15,9 @@ module Leftovers
15
15
  return unless str
16
16
 
17
17
  @then_processor.process(str.singularize, current_node, matched_node, acc)
18
- rescue NoMethodError
19
- Leftovers.error <<~MESSAGE
20
- Tried using the String#singularize method, but the activesupport gem was not available and/or not required
18
+ rescue ::NoMethodError
19
+ ::Leftovers.error <<~MESSAGE
20
+ Tried using the ::String#singularize method, but the activesupport gem was not available and/or not required
21
21
  `gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
22
22
  MESSAGE
23
23
  end
@@ -15,9 +15,9 @@ module Leftovers
15
15
  return unless str
16
16
 
17
17
  @then_processor.process(str.titleize, current_node, matched_node, acc)
18
- rescue NoMethodError
19
- Leftovers.error <<~MESSAGE
20
- Tried using the String#titleize method, but the activesupport gem was not available and/or not required
18
+ rescue ::NoMethodError
19
+ ::Leftovers.error <<~MESSAGE
20
+ Tried using the ::String#titleize method, but the activesupport gem was not available and/or not required
21
21
  `gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
22
22
  MESSAGE
23
23
  end
@@ -15,9 +15,9 @@ module Leftovers
15
15
  return unless str
16
16
 
17
17
  @then_processor.process(str.underscore, current_node, matched_node, acc)
18
- rescue NoMethodError
19
- Leftovers.error <<~MESSAGE
20
- Tried using the String#underscore method, but the activesupport gem was not available and/or not required
18
+ rescue ::NoMethodError
19
+ ::Leftovers.error <<~MESSAGE
20
+ Tried using the ::String#underscore method, but the activesupport gem was not available and/or not required
21
21
  `gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
22
22
  MESSAGE
23
23
  end
@@ -1,49 +1,7 @@
1
- # frozen-string-literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
4
  module Processors
5
- autoload(:AddCall, "#{__dir__}/processors/add_call")
6
- autoload(:AddDefinitionNode, "#{__dir__}/processors/add_definition_node")
7
- autoload(:AddDynamicPrefix, "#{__dir__}/processors/add_dynamic_prefix")
8
- autoload(:AddDynamicSuffix, "#{__dir__}/processors/add_dynamic_suffix")
9
- autoload(:AddPrefix, "#{__dir__}/processors/add_prefix")
10
- autoload(:AddSuffix, "#{__dir__}/processors/add_suffix")
11
- autoload(:AppendSym, "#{__dir__}/processors/append_sym")
12
- autoload(:Camelize, "#{__dir__}/processors/camelize")
13
- autoload(:Capitalize, "#{__dir__}/processors/capitalize")
14
- autoload(:Deconstantize, "#{__dir__}/processors/deconstantize")
15
- autoload(:DeleteAfter, "#{__dir__}/processors/delete_after")
16
- autoload(:DeleteAfterLast, "#{__dir__}/processors/delete_after_last")
17
- autoload(:DeleteBefore, "#{__dir__}/processors/delete_before")
18
- autoload(:DeleteBeforeLast, "#{__dir__}/processors/delete_before_last")
19
- autoload(:DeletePrefix, "#{__dir__}/processors/delete_prefix")
20
- autoload(:DeleteSuffix, "#{__dir__}/processors/delete_suffix")
21
- autoload(:Demodulize, "#{__dir__}/processors/demodulize")
22
- autoload(:Downcase, "#{__dir__}/processors/downcase")
23
- autoload(:Each, "#{__dir__}/processors/each")
24
- autoload(:EachForDefinitionSet, "#{__dir__}/processors/each_for_definition_set")
25
- autoload(:EachKeyword, "#{__dir__}/processors/each_keyword")
26
- autoload(:EachKeywordArgument, "#{__dir__}/processors/each_keyword_argument")
27
- autoload(:EachPositionalArgument, "#{__dir__}/processors/each_positional_argument")
28
- autoload(:EachPositionalArgumentFrom, "#{__dir__}/processors/each_positional_argument_from")
29
- autoload(:Eval, "#{__dir__}/processors/eval")
30
- autoload(:Itself, "#{__dir__}/processors/itself")
31
- autoload(:KeywordArgument, "#{__dir__}/processors/keyword_argument")
32
- autoload(:MatchCurrentNode, "#{__dir__}/processors/match_current_node")
33
- autoload(:MatchMatchedNode, "#{__dir__}/processors/match_matched_node")
34
- autoload(:Parameterize, "#{__dir__}/processors/parameterize")
35
- autoload(:Placeholder, "#{__dir__}/processors/placeholder")
36
- autoload(:Pluralize, "#{__dir__}/processors/pluralize")
37
- autoload(:PositionalArgument, "#{__dir__}/processors/positional_argument")
38
- autoload(:Receiver, "#{__dir__}/processors/receiver")
39
- autoload(:ReplaceValue, "#{__dir__}/processors/replace_value")
40
- autoload(:SetDefaultPrivacy, "#{__dir__}/processors/set_default_privacy")
41
- autoload(:SetPrivacy, "#{__dir__}/processors/set_privacy")
42
- autoload(:Singularize, "#{__dir__}/processors/singularize")
43
- autoload(:Split, "#{__dir__}/processors/split")
44
- autoload(:Swapcase, "#{__dir__}/processors/swapcase")
45
- autoload(:Titleize, "#{__dir__}/processors/titleize")
46
- autoload(:Underscore, "#{__dir__}/processors/underscore")
47
- autoload(:Upcase, "#{__dir__}/processors/upcase")
5
+ include Autoloader
48
6
  end
49
7
  end
@@ -27,7 +27,7 @@ module Leftovers
27
27
  def escaped_argv(argv = @default_argv)
28
28
  return if argv.empty?
29
29
 
30
- Shellwords.shelljoin(argv)
30
+ ::Shellwords.shelljoin(argv)
31
31
  end
32
32
 
33
33
  def describe_task
@@ -49,7 +49,7 @@ module Leftovers
49
49
  end
50
50
 
51
51
  def run(argv)
52
- exitstatus = Leftovers::CLI.new(argv: argv).run
52
+ exitstatus = CLI.new(argv: argv).run
53
53
 
54
54
  exit exitstatus unless exitstatus == 0
55
55
  end
@@ -1,63 +1,65 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
- class Reporter
5
- def prepare; end
4
+ module Reporter
5
+ class << self
6
+ def prepare; end
6
7
 
7
- def report(only_test:, none:)
8
- report_list('Only directly called in tests:', only_test)
9
- report_list('Not directly called at all:', none)
10
- report_instructions
8
+ def report(collection)
9
+ report_list('Only directly called in tests:', collection.with_tests)
10
+ report_list('Not directly called at all:', collection.without_tests)
11
+ report_instructions
11
12
 
12
- 1
13
- end
13
+ 1
14
+ end
14
15
 
15
- def report_success
16
- puts green('Everything is used')
16
+ def report_success
17
+ puts green('Everything is used')
17
18
 
18
- 0
19
- end
19
+ 0
20
+ end
20
21
 
21
- private
22
+ private
22
23
 
23
- def report_instructions
24
- puts <<~HELP
24
+ def report_instructions
25
+ puts <<~HELP
25
26
 
26
- how to resolve: #{green Leftovers.resolution_instructions_link}
27
- HELP
28
- end
27
+ how to resolve: #{green ::Leftovers.resolution_instructions_link}
28
+ HELP
29
+ end
29
30
 
30
- def report_list(title, list)
31
- return if list.empty?
31
+ def report_list(title, list)
32
+ return if list.empty?
32
33
 
33
- puts red(title)
34
- list.each { |d| print_definition(d) }
35
- end
34
+ puts red(title)
35
+ list.each { |d| print_definition(d) }
36
+ end
36
37
 
37
- def print_definition(definition)
38
- puts "#{aqua definition.location_s} " \
39
- "#{definition} " \
40
- "#{grey definition.highlighted_source("\e[33m", "\e[0;2m")}"
41
- end
38
+ def print_definition(definition)
39
+ puts "#{aqua definition.location_s} " \
40
+ "#{definition} " \
41
+ "#{grey definition.highlighted_source("\e[33m", "\e[0;2m")}"
42
+ end
42
43
 
43
- def puts(string)
44
- Leftovers.puts(string)
45
- end
44
+ def puts(string)
45
+ ::Leftovers.puts(string)
46
+ end
46
47
 
47
- def red(string)
48
- "\e[31m#{string}\e[0m"
49
- end
48
+ def red(string)
49
+ "\e[31m#{string}\e[0m"
50
+ end
50
51
 
51
- def green(string)
52
- "\e[32m#{string}\e[0m"
53
- end
52
+ def green(string)
53
+ "\e[32m#{string}\e[0m"
54
+ end
54
55
 
55
- def aqua(string)
56
- "\e[36m#{string}\e[0m"
57
- end
56
+ def aqua(string)
57
+ "\e[36m#{string}\e[0m"
58
+ end
58
59
 
59
- def grey(string)
60
- "\e[2m#{string}\e[0m"
60
+ def grey(string)
61
+ "\e[2m#{string}\e[0m"
62
+ end
61
63
  end
62
64
  end
63
65
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leftovers
4
+ class Runner
5
+ attr_writer :reporter
6
+
7
+ def run
8
+ reporter.prepare
9
+ return reporter.report_success if collection.empty?
10
+
11
+ reporter.report(collection)
12
+ end
13
+
14
+ def parallel=(value)
15
+ collector.parallel = value
16
+ end
17
+
18
+ def progress=(value)
19
+ collector.progress = value
20
+ end
21
+
22
+ def collection
23
+ @collection ||= begin
24
+ collector.collect
25
+
26
+ collector.collection
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def reporter
33
+ @reporter ||= Reporter
34
+ end
35
+
36
+ def collector
37
+ @collector ||= Collector.new
38
+ end
39
+ end
40
+ end
@@ -3,100 +3,102 @@
3
3
  require 'pathname'
4
4
 
5
5
  module Leftovers
6
- class TodoReporter
7
- def prepare
8
- return unless path.exist?
9
-
10
- puts "Removing previous #{path.basename} file"
11
- puts ''
12
- path.delete
13
- end
14
-
15
- def report(only_test:, none:)
16
- path.write(generate_file_body(only_test, none))
17
- report_instructions
18
-
19
- 0
20
- end
21
-
22
- def report_success
23
- puts "No #{path.basename} file generated, everything is used"
24
-
25
- 0
26
- end
27
-
28
- private
29
-
30
- def report_instructions
31
- puts <<~MESSAGE
32
- generated #{path.basename}.
33
- running leftovers again will read this file and not alert you to any unused items mentioned in it.
34
-
35
- commit this file so you/your team can gradually address these items while still having leftovers alert you to any newly unused items.
36
- MESSAGE
37
- end
38
-
39
- def path
40
- Leftovers.pwd.join('.leftovers_todo.yml')
41
- end
42
-
43
- def generate_file_body(only_test, none)
44
- <<~YML.chomp
45
- #{generation_message.chomp}
46
- #
47
- #{resolution_instructions}
48
- #{todo_data(only_test, none).chomp}
49
- YML
50
- end
51
-
52
- def generation_message
53
- <<~YML
54
- # This file was generated by `leftovers --write-todo`
55
- # Generated at: #{Time.now.utc.strftime('%F %T')} UTC
56
- YML
57
- end
58
-
59
- def resolution_instructions
60
- <<~YML
61
- # for instructions on how to address these
62
- # see #{Leftovers.resolution_instructions_link}
63
- YML
64
- end
65
-
66
- def todo_data(only_test, none)
67
- [
68
- list_data(
69
- :test_only, 'Only directly called in tests', only_test
70
- ),
71
- list_data(
72
- :keep, 'Not directly called at all', none
73
- )
74
- ].compact.join
75
- end
76
-
77
- def list_data(key, title, list)
78
- return if list.empty?
79
-
80
- <<~YML
81
- #{key}:
82
- # #{title}:
83
- #{print_definition_list(list)}
84
-
85
- YML
86
- end
87
-
88
- def print_definition_list(definition_list)
89
- definition_list.map { |definition| print_definition(definition) }.sort.join("\n")
90
- end
91
-
92
- def print_definition(definition)
93
- return print_definition_list(definition.definitions) if definition.is_a?(DefinitionSet)
94
-
95
- " - #{definition.to_s.inspect} # #{definition.location_s} #{definition.source_line.strip}"
96
- end
97
-
98
- def puts(string)
99
- Leftovers.puts(string)
6
+ module TodoReporter
7
+ class << self
8
+ def prepare
9
+ return unless path.exist?
10
+
11
+ puts "Removing previous #{path.basename} file"
12
+ puts ''
13
+ path.delete
14
+ end
15
+
16
+ def report(collection)
17
+ path.write(generate_file_body(collection))
18
+ report_instructions
19
+
20
+ 0
21
+ end
22
+
23
+ def report_success
24
+ puts "No #{path.basename} file generated, everything is used"
25
+
26
+ 0
27
+ end
28
+
29
+ private
30
+
31
+ def report_instructions
32
+ puts <<~MESSAGE
33
+ generated #{path.basename}.
34
+ running leftovers again will read this file and not alert you to any unused items mentioned in it.
35
+
36
+ commit this file so you/your team can gradually address these items while still having leftovers alert you to any newly unused items.
37
+ MESSAGE
38
+ end
39
+
40
+ def path
41
+ ::Leftovers.pwd.join('.leftovers_todo.yml')
42
+ end
43
+
44
+ def generate_file_body(collection)
45
+ <<~YML.chomp
46
+ #{generation_message.chomp}
47
+ #
48
+ #{resolution_instructions}
49
+ #{todo_data(collection).chomp}
50
+ YML
51
+ end
52
+
53
+ def generation_message
54
+ <<~YML
55
+ # This file was generated by `leftovers --write-todo`
56
+ # Generated at: #{Time.now.utc.strftime('%F %T')} UTC
57
+ YML
58
+ end
59
+
60
+ def resolution_instructions
61
+ <<~YML
62
+ # for instructions on how to address these
63
+ # see #{::Leftovers.resolution_instructions_link}
64
+ YML
65
+ end
66
+
67
+ def todo_data(collection)
68
+ [
69
+ list_data(
70
+ :test_only, 'Only directly called in tests', collection.with_tests
71
+ ),
72
+ list_data(
73
+ :keep, 'Not directly called at all', collection.without_tests
74
+ )
75
+ ].compact.join
76
+ end
77
+
78
+ def list_data(key, title, list)
79
+ return if list.empty?
80
+
81
+ <<~YML
82
+ #{key}:
83
+ # #{title}:
84
+ #{print_definition_list(list)}
85
+
86
+ YML
87
+ end
88
+
89
+ def print_definition_list(definition_list)
90
+ definition_list.map { |definition| print_definition(definition) }.sort.join("\n")
91
+ end
92
+
93
+ def print_definition(definition)
94
+ return print_definition_list(definition.definitions) if definition.is_a?(DefinitionSet)
95
+
96
+ " - #{definition.to_s.inspect} # #{definition.location_s} #{definition.source_line.strip}"
97
+ end
98
+
99
+ def puts(string)
100
+ ::Leftovers.puts(string)
101
+ end
100
102
  end
101
103
  end
102
104
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nocov:
4
+ module Leftovers
5
+ class UnexpectedCase < Error
6
+ end
7
+ end
8
+ # :nocov:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leftovers
4
- VERSION = '0.11.0'
4
+ VERSION = '0.11.2'
5
5
  end