leftovers 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/config/audited.yml +4 -0
- data/lib/config/rails.yml +7 -0
- data/lib/config/ruby.yml +14 -4
- data/lib/leftovers/argument_rule.rb +3 -2
- data/lib/leftovers/definition_set.rb +4 -0
- data/lib/leftovers/file_collector.rb +3 -31
- data/lib/leftovers/parser.rb +40 -0
- data/lib/leftovers/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b371d523daccdf78bc7c31a0b17256299029e95aa6d9d14a3578ac42929ee08d
|
4
|
+
data.tar.gz: 6798582ea10ea250ea68fc0325564e116fa2d317416d0df0b02a7d2e8235849a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b38f49be63e8d7ba2e63a3c5a7bbddd8d61692dc603da0d2f0b936fdb02f421b357a8b2a089100e8dd3e21b50b6acc21668dd7aa1f472b721d25fe6d4655b4fe
|
7
|
+
data.tar.gz: f015305d13562b66a33b4f4effc680784bf8a8d24b3d7e143a2a6d2c20285ae47377867ea22cad995e9dd467b5d86064afbc78becd6d55424b0ee96c4a54737b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# v0.2.1
|
2
|
+
|
3
|
+
- Fix route arguments with '/' handling (e.g get `'/admin', to: 'admin/dashboard#index'`)
|
4
|
+
- Fix route arguments for `root to: "whatever#index"`
|
5
|
+
- Add some more rails exceptions (`APP_ROOT`, `APP_PATH`, Mailer Previews)
|
6
|
+
- add more ruby object methods that are called by various bits of ruby
|
7
|
+
- correct output of unused definitions using `linked_transforms:`
|
8
|
+
- add `audited` gem
|
9
|
+
|
1
10
|
# v0.2.0
|
2
11
|
|
3
12
|
Play nice with rubocop
|
data/lib/config/rails.yml
CHANGED
@@ -18,10 +18,16 @@ rules:
|
|
18
18
|
- validate_each # ActiveModel::EachValidator
|
19
19
|
- format_message # ActiveSupport::Logger
|
20
20
|
- ssl_configured? # ApplicationController
|
21
|
+
- APP_PATH
|
22
|
+
- APP_ROOT
|
21
23
|
- skip: true
|
22
24
|
names:
|
23
25
|
has_suffix: Helper
|
24
26
|
path: /app/helpers
|
27
|
+
- skip: true
|
28
|
+
names:
|
29
|
+
has_suffix: Preview
|
30
|
+
path: '**/mailers/previews/**/*_preview.rb'
|
25
31
|
- names:
|
26
32
|
- after_initialize
|
27
33
|
- after_find
|
@@ -227,6 +233,7 @@ rules:
|
|
227
233
|
- patch
|
228
234
|
- post
|
229
235
|
- put
|
236
|
+
- root
|
230
237
|
calls:
|
231
238
|
- arguments: [1, action]
|
232
239
|
- argument: '**'
|
data/lib/config/ruby.yml
CHANGED
@@ -17,12 +17,18 @@ rules:
|
|
17
17
|
- skip: true
|
18
18
|
name:
|
19
19
|
- initialize # called by new
|
20
|
-
- inspect # called by repl
|
20
|
+
- inspect # called by repl, to_s
|
21
21
|
- respond_to_missing? # called by respond_to?
|
22
22
|
- method_missing # called by method dispatch
|
23
|
-
-
|
24
|
-
-
|
25
|
-
-
|
23
|
+
- coerce # called by Numeric
|
24
|
+
- to_s # called by "#{}"
|
25
|
+
- to_ary # called by Array(), []+
|
26
|
+
- to_a # called by Array(), *splat
|
27
|
+
- to_str # called by String(), ""+
|
28
|
+
- to_hash # called by Hash(), **splat, {}.merge
|
29
|
+
- to_int # called by Integer()
|
30
|
+
- to_i # called by Integer()
|
31
|
+
- to_f # called by Float()
|
26
32
|
- <=> # called by Comparable
|
27
33
|
- each # called by Enumerable
|
28
34
|
- marshal_dump # called by Marshal.dump
|
@@ -33,6 +39,10 @@ rules:
|
|
33
39
|
- extended # called by extend Module
|
34
40
|
- included # called by include Module
|
35
41
|
- $VERBOSE # called by whatever is outputting warnings i guess
|
42
|
+
- === # called by when
|
43
|
+
- == # called by Array value, Hash value equality, ===
|
44
|
+
- hash # called by Hash key equality
|
45
|
+
- eql? # called by Hash key equality
|
36
46
|
- name:
|
37
47
|
- send
|
38
48
|
- public_send
|
@@ -176,7 +176,8 @@ module Leftovers
|
|
176
176
|
|
177
177
|
SPLIT = /[.:]+/.freeze
|
178
178
|
def symbol_values(symbol_node, method_node) # rubocop:disable Metrics/MethodLength
|
179
|
-
subnodes = symbol_node.to_s
|
179
|
+
subnodes = Array(transform(symbol_node.to_s, method_node))
|
180
|
+
.flat_map { |s| s.to_s.split(SPLIT).map(&:to_sym) }
|
180
181
|
|
181
182
|
return subnodes unless @definer
|
182
183
|
|
@@ -199,7 +200,7 @@ module Leftovers
|
|
199
200
|
end
|
200
201
|
|
201
202
|
def transform(string, method_node)
|
202
|
-
return string
|
203
|
+
return string unless @transform || @transforms
|
203
204
|
return @transform.transform(string, method_node) if @transform
|
204
205
|
|
205
206
|
@transforms.map do |transform|
|
@@ -2,14 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'fast_ignore'
|
4
4
|
require 'set'
|
5
|
-
|
6
|
-
require 'parser/current'
|
7
|
-
require_relative 'ast/builder'
|
8
|
-
require_relative 'ast/node'
|
5
|
+
require_relative 'parser'
|
9
6
|
require_relative 'definition'
|
10
7
|
|
11
8
|
module Leftovers
|
12
|
-
class FileCollector < Parser::AST::Processor # rubocop:disable Metrics/ClassLength
|
9
|
+
class FileCollector < ::Parser::AST::Processor # rubocop:disable Metrics/ClassLength
|
13
10
|
attr_reader :calls
|
14
11
|
attr_reader :definitions
|
15
12
|
|
@@ -34,33 +31,8 @@ module Leftovers
|
|
34
31
|
}
|
35
32
|
end
|
36
33
|
|
37
|
-
# mostly copied from https://github.com/whitequark/parser/blob/master/lib/parser/base.rb
|
38
|
-
# but with our builder
|
39
|
-
def self.parser # rubocop:disable Metrics/MethodLength
|
40
|
-
p = ::Parser::CurrentRuby.new(Leftovers::AST::Builder.new)
|
41
|
-
p.diagnostics.all_errors_are_fatal = true
|
42
|
-
p.diagnostics.ignore_warnings = true
|
43
|
-
|
44
|
-
p.diagnostics.consumer = lambda do |diagnostic|
|
45
|
-
warn(diagnostic.render)
|
46
|
-
end
|
47
|
-
|
48
|
-
p
|
49
|
-
end
|
50
|
-
PARSER = parser
|
51
|
-
|
52
|
-
# mostly copied from https://github.com/whitequark/parser/blob/master/lib/parser/base.rb
|
53
|
-
# but with our parser
|
54
|
-
def parse_with_comments(string, file = '(string)', line = 1)
|
55
|
-
PARSER.reset
|
56
|
-
source_buffer = ::Parser::CurrentRuby.send(
|
57
|
-
:setup_source_buffer, file, line, string, PARSER.default_encoding
|
58
|
-
)
|
59
|
-
PARSER.parse_with_comments(source_buffer)
|
60
|
-
end
|
61
|
-
|
62
34
|
def collect
|
63
|
-
ast, comments = parse_with_comments(@ruby, @file)
|
35
|
+
ast, comments = Leftovers::Parser.parse_with_comments(@ruby, @file)
|
64
36
|
process_comments(comments)
|
65
37
|
process(ast)
|
66
38
|
rescue Parser::SyntaxError => e
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'parser'
|
4
|
+
require 'parser/current'
|
5
|
+
|
6
|
+
require_relative 'ast/builder'
|
7
|
+
require_relative 'ast/node'
|
8
|
+
|
9
|
+
module Leftovers
|
10
|
+
module Parser
|
11
|
+
class << self
|
12
|
+
# mostly copied from https://github.com/whitequark/parser/blob/master/lib/parser/base.rb
|
13
|
+
# but with our parser
|
14
|
+
def parse_with_comments(string, file = '(string)', line = 1)
|
15
|
+
PARSER.reset
|
16
|
+
source_buffer = ::Parser::CurrentRuby.send(
|
17
|
+
:setup_source_buffer, file, line, string, PARSER.default_encoding
|
18
|
+
)
|
19
|
+
PARSER.parse_with_comments(source_buffer)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# mostly copied from https://github.com/whitequark/parser/blob/master/lib/parser/base.rb
|
25
|
+
# but with our builder
|
26
|
+
def parser # rubocop:disable Metrics/MethodLength
|
27
|
+
p = ::Parser::CurrentRuby.new(Leftovers::AST::Builder.new)
|
28
|
+
p.diagnostics.all_errors_are_fatal = true
|
29
|
+
p.diagnostics.ignore_warnings = true
|
30
|
+
|
31
|
+
p.diagnostics.consumer = lambda do |diagnostic|
|
32
|
+
warn(diagnostic.render)
|
33
|
+
end
|
34
|
+
|
35
|
+
p
|
36
|
+
end
|
37
|
+
end
|
38
|
+
PARSER = parser
|
39
|
+
end
|
40
|
+
end
|
data/lib/leftovers/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dana Sherson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -207,6 +207,7 @@ files:
|
|
207
207
|
- exe/leftovers
|
208
208
|
- leftovers.gemspec
|
209
209
|
- lib/config/attr_encrypted.yml
|
210
|
+
- lib/config/audited.yml
|
210
211
|
- lib/config/builder.yml
|
211
212
|
- lib/config/capistrano.yml
|
212
213
|
- lib/config/datagrid.yml
|
@@ -247,6 +248,7 @@ files:
|
|
247
248
|
- lib/leftovers/hash_rule.rb
|
248
249
|
- lib/leftovers/merged_config.rb
|
249
250
|
- lib/leftovers/name_rule.rb
|
251
|
+
- lib/leftovers/parser.rb
|
250
252
|
- lib/leftovers/rake_task.rb
|
251
253
|
- lib/leftovers/reporter.rb
|
252
254
|
- lib/leftovers/rule.rb
|