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
data/lib/leftovers.rb CHANGED
@@ -1,118 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'parser'
4
- require 'parser/current' # to get the error message early and once.
5
-
6
- module Leftovers # rubocop:disable Metrics/ModuleLength
7
- class Error < ::StandardError; end
8
- class UnexpectedCase < Error; end
9
-
10
- class PrecompileError < Error
11
- attr_reader :line, :column
12
-
13
- def initialize(message, line: nil, column: nil)
14
- @line = line
15
- @column = column
16
- super(message)
17
- end
18
-
19
- def warn(path:)
20
- line_column = ":#{line}#{":#{column}" if column}" if line
21
- klass = cause ? cause.class : self.class
22
-
23
- Leftovers.warn "#{klass}: #{path}#{line_column} #{message}"
24
- end
25
- end
26
-
27
- autoload(:AST, "#{__dir__}/leftovers/ast")
28
- autoload(:CLI, "#{__dir__}/leftovers/cli")
29
- autoload(:Collector, "#{__dir__}/leftovers/collector")
30
- autoload(:ComparableInstance, "#{__dir__}/leftovers/comparable_instance")
31
- autoload(:ConfigLoader, "#{__dir__}/leftovers/config_loader")
32
- autoload(:Config, "#{__dir__}/leftovers/config")
33
- autoload(:Definition, "#{__dir__}/leftovers/definition")
34
- autoload(:DefinitionCollection, "#{__dir__}/leftovers/definition_collection")
35
- autoload(:DefinitionNode, "#{__dir__}/leftovers/definition_node")
36
- autoload(:DefinitionNodeSet, "#{__dir__}/leftovers/definition_node_set")
37
- autoload(:DefinitionSet, "#{__dir__}/leftovers/definition_set")
38
- autoload(:DefinitionToAdd, "#{__dir__}/leftovers/definition_to_add")
39
- autoload(:FileCollector, "#{__dir__}/leftovers/file_collector")
40
- autoload(:FileList, "#{__dir__}/leftovers/file_list")
41
- autoload(:File, "#{__dir__}/leftovers/file")
42
- autoload(:MatcherBuilders, "#{__dir__}/leftovers/matcher_builders")
43
- autoload(:Matchers, "#{__dir__}/leftovers/matchers")
44
- autoload(:MergedConfig, "#{__dir__}/leftovers/merged_config")
45
- autoload(:Parser, "#{__dir__}/leftovers/parser")
46
- autoload(:Precompilers, "#{__dir__}/leftovers/precompilers")
47
- autoload(:ProcessorBuilders, "#{__dir__}/leftovers/processor_builders")
48
- autoload(:RakeTask, "#{__dir__}/leftovers/rake_task")
49
- autoload(:Reporter, "#{__dir__}/leftovers/reporter")
50
- autoload(:TodoReporter, "#{__dir__}/leftovers/todo_reporter")
51
- autoload(:Processors, "#{__dir__}/leftovers/processors")
52
- autoload(:VERSION, "#{__dir__}/leftovers/version")
3
+ module Leftovers
4
+ require_relative 'leftovers/autoloader'
5
+ include Autoloader
53
6
 
54
7
  MEMOIZED_IVARS = %i{
55
8
  @config
56
- @collector
57
- @reporter
58
- @leftovers
59
9
  @try_require_cache
60
10
  @stdout
61
11
  @stderr
62
- @parallel
63
12
  @pwd
64
- @progress
65
13
  }.freeze
66
14
 
67
15
  class << self
68
- attr_accessor :parallel, :progress
69
- attr_writer :reporter
70
- alias_method :parallel?, :parallel
71
- alias_method :progress?, :progress
16
+ attr_writer :stdout, :stderr
72
17
 
73
18
  def stdout
74
- @stdout ||= $stdout
19
+ @stdout ||= ::StringIO.new
75
20
  end
76
21
 
77
22
  def stderr
78
- @stderr ||= $stderr
23
+ @stderr ||= ::StringIO.new
79
24
  end
80
25
 
81
26
  def config
82
- @config ||= Leftovers::MergedConfig.new(load_defaults: true)
83
- end
84
-
85
- def collector
86
- @collector ||= Leftovers::Collector.new
87
- end
88
-
89
- def reporter
90
- @reporter ||= Leftovers::Reporter.new
91
- end
92
-
93
- def leftovers
94
- @leftovers ||= begin
95
- collector.collect
96
- collector.definitions.reject(&:in_collection?)
97
- end
98
- end
99
-
100
- def run(stdout: StringIO.new, stderr: StringIO.new) # rubocop:disable Metrics/MethodLength
101
- @stdout = stdout
102
- @stderr = stderr
103
- return reporter.report_success if leftovers.empty?
104
-
105
- only_test = []
106
- none = []
107
- leftovers.sort_by(&:location_s).each do |definition|
108
- if !definition.test? && definition.in_test_collection?
109
- only_test << definition
110
- else
111
- none << definition
112
- end
113
- end
114
-
115
- reporter.report(only_test: only_test, none: none)
27
+ @config ||= MergedConfig.new(load_defaults: true)
116
28
  end
117
29
 
118
30
  def reset
@@ -122,15 +34,16 @@ module Leftovers # rubocop:disable Metrics/ModuleLength
122
34
  end
123
35
 
124
36
  def resolution_instructions_link
125
- "https://github.com/robotdana/leftovers/tree/v#{Leftovers::VERSION}/README.md#how-to-resolve"
37
+ "https://github.com/robotdana/leftovers/tree/v#{VERSION}/README.md#how-to-resolve"
126
38
  end
127
39
 
128
40
  def warn(message)
129
41
  stderr.puts("\e[2K#{message}")
130
42
  end
131
43
 
132
- def error(message)
44
+ def error(message, did_you_mean = nil)
133
45
  warn("\e[31m#{message}\e[0m")
46
+ warn("\n#{did_you_mean}") if did_you_mean
134
47
  exit 1
135
48
  end
136
49
 
@@ -139,15 +52,11 @@ module Leftovers # rubocop:disable Metrics/ModuleLength
139
52
  end
140
53
 
141
54
  def print(message)
142
- stdout.print(message)
143
- end
144
-
145
- def newline
146
- stdout.puts('')
55
+ stdout.print("\e[2K#{message}\r")
147
56
  end
148
57
 
149
58
  def pwd
150
- @pwd ||= Pathname.new(Dir.pwd + '/')
59
+ @pwd ||= ::Pathname.new(::Dir.pwd + '/')
151
60
  end
152
61
 
153
62
  def exit(status = 0)
@@ -159,13 +68,11 @@ module Leftovers # rubocop:disable Metrics/ModuleLength
159
68
  try_require_cache(requirable)
160
69
  end
161
70
 
162
- def each_or_self(value, &block)
163
- return enum_for(__method__, value) unless block
164
-
71
+ def wrap_array(value)
165
72
  case value
166
- when nil then nil
167
- when Array then value.each(&block)
168
- else yield(value)
73
+ when nil then []
74
+ when ::Array then value
75
+ else [value]
169
76
  end
170
77
  end
171
78
 
@@ -185,7 +92,7 @@ module Leftovers # rubocop:disable Metrics/ModuleLength
185
92
  @try_require_cache.fetch(requirable) do
186
93
  require requirable
187
94
  @try_require_cache[requirable] = true
188
- rescue LoadError
95
+ rescue ::LoadError
189
96
  @try_require_cache[requirable] = false
190
97
  end
191
98
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leftovers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dana Sherson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-29 00:00:00.000000000 Z
11
+ date: 2022-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
- - !ruby/object:Gem::Dependency
56
- name: did_you_mean
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: haml
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -396,7 +382,9 @@ files:
396
382
  - lib/leftovers/ast/true_node.rb
397
383
  - lib/leftovers/ast/var_node.rb
398
384
  - lib/leftovers/ast/vasgn_node.rb
385
+ - lib/leftovers/autoloader.rb
399
386
  - lib/leftovers/cli.rb
387
+ - lib/leftovers/collection.rb
400
388
  - lib/leftovers/collector.rb
401
389
  - lib/leftovers/comparable_instance.rb
402
390
  - lib/leftovers/config.rb
@@ -405,6 +393,7 @@ files:
405
393
  - lib/leftovers/config_loader/argumentless_transform_schema.rb
406
394
  - lib/leftovers/config_loader/array_schema.rb
407
395
  - lib/leftovers/config_loader/attribute.rb
396
+ - lib/leftovers/config_loader/bool_schema.rb
408
397
  - lib/leftovers/config_loader/built_in_precompiler_schema.rb
409
398
  - lib/leftovers/config_loader/document_schema.rb
410
399
  - lib/leftovers/config_loader/dynamic_schema.rb
@@ -445,6 +434,7 @@ files:
445
434
  - lib/leftovers/definition_node_set.rb
446
435
  - lib/leftovers/definition_set.rb
447
436
  - lib/leftovers/definition_to_add.rb
437
+ - lib/leftovers/error.rb
448
438
  - lib/leftovers/file.rb
449
439
  - lib/leftovers/file_collector.rb
450
440
  - lib/leftovers/file_collector/comments_processor.rb
@@ -452,11 +442,11 @@ files:
452
442
  - lib/leftovers/file_list.rb
453
443
  - lib/leftovers/matcher_builders.rb
454
444
  - lib/leftovers/matcher_builders/and.rb
455
- - lib/leftovers/matcher_builders/and_not.rb
456
445
  - lib/leftovers/matcher_builders/document.rb
457
446
  - lib/leftovers/matcher_builders/name.rb
458
447
  - lib/leftovers/matcher_builders/node.rb
459
448
  - lib/leftovers/matcher_builders/node_has_argument.rb
449
+ - lib/leftovers/matcher_builders/node_has_block.rb
460
450
  - lib/leftovers/matcher_builders/node_has_keyword_argument.rb
461
451
  - lib/leftovers/matcher_builders/node_has_positional_argument.rb
462
452
  - lib/leftovers/matcher_builders/node_has_receiver.rb
@@ -479,6 +469,7 @@ files:
479
469
  - lib/leftovers/matchers/node_has_any_keyword_argument.rb
480
470
  - lib/leftovers/matchers/node_has_any_positional_argument_with_value.rb
481
471
  - lib/leftovers/matchers/node_has_any_receiver.rb
472
+ - lib/leftovers/matchers/node_has_block.rb
482
473
  - lib/leftovers/matchers/node_has_positional_argument.rb
483
474
  - lib/leftovers/matchers/node_has_positional_argument_with_value.rb
484
475
  - lib/leftovers/matchers/node_has_receiver.rb
@@ -495,6 +486,7 @@ files:
495
486
  - lib/leftovers/matchers/path.rb
496
487
  - lib/leftovers/merged_config.rb
497
488
  - lib/leftovers/parser.rb
489
+ - lib/leftovers/precompile_error.rb
498
490
  - lib/leftovers/precompilers.rb
499
491
  - lib/leftovers/precompilers/erb.rb
500
492
  - lib/leftovers/precompilers/haml.rb
@@ -502,6 +494,7 @@ files:
502
494
  - lib/leftovers/precompilers/precompiler.rb
503
495
  - lib/leftovers/precompilers/slim.rb
504
496
  - lib/leftovers/precompilers/yaml.rb
497
+ - lib/leftovers/precompilers/yaml/builder.rb
505
498
  - lib/leftovers/processor_builders.rb
506
499
  - lib/leftovers/processor_builders/action.rb
507
500
  - lib/leftovers/processor_builders/add_prefix.rb
@@ -509,6 +502,7 @@ files:
509
502
  - lib/leftovers/processor_builders/argument.rb
510
503
  - lib/leftovers/processor_builders/dynamic.rb
511
504
  - lib/leftovers/processor_builders/each.rb
505
+ - lib/leftovers/processor_builders/each_for_definition_set.rb
512
506
  - lib/leftovers/processor_builders/itself.rb
513
507
  - lib/leftovers/processor_builders/keyword.rb
514
508
  - lib/leftovers/processor_builders/keyword_argument.rb
@@ -563,7 +557,9 @@ files:
563
557
  - lib/leftovers/processors/upcase.rb
564
558
  - lib/leftovers/rake_task.rb
565
559
  - lib/leftovers/reporter.rb
560
+ - lib/leftovers/runner.rb
566
561
  - lib/leftovers/todo_reporter.rb
562
+ - lib/leftovers/unexpected_case.rb
567
563
  - lib/leftovers/version.rb
568
564
  homepage: http://github.com/robotdana/leftovers
569
565
  licenses:
@@ -1,16 +0,0 @@
1
- # frozen-string-literal: true
2
-
3
- module Leftovers
4
- module MatcherBuilders
5
- module AndNot
6
- class << self
7
- def build(positive_matcher, negative_matcher)
8
- ::Leftovers::MatcherBuilders::And.build([
9
- positive_matcher,
10
- ::Leftovers::MatcherBuilders::Unless.build(negative_matcher)
11
- ])
12
- end
13
- end
14
- end
15
- end
16
- end