leftovers 0.11.1 → 0.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +1 -0
- data/docs/Configuration.md +7 -0
- data/exe/leftovers +3 -1
- data/leftovers.gemspec +3 -4
- data/lib/config/activesupport.yml +1 -1
- data/lib/config/rspec.yml +21 -0
- data/lib/leftovers/ast/array_node.rb +2 -2
- data/lib/leftovers/ast/block_node.rb +1 -1
- data/lib/leftovers/ast/builder.rb +19 -18
- data/lib/leftovers/ast/casgn_node.rb +2 -2
- data/lib/leftovers/ast/const_node.rb +1 -1
- data/lib/leftovers/ast/def_node.rb +1 -1
- data/lib/leftovers/ast/defs_node.rb +1 -1
- data/lib/leftovers/ast/false_node.rb +1 -1
- data/lib/leftovers/ast/hash_node.rb +2 -2
- data/lib/leftovers/ast/module_node.rb +1 -1
- data/lib/leftovers/ast/nil_node.rb +1 -1
- data/lib/leftovers/ast/node.rb +13 -1
- data/lib/leftovers/ast/numeric_node.rb +1 -1
- data/lib/leftovers/ast/send_node.rb +16 -3
- data/lib/leftovers/ast/str_node.rb +1 -1
- data/lib/leftovers/ast/sym_node.rb +1 -1
- data/lib/leftovers/ast/true_node.rb +1 -1
- data/lib/leftovers/ast/var_node.rb +1 -1
- data/lib/leftovers/ast/vasgn_node.rb +2 -2
- data/lib/leftovers/ast.rb +2 -21
- data/lib/leftovers/autoloader.rb +36 -0
- data/lib/leftovers/cli.rb +58 -42
- data/lib/leftovers/collection.rb +66 -0
- data/lib/leftovers/collector.rb +17 -27
- data/lib/leftovers/config.rb +17 -5
- data/lib/leftovers/config_loader/attribute.rb +2 -2
- data/lib/leftovers/config_loader/bool_schema.rb +21 -0
- data/lib/leftovers/config_loader/document_schema.rb +2 -2
- data/lib/leftovers/config_loader/inherit_schema_attributes.rb +1 -1
- data/lib/leftovers/config_loader/node.rb +8 -8
- data/lib/leftovers/config_loader/regexp_schema.rb +1 -1
- data/lib/leftovers/config_loader/rule_pattern_schema.rb +1 -0
- data/lib/leftovers/config_loader/schema.rb +1 -1
- data/lib/leftovers/config_loader/string_enum_schema.rb +1 -1
- data/lib/leftovers/config_loader/value_or_array_schema.rb +1 -1
- data/lib/leftovers/config_loader.rb +8 -48
- data/lib/leftovers/definition.rb +4 -4
- data/lib/leftovers/definition_collection.rb +3 -3
- data/lib/leftovers/definition_node.rb +2 -2
- data/lib/leftovers/definition_node_set.rb +1 -1
- data/lib/leftovers/definition_set.rb +4 -4
- data/lib/leftovers/definition_to_add.rb +2 -2
- data/lib/leftovers/error.rb +6 -0
- data/lib/leftovers/file.rb +4 -4
- data/lib/leftovers/file_collector/comments_processor.rb +23 -18
- data/lib/leftovers/file_collector/node_processor.rb +8 -1
- data/lib/leftovers/file_collector.rb +12 -15
- data/lib/leftovers/file_list.rb +4 -6
- data/lib/leftovers/matcher_builders/and.rb +5 -5
- data/lib/leftovers/matcher_builders/document.rb +1 -3
- data/lib/leftovers/matcher_builders/name.rb +4 -7
- data/lib/leftovers/matcher_builders/node.rb +21 -35
- data/lib/leftovers/matcher_builders/node_has_argument.rb +17 -29
- data/lib/leftovers/matcher_builders/node_has_block.rb +17 -0
- data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +7 -9
- data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +10 -10
- data/lib/leftovers/matcher_builders/node_has_receiver.rb +6 -8
- data/lib/leftovers/matcher_builders/node_name.rb +3 -5
- data/lib/leftovers/matcher_builders/node_pair_key.rb +4 -4
- data/lib/leftovers/matcher_builders/node_pair_value.rb +4 -4
- data/lib/leftovers/matcher_builders/node_path.rb +3 -4
- data/lib/leftovers/matcher_builders/node_privacy.rb +3 -3
- data/lib/leftovers/matcher_builders/node_type.rb +13 -14
- data/lib/leftovers/matcher_builders/node_value.rb +18 -31
- data/lib/leftovers/matcher_builders/or.rb +10 -10
- data/lib/leftovers/matcher_builders/path.rb +3 -3
- data/lib/leftovers/matcher_builders/string_pattern.rb +2 -0
- data/lib/leftovers/matcher_builders/unless.rb +1 -3
- data/lib/leftovers/matcher_builders.rb +2 -22
- data/lib/leftovers/matchers/node_has_block.rb +13 -0
- data/lib/leftovers/matchers/node_scalar_value.rb +1 -1
- data/lib/leftovers/matchers.rb +2 -27
- data/lib/leftovers/merged_config.rb +16 -17
- data/lib/leftovers/parser.rb +1 -1
- data/lib/leftovers/precompile_error.rb +31 -0
- data/lib/leftovers/precompilers/haml.rb +23 -3
- data/lib/leftovers/precompilers/json.rb +1 -1
- data/lib/leftovers/precompilers/precompiler.rb +3 -3
- data/lib/leftovers/precompilers/slim.rb +1 -1
- data/lib/leftovers/precompilers/yaml/builder.rb +62 -0
- data/lib/leftovers/precompilers/yaml.rb +3 -56
- data/lib/leftovers/precompilers.rb +11 -16
- data/lib/leftovers/processor_builders/action.rb +15 -19
- data/lib/leftovers/processor_builders/add_prefix.rb +4 -6
- data/lib/leftovers/processor_builders/add_suffix.rb +4 -6
- data/lib/leftovers/processor_builders/argument.rb +10 -15
- data/lib/leftovers/processor_builders/dynamic.rb +12 -30
- data/lib/leftovers/processor_builders/each.rb +63 -76
- data/lib/leftovers/processor_builders/each_for_definition_set.rb +15 -0
- data/lib/leftovers/processor_builders/itself.rb +2 -4
- data/lib/leftovers/processor_builders/keyword.rb +4 -4
- data/lib/leftovers/processor_builders/keyword_argument.rb +4 -4
- data/lib/leftovers/processor_builders/receiver.rb +2 -4
- data/lib/leftovers/processor_builders/transform.rb +26 -49
- data/lib/leftovers/processor_builders/transform_chain.rb +4 -7
- data/lib/leftovers/processor_builders/transform_set.rb +6 -7
- data/lib/leftovers/processor_builders/value.rb +2 -2
- data/lib/leftovers/processor_builders.rb +2 -15
- data/lib/leftovers/processors/add_definition_node.rb +2 -2
- data/lib/leftovers/processors/camelize.rb +3 -3
- data/lib/leftovers/processors/deconstantize.rb +3 -3
- data/lib/leftovers/processors/demodulize.rb +3 -3
- data/lib/leftovers/processors/each_for_definition_set.rb +2 -2
- data/lib/leftovers/processors/eval.rb +1 -1
- data/lib/leftovers/processors/parameterize.rb +3 -3
- data/lib/leftovers/processors/placeholder.rb +1 -1
- data/lib/leftovers/processors/pluralize.rb +3 -3
- data/lib/leftovers/processors/set_default_privacy.rb +1 -1
- data/lib/leftovers/processors/set_privacy.rb +1 -1
- data/lib/leftovers/processors/singularize.rb +3 -3
- data/lib/leftovers/processors/titleize.rb +3 -3
- data/lib/leftovers/processors/underscore.rb +3 -3
- data/lib/leftovers/processors.rb +2 -44
- data/lib/leftovers/rake_task.rb +2 -2
- data/lib/leftovers/reporter.rb +44 -42
- data/lib/leftovers/runner.rb +40 -0
- data/lib/leftovers/todo_reporter.rb +96 -94
- data/lib/leftovers/unexpected_case.rb +8 -0
- data/lib/leftovers/version.rb +1 -1
- data/lib/leftovers.rb +17 -110
- metadata +13 -17
- data/lib/leftovers/matcher_builders/and_not.rb +0 -16
@@ -1,20 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Leftovers
|
4
4
|
module ProcessorBuilders
|
5
|
-
|
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
|
-
#
|
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
|
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
|
-
#
|
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 =
|
17
|
+
set = DefinitionNodeSet.new
|
18
18
|
|
19
19
|
@processors.each do |processor|
|
20
20
|
processor.process(str, current_node, matched_node, set)
|
@@ -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
|
@@ -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
|
@@ -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
|
data/lib/leftovers/processors.rb
CHANGED
@@ -1,49 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Leftovers
|
4
4
|
module Processors
|
5
|
-
|
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
|
data/lib/leftovers/rake_task.rb
CHANGED
@@ -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 =
|
52
|
+
exitstatus = CLI.new(argv: argv).run
|
53
53
|
|
54
54
|
exit exitstatus unless exitstatus == 0
|
55
55
|
end
|
data/lib/leftovers/reporter.rb
CHANGED
@@ -1,63 +1,65 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Leftovers
|
4
|
-
|
5
|
-
|
4
|
+
module Reporter
|
5
|
+
class << self
|
6
|
+
def prepare; end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
13
|
-
|
13
|
+
1
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
def report_success
|
17
|
+
puts green('Everything is used')
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
0
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
+
private
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
def report_instructions
|
25
|
+
puts <<~HELP
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
how to resolve: #{green ::Leftovers.resolution_instructions_link}
|
28
|
+
HELP
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
def report_list(title, list)
|
32
|
+
return if list.empty?
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
puts red(title)
|
35
|
+
list.each { |d| print_definition(d) }
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
44
|
+
def puts(string)
|
45
|
+
::Leftovers.puts(string)
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
def red(string)
|
49
|
+
"\e[31m#{string}\e[0m"
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
def green(string)
|
53
|
+
"\e[32m#{string}\e[0m"
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
def aqua(string)
|
57
|
+
"\e[36m#{string}\e[0m"
|
58
|
+
end
|
58
59
|
|
59
|
-
|
60
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
data/lib/leftovers/version.rb
CHANGED