leftovers 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +17 -0
  3. data/README.md +23 -3
  4. data/docs/Configuration.md +119 -2
  5. data/leftovers.gemspec +8 -4
  6. data/lib/.DS_Store +0 -0
  7. data/lib/config/actionpack.yml +11 -0
  8. data/lib/config/activesupport.yml +1 -0
  9. data/lib/config/ruby.yml +10 -0
  10. data/lib/config/slim.yml +4 -0
  11. data/lib/leftovers/collector.rb +3 -1
  12. data/lib/leftovers/config.rb +12 -4
  13. data/lib/leftovers/config_validator/schema_hash.rb +171 -149
  14. data/lib/leftovers/config_validator.rb +1 -0
  15. data/lib/leftovers/definition.rb +1 -1
  16. data/lib/leftovers/dynamic_processors/call.rb +0 -4
  17. data/lib/leftovers/dynamic_processors/call_definition.rb +0 -4
  18. data/lib/leftovers/dynamic_processors/definition.rb +0 -4
  19. data/lib/leftovers/erb.rb +1 -1
  20. data/lib/leftovers/file.rb +53 -5
  21. data/lib/leftovers/file_collector.rb +33 -2
  22. data/lib/leftovers/json.rb +28 -0
  23. data/lib/leftovers/matcher_builders/document.rb +13 -0
  24. data/lib/leftovers/matcher_builders/node.rb +3 -1
  25. data/lib/leftovers/matcher_builders/node_has_argument.rb +3 -4
  26. data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +1 -1
  27. data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +1 -1
  28. data/lib/leftovers/matcher_builders.rb +1 -0
  29. data/lib/leftovers/matchers/all.rb +0 -4
  30. data/lib/leftovers/matchers/and.rb +0 -4
  31. data/lib/leftovers/matchers/any.rb +0 -4
  32. data/lib/leftovers/matchers/node_has_any_keyword_argument.rb +1 -7
  33. data/lib/leftovers/matchers/node_has_any_positional_argument_with_value.rb +1 -7
  34. data/lib/leftovers/matchers/node_has_positional_argument_with_value.rb +0 -4
  35. data/lib/leftovers/matchers/node_name.rb +0 -4
  36. data/lib/leftovers/matchers/node_pair_value.rb +0 -4
  37. data/lib/leftovers/matchers/node_path.rb +0 -4
  38. data/lib/leftovers/matchers/node_scalar_value.rb +0 -4
  39. data/lib/leftovers/matchers/node_type.rb +0 -4
  40. data/lib/leftovers/matchers/not.rb +0 -4
  41. data/lib/leftovers/matchers/or.rb +0 -4
  42. data/lib/leftovers/merged_config.rb +43 -9
  43. data/lib/leftovers/processor_builders/dynamic.rb +2 -1
  44. data/lib/leftovers/slim.rb +21 -0
  45. data/lib/leftovers/todo_reporter.rb +10 -35
  46. data/lib/leftovers/value_processors/camelize.rb +1 -1
  47. data/lib/leftovers/value_processors/deconstantize.rb +1 -1
  48. data/lib/leftovers/value_processors/delete_prefix.rb +0 -6
  49. data/lib/leftovers/value_processors/delete_suffix.rb +0 -6
  50. data/lib/leftovers/value_processors/demodulize.rb +1 -1
  51. data/lib/leftovers/value_processors/keyword.rb +0 -4
  52. data/lib/leftovers/value_processors/keyword_argument.rb +0 -4
  53. data/lib/leftovers/value_processors/parameterize.rb +1 -1
  54. data/lib/leftovers/value_processors/pluralize.rb +1 -1
  55. data/lib/leftovers/value_processors/return_definition.rb +0 -4
  56. data/lib/leftovers/value_processors/singularize.rb +1 -1
  57. data/lib/leftovers/value_processors/titleize.rb +1 -1
  58. data/lib/leftovers/value_processors/underscore.rb +1 -1
  59. data/lib/leftovers/version.rb +1 -1
  60. data/lib/leftovers/yaml.rb +73 -0
  61. data/lib/leftovers.rb +8 -8
  62. metadata +51 -18
  63. data/lib/leftovers/backports.rb +0 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0ca0079209fd4a81f12410ab2b9ccc3ac8eeb176
4
- data.tar.gz: 1c4cca1116e1cb07b630bf97742da022a2fc8362
2
+ SHA256:
3
+ metadata.gz: 32e8f2762f7f513145ea799b64a059c7228dd7e9a4e08c2762abe92aad1370b1
4
+ data.tar.gz: 9134e7d5c66bcbb25bb5fba15f5b1bb661ce18972cf91e179f165af52f955662
5
5
  SHA512:
6
- metadata.gz: 64427530e7fc79d4f683adbbb5eb3df1b6e7693171ab2debd2b2e5b32b394bf7185e2a742b94524a08b130c9eb76ed02d786020acfdffd52a306e7588fc3eff3
7
- data.tar.gz: 1aa3183b82769536d95738f1271f0d7581622fc5607dc48a40788151228151f1e1117ef75b6520db5ca28389b31ddefde19b675d6884e092e405ce123785b188
6
+ metadata.gz: e361dc15e0a3496dadf81f91d356183631b1ad9f0b44951f976785622aa8550ccd0d8a6632064ab646a65231c4b772236cf1136b9267ceb81c59217d36bb4f78
7
+ data.tar.gz: d82fd190746370c9ead45a27e5a660f81aafadf58736afd644d5fafad816daa450f25eebcf30d18875b185ab7d76b3215a696ed35bb75ad33509a474cff87736
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ # 0.6.0
2
+ - drop ruby 2.4 support, allowing for some performance improvements
3
+ - Add ability to parse JSON and YAML files
4
+ - Add magic comment that points to a particular dynamic rule
5
+ - repeated calls to --write-todo won't have ordering differences
6
+ - fix issue with --write-todo and unused methods defined in test files
7
+
8
+ # 0.5.5
9
+ - Fix rails resource/resources method signatures
10
+
11
+ # 0.5.4
12
+ - Add support for slim templates #13 - thanks @veganstraightedge
13
+ - fix the #how-to-resolve link #11 - thanks @veganstraightedge
14
+
15
+ # v0.5.3
16
+ - fix incompatibility with activesupport 7.
17
+
1
18
  # v0.5.2
2
19
  - allow config entries to have duplicates (especially as --write-todo) can write a file with duplicates)
3
20
 
data/README.md CHANGED
@@ -57,7 +57,7 @@ Not directly called at all:
57
57
  lib/hello_world.rb:6:6 generated_method= attr_accessor :generated_method
58
58
  lib/hello_world.rb:6:6 generated_method attr_accessor :generated_method
59
59
 
60
- how to resolve: https://github.com/robotdana/leftovers/tree/main/Readme.md#how_to_resolve
60
+ how to resolve: https://github.com/robotdana/leftovers/tree/main/Readme.md#how-to-resolve
61
61
  ```
62
62
 
63
63
  if there is an overwhelming number of results, try using [`--write-todo`](#write-todo)
@@ -129,7 +129,7 @@ To do this for all definitions of this name, instead of adding a comment, add th
129
129
 
130
130
  ### `# leftovers:call`
131
131
  _aliases `leftovers:calls`_
132
- To mark a dynamic call that doesn't use literal values, use `leftovers:call` with the method name listed
132
+ To mark a call that doesn't use literal values, use `leftovers:call` with the method name listed
133
133
  ```ruby
134
134
  method = [:puts, :warn].sample # leftovers:call puts, warn
135
135
  send(method, 'text')
@@ -137,6 +137,26 @@ send(method, 'text')
137
137
 
138
138
  This would consider `puts` and `warn` to both have been called
139
139
 
140
+ ### `# leftovers:dynamic:*`
141
+ To mark a dynamic call for literal hash and array values without enumerating everything in the comment again, use `leftovers:dynamic:` on the same line as the beginning of the array or hash
142
+
143
+ ```ruby
144
+ [ # leftovers:dynamic:call_login
145
+ :user,
146
+ :admin
147
+ ].each { |method| send("#{method}_login") }
148
+ ```
149
+
150
+ with the following configuration matching the `name: value` to the `leftovers:dynamic:process_name`
151
+
152
+ ```yaml
153
+ dynamic:
154
+ name: call_login
155
+ arguments: '*'
156
+ add_suffix: '_login'
157
+ ```
158
+ This would consider `user_login` and `admin_login` to both have been called.
159
+
140
160
  ## Configuration file
141
161
 
142
162
  The configuration is read from `.leftovers.yml` in your project root.
@@ -163,7 +183,7 @@ see the [built in config files](https://github.com/robotdana/leftovers/tree/main
163
183
 
164
184
  Add the method/pattern to the `dynamic:` list with `skip: true` in the `.leftovers.yml`, or add an inline comment with the list of possibilities `# leftovers:call my_method_1, my_method_2`.
165
185
  - Leftovers compares by name only, so multiple definitions with the same name will count as used even if only one is.
166
- - haml & erb line and column numbers will be wrong as the files have to be precompiled before checking.
186
+ - haml, slim & erb line and column numbers will be wrong as the files have to be precompiled before checking.
167
187
 
168
188
  ## Other tools
169
189
 
@@ -7,7 +7,10 @@ Its presence is optional and all of these settings are optional.
7
7
  - [`exclude_paths:`](#exclude_paths)
8
8
  - [`test_paths:`](#test_paths)
9
9
  - [`haml_paths:`](#haml_paths)
10
+ - [`slim_paths:`](#slim_paths)
10
11
  - [`erb_paths:`](#erb_paths)
12
+ - [`yaml_paths:`](#yaml_paths)
13
+ - [`json_paths:`](#json_paths)
11
14
  - [`requires:`](#requires)
12
15
  - [`gems:`](#gems)
13
16
  - [`keep:`](#keep)
@@ -92,6 +95,18 @@ haml_paths:
92
95
 
93
96
  Arrays are not necessary for single values. `*.haml` is recognized by default
94
97
 
98
+ ## `slim_paths:`
99
+
100
+ list filenames/paths of test directories that are in the slim format
101
+ Defined using the [.gitignore pattern format](https://git-scm.com/docs/gitignore#_pattern_format)
102
+
103
+ ```yml
104
+ slim_paths:
105
+ - '*.slim'
106
+ ```
107
+
108
+ Arrays are not necessary for single values. `*.slim` is recognized by default
109
+
95
110
  ## `erb_paths:`
96
111
 
97
112
  list filenames/paths of test directories that are in the erb format
@@ -104,6 +119,76 @@ erb_paths:
104
119
 
105
120
  Arrays are not necessary for single values. `*.erb` is recognized by default
106
121
 
122
+ ## `yaml_paths:`
123
+
124
+ list filenames/paths of test directories that are in the yaml format
125
+ Defined using the [.gitignore pattern format](https://git-scm.com/docs/gitignore#_pattern_format)
126
+
127
+ ```yml
128
+ include:
129
+ - 'config/*.yml'
130
+ yaml_paths:
131
+ - '*.yml'
132
+ ```
133
+
134
+ These documents will consider yaml tags like `!ruby/class 'MyClass'` to be a call to `MyClass` and render the structure of the yaml as arguments for the [`document:true`](#document-true) rule.
135
+
136
+ so you could, e.g. read the class name out of a yaml document like:
137
+
138
+ ```yml
139
+ class_name: MyClass
140
+ ```
141
+
142
+ with config like:
143
+
144
+ ```yml
145
+ include_paths:
146
+ - 'config/*.yml'
147
+
148
+ dynamic:
149
+ document: true
150
+ path: config/*.yml
151
+ calls:
152
+ argument: class_name
153
+ ```
154
+
155
+ [`nested:`](#nested) may be useful for more complex yaml structures
156
+
157
+ ## `json_paths:`
158
+
159
+ list filenames/paths of test directories that are in the json format
160
+ Defined using the [.gitignore pattern format](https://git-scm.com/docs/gitignore#_pattern_format)
161
+
162
+ ```yml
163
+ include:
164
+ - 'config/*.json'
165
+ json_paths:
166
+ - '*.json'
167
+ ```
168
+
169
+ These documents render the structure of the yaml as arguments for the [`document:true`](#document-true) rule.
170
+
171
+ so you could, e.g. read the class name out of a yaml document like:
172
+
173
+ ```json
174
+ { "class_name": "MyClass" }
175
+ ```
176
+
177
+ with config like:
178
+
179
+ ```yml
180
+ include_paths:
181
+ - 'config/*.json'
182
+
183
+ dynamic:
184
+ document: true
185
+ path: config/*.json
186
+ calls:
187
+ argument: class_name
188
+ ```
189
+
190
+ [`nested:`](#nested) may be useful for more complex json structures
191
+
107
192
  ## `gems:`
108
193
  _alias `gem:`_
109
194
 
@@ -189,7 +274,8 @@ Each entry must have at least one of the following properties to restrict which
189
274
  - [`paths:`](#paths)
190
275
  - [`has_arguments:`](#has_arguments)
191
276
  - [`has_receiver:`](#has_receiver)
192
- - [`unless`](#unless)
277
+ - [`unless:`](#unless)
278
+ - [`document: true`](#document-true)
193
279
 
194
280
  And must have one or both of
195
281
  - ['calls:`](#calls-defines)
@@ -286,6 +372,33 @@ keep:
286
372
  path: /app/helpers
287
373
  ```
288
374
 
375
+ ## `document: true`
376
+
377
+ Instructs to consider the whole document. this is useful when parsing [YAML](#yaml-paths) or [JSON](#json-paths) config files for various values.
378
+
379
+ e.g.
380
+
381
+ ```yml
382
+ includes: /config/roles.yml
383
+ dynamic:
384
+ - document: true
385
+ path: /config/roles.yml
386
+ defines:
387
+ arguments: '*'
388
+ add_suffix: '?'
389
+ add_prefix: can_
390
+ ```
391
+
392
+ will parse "config/roles.yml"
393
+ ```yml
394
+ - build_house
395
+ - drive_car
396
+ ```
397
+
398
+ and consider it to have created methods like `can_build_house?` and `can_drive_car?`
399
+
400
+ [`nested:`](#nested) may be useful for more complex data structures
401
+
289
402
  ## `calls:`, `defines:`
290
403
  _aliases `call:`, `define:`_
291
404
 
@@ -353,7 +466,9 @@ It can have any of these properties:
353
466
  - [`at:`](#at)
354
467
  - [`has_value:`](#has_value_has_receiver)
355
468
 
356
- Arrays are not necessary for single values and if the rule contains only `at:` it can be omitted, and the values moved up a level
469
+ Arrays are not necessary for single values and if the rule contains only `at:` it can be omitted, and the values moved up a level.
470
+
471
+ Positional arguments are zero indexed
357
472
 
358
473
  ## `has_arguments:`
359
474
  _alias `has_argument:`_
@@ -371,6 +486,8 @@ It can have any of these properties:
371
486
 
372
487
  Arrays are not necessary for single values and if the rule contains only `at:` it can be omitted, and the values moved up a level
373
488
 
489
+ Positional arguments are zero indexed
490
+
374
491
  ## `keywords:`
375
492
  When the keyword argument **keywords** are the thing being called.
376
493
 
data/leftovers.gemspec CHANGED
@@ -17,7 +17,9 @@ Gem::Specification.new do |spec|
17
17
  spec.metadata['homepage_uri'] = spec.homepage
18
18
  spec.metadata['source_code_uri'] = 'http://github.com/robotdana/leftovers'
19
19
  spec.metadata['changelog_uri'] = 'http://github.com/robotdana/leftovers/blob/main/CHANGELOG.md'
20
- spec.required_ruby_version = '>= 2.4.0'
20
+
21
+ spec.metadata['rubygems_mfa_required'] = 'true'
22
+ spec.required_ruby_version = '>= 2.5.0'
21
23
 
22
24
  spec.files = Dir.glob('{lib,exe,docs}/**/{*,.*}') + %w{
23
25
  CHANGELOG.md
@@ -37,11 +39,13 @@ Gem::Specification.new do |spec|
37
39
  spec.add_development_dependency 'pry', '~> 0.1'
38
40
  spec.add_development_dependency 'rake', '>= 13'
39
41
  spec.add_development_dependency 'rspec', '~> 3.0'
40
- spec.add_development_dependency 'rubocop', '~> 0.93.1'
41
- spec.add_development_dependency 'rubocop-performance', '~> 1.8.1'
42
- spec.add_development_dependency 'rubocop-rspec', '~> 1.44.1'
42
+ spec.add_development_dependency 'rubocop'
43
+ spec.add_development_dependency 'rubocop-performance'
44
+ spec.add_development_dependency 'rubocop-rake'
45
+ spec.add_development_dependency 'rubocop-rspec'
43
46
  spec.add_development_dependency 'simplecov', '>= 0.18.5'
44
47
  spec.add_development_dependency 'simplecov-console'
48
+ spec.add_development_dependency 'slim'
45
49
  spec.add_development_dependency 'timecop'
46
50
  spec.add_development_dependency 'tty_string', '>= 0.2.1'
47
51
 
data/lib/.DS_Store ADDED
Binary file
@@ -73,8 +73,12 @@ dynamic:
73
73
  - name:
74
74
  - resource
75
75
  - resources
76
+ has_argument: 0
76
77
  calls:
77
78
  - argument: only
79
+ - argument: only
80
+ nested:
81
+ argument: '*'
78
82
  - argument: controller
79
83
  camelize: true
80
84
  add_suffix: Controller
@@ -82,6 +86,7 @@ dynamic:
82
86
  - name:
83
87
  - resource
84
88
  - resources
89
+ has_argument: 0
85
90
  unless:
86
91
  has_argument:
87
92
  - at: only
@@ -96,6 +101,7 @@ dynamic:
96
101
  - name:
97
102
  - resource
98
103
  - resources
104
+ has_argument: 0
99
105
  unless:
100
106
  has_argument:
101
107
  - at: only
@@ -110,6 +116,7 @@ dynamic:
110
116
  - name:
111
117
  - resource
112
118
  - resources
119
+ has_argument: 0
113
120
  unless:
114
121
  has_argument:
115
122
  - at: only
@@ -124,6 +131,7 @@ dynamic:
124
131
  - name:
125
132
  - resource
126
133
  - resources
134
+ has_argument: 0
127
135
  unless:
128
136
  has_argument:
129
137
  - at: only
@@ -138,6 +146,7 @@ dynamic:
138
146
  - name:
139
147
  - resource
140
148
  - resources
149
+ has_argument: 0
141
150
  unless:
142
151
  has_argument:
143
152
  - at: only
@@ -152,6 +161,7 @@ dynamic:
152
161
  - name:
153
162
  - resource
154
163
  - resources
164
+ has_argument: 0
155
165
  unless:
156
166
  has_argument:
157
167
  - at: only
@@ -165,6 +175,7 @@ dynamic:
165
175
  - value: destroy
166
176
  - name:
167
177
  - resources
178
+ - resource
168
179
  - controller
169
180
  - namespace
170
181
  calls:
@@ -1,4 +1,5 @@
1
1
  requires:
2
+ - 'active_support'
2
3
  - 'active_support/core_ext/string'
3
4
  - 'active_support/inflections'
4
5
  - './config/initializers/inflections'
data/lib/config/ruby.yml CHANGED
@@ -10,6 +10,13 @@ include_paths:
10
10
  - '*.erb'
11
11
  - '*.rb'
12
12
 
13
+ yaml_paths:
14
+ - '*.yml'
15
+ - '*.yaml'
16
+
17
+ json_paths:
18
+ - '*.json'
19
+
13
20
  test_paths:
14
21
  - /tests/
15
22
  - /test/
@@ -20,6 +27,9 @@ erb_paths:
20
27
  haml_paths:
21
28
  - '*.haml'
22
29
 
30
+ slim_paths:
31
+ - '*.slim'
32
+
23
33
  keep:
24
34
  - initialize # called by new
25
35
  - inspect # called by repl, to_s
@@ -0,0 +1,4 @@
1
+ include_paths:
2
+ - '*.slim'
3
+ slim_paths:
4
+ - '*.slim'
@@ -28,7 +28,9 @@ module Leftovers
28
28
 
29
29
  def collect_file_list(list)
30
30
  if Leftovers.parallel?
31
- Parallel.each(list, finish: method(:finish_file), &method(:collect_file))
31
+ Parallel.each(list, finish: method(:finish_file)) do |file|
32
+ collect_file(file)
33
+ end
32
34
  else
33
35
  list.each { |file| finish_file(nil, nil, collect_file(file)) }
34
36
  end
@@ -4,10 +4,6 @@ require 'yaml'
4
4
 
5
5
  module Leftovers
6
6
  class Config
7
- # :nocov:
8
- using ::Leftovers::Backports::SetCaseEq if defined?(::Leftovers::Backports::SetCaseEq)
9
- # :nocov:
10
-
11
7
  attr_reader :name
12
8
 
13
9
  def initialize(name, path: nil, content: nil)
@@ -36,6 +32,18 @@ module Leftovers
36
32
  @haml_paths ||= Array(yaml[:haml_paths])
37
33
  end
38
34
 
35
+ def slim_paths
36
+ @slim_paths ||= Array(yaml[:slim_paths])
37
+ end
38
+
39
+ def yaml_paths
40
+ @yaml_paths ||= Array(yaml[:yaml_paths])
41
+ end
42
+
43
+ def json_paths
44
+ @json_paths ||= Array(yaml[:json_paths])
45
+ end
46
+
39
47
  def erb_paths
40
48
  @erb_paths ||= Array(yaml[:erb_paths])
41
49
  end