nodegrep 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/nodegrep +33 -23
- data/lib/nodegrep/matcher.rb +5 -2
- data/lib/nodegrep/presenter.rb +6 -3
- data/lib/nodegrep.rb +3 -1
- metadata +25 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d519b2a5c909e0cc9dcaaceded64a73f3f9b5e4f6d31b2914da28a0e2fc0fb47
|
4
|
+
data.tar.gz: c8273e0c3797616efdb7f122819fab7424f4c44dcea1c63371f4a5609d68d9af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57b38476abe2cf5680b95430ef0e1c64f7f908307a690e8e39ac316aa22ad044304ad0126750a4bd81e9af962eefbddc9c1cf61fdd3409fd4555d2299379602a
|
7
|
+
data.tar.gz: be6cf1bf29b45d197009e4838d4bb040b1f53e22f1cef3b253ffac960b45807255d8c6b22de6b204d87b2f9d9dc8f1ea1aff41557a839949502816a4535622ef
|
data/bin/nodegrep
CHANGED
@@ -1,25 +1,28 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'nodegrep'
|
3
5
|
|
6
|
+
DIRECTORY_GLOB = '**/*.{rb,rake}'
|
7
|
+
|
4
8
|
recurse = false
|
5
9
|
line_numbers = false
|
6
10
|
lazy = false
|
7
11
|
|
8
12
|
helpmesg = <<~HELP
|
9
|
-
nodegrep - find code that matches NodePattern DSL
|
13
|
+
nodegrep - find code that matches NodePattern DSL
|
10
14
|
|
11
|
-
USAGE
|
15
|
+
USAGE
|
12
16
|
|
13
|
-
nodegrep [flags] pattern files
|
17
|
+
nodegrep [flags] pattern files
|
14
18
|
|
15
|
-
Available flags:
|
19
|
+
Available flags:
|
16
20
|
|
17
|
-
-l\tLazy evaluation - stop at the first match
|
18
|
-
-n\tTurn on line number output
|
19
|
-
-r\tRecurse into directories
|
21
|
+
-l\tLazy evaluation - stop at the first match
|
22
|
+
-n\tTurn on line number output
|
23
|
+
-r\tRecurse into directories
|
20
24
|
HELP
|
21
25
|
|
22
|
-
|
23
26
|
# nodegrep [flags] pattern file(s)
|
24
27
|
|
25
28
|
# process flags
|
@@ -28,10 +31,11 @@ arg = ''
|
|
28
31
|
loop do
|
29
32
|
arg = ARGV.shift
|
30
33
|
if arg.nil?
|
31
|
-
print helpmesg
|
32
|
-
exit
|
34
|
+
print helpmesg
|
35
|
+
exit(-1)
|
33
36
|
end
|
34
37
|
break if arg[0] != '-'
|
38
|
+
|
35
39
|
case arg[1]
|
36
40
|
when 'l'
|
37
41
|
lazy = true
|
@@ -42,7 +46,7 @@ loop do
|
|
42
46
|
else
|
43
47
|
puts "Error - Illegal flag: -#{arg[1]}".red
|
44
48
|
print helpmesg
|
45
|
-
exit
|
49
|
+
exit(-1)
|
46
50
|
end
|
47
51
|
end
|
48
52
|
|
@@ -50,27 +54,34 @@ end
|
|
50
54
|
|
51
55
|
pattern = arg
|
52
56
|
|
57
|
+
# If 'pattern' is preceded by "method:", presume that we are just looking for method invocations
|
58
|
+
|
59
|
+
if pattern =~ %r{\Amethod:([a-z_]+)}
|
60
|
+
pattern = "(send nil? :#{$1} ... )"
|
61
|
+
end
|
62
|
+
|
53
63
|
# The rest of the args are filenames
|
54
64
|
|
55
|
-
if ARGV.length
|
56
|
-
puts
|
57
|
-
exit
|
65
|
+
if ARGV.length.zero? && !recurse
|
66
|
+
puts 'Error - no files to process'.red
|
67
|
+
exit(-1)
|
58
68
|
end
|
59
69
|
|
60
70
|
files_to_process = []
|
61
71
|
|
62
72
|
if recurse
|
63
|
-
|
64
|
-
|
65
|
-
|
73
|
+
case ARGV.length
|
74
|
+
when 0
|
75
|
+
files_to_process = Dir.glob(DIRECTORY_GLOB, base: Dir.getwd)
|
76
|
+
when 1
|
66
77
|
unless File.directory?(ARGV[0])
|
67
78
|
puts "Error - value #{ARGV[0]} is not a directory"
|
68
|
-
exit
|
79
|
+
exit(-1)
|
69
80
|
end
|
70
|
-
files_to_process = Dir.glob(
|
81
|
+
files_to_process = Dir.glob(DIRECTORY_GLOB, base: ARGV[0]).map { |f| File.join(ARGV[0], f) }
|
71
82
|
else
|
72
|
-
puts
|
73
|
-
exit
|
83
|
+
puts 'Error - cannot recursively process more than one directory'
|
84
|
+
exit(-1)
|
74
85
|
end
|
75
86
|
else
|
76
87
|
files_to_process = ARGV
|
@@ -87,10 +98,9 @@ files_to_process.each do |f|
|
|
87
98
|
pres = NodeGrep::Presenter.new(source)
|
88
99
|
pres.line_numbers = line_numbers
|
89
100
|
matches = m.matching_nodes(pattern)
|
90
|
-
puts " *** #{f}".green if matches.length
|
101
|
+
puts " *** #{f}".green if matches.length.positive?
|
91
102
|
matches.each do |match|
|
92
103
|
puts pres.get_lines(match.first_line, match.last_line)
|
93
104
|
exit if lazy
|
94
105
|
end
|
95
106
|
end
|
96
|
-
|
data/lib/nodegrep/matcher.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rubocop'
|
2
4
|
require 'rubocop-ast'
|
3
5
|
|
@@ -23,8 +25,9 @@ module NodeGrep
|
|
23
25
|
|
24
26
|
def visit_node(node)
|
25
27
|
return unless node.class.to_s.include?('RuboCop::AST')
|
28
|
+
|
26
29
|
@matches << node if @pattern.match(node)
|
27
|
-
node.children.each{ |child| visit_node(child) }
|
30
|
+
node.children.each { |child| visit_node(child) }
|
28
31
|
end
|
29
32
|
end
|
30
|
-
end
|
33
|
+
end
|
data/lib/nodegrep/presenter.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'colorize'
|
2
4
|
|
3
5
|
module NodeGrep
|
@@ -10,17 +12,18 @@ module NodeGrep
|
|
10
12
|
@line_numbers = false
|
11
13
|
|
12
14
|
def initialize(source)
|
13
|
-
@source_lines = source.split("\n").map{ |l| l.gsub("\r",
|
15
|
+
@source_lines = source.split("\n").map { |l| l.gsub("\r", '') }
|
14
16
|
end
|
15
17
|
|
16
18
|
def get_lines(x, y)
|
17
19
|
num_lines = @source_lines.length
|
18
20
|
raise OutOfBounds if x < 1 || y < 1 || x > y
|
19
21
|
raise OutOfBounds if x > num_lines || y > num_lines
|
22
|
+
|
20
23
|
x -= 1
|
21
24
|
y -= 1
|
22
25
|
formatted_lines = (x..y).each.collect do |i|
|
23
|
-
output =
|
26
|
+
output = String.new
|
24
27
|
output << "#{i + 1}: " if @line_numbers
|
25
28
|
output << @source_lines[i]
|
26
29
|
output
|
@@ -28,4 +31,4 @@ module NodeGrep
|
|
28
31
|
formatted_lines.join("\n")
|
29
32
|
end
|
30
33
|
end
|
31
|
-
end
|
34
|
+
end
|
data/lib/nodegrep.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nodegrep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Jenkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rubocop
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,19 +39,19 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '1.40'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: pry
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
34
|
-
type: :
|
47
|
+
version: '0.14'
|
48
|
+
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
54
|
+
version: '0.14'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,19 +67,19 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '3.12'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rubocop-rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '2.15'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '2.15'
|
69
83
|
description:
|
70
84
|
email: jjenkins@gitlab.com
|
71
85
|
executables:
|
@@ -77,7 +91,7 @@ files:
|
|
77
91
|
- lib/nodegrep.rb
|
78
92
|
- lib/nodegrep/matcher.rb
|
79
93
|
- lib/nodegrep/presenter.rb
|
80
|
-
homepage: https://gitlab.com/jon_jenkins
|
94
|
+
homepage: https://gitlab.com/jon_jenkins/nodegrep
|
81
95
|
licenses:
|
82
96
|
- MIT
|
83
97
|
metadata: {}
|
@@ -96,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
110
|
- !ruby/object:Gem::Version
|
97
111
|
version: '0'
|
98
112
|
requirements: []
|
99
|
-
rubygems_version: 3.
|
113
|
+
rubygems_version: 3.1.6
|
100
114
|
signing_key:
|
101
115
|
specification_version: 4
|
102
116
|
summary: A utility to match patterns in Ruby code
|