nodegrep 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f209db3fa387b6bbe388714324c6496e1b0ce06ad2d0e840f0d6b9fa926b02b8
4
- data.tar.gz: 7a0b15225d3d88ce0fb526c62efe52d0e89b6cd3ef2b182dbf715b076ca17d26
3
+ metadata.gz: 108aaff1f92b660f728f8b1f61723a48e54dc490eba6baa5b8762a2108bef662
4
+ data.tar.gz: 13186164306f961fea541eff0dd21dc850be5fe9714816a009bba1ca82c22b56
5
5
  SHA512:
6
- metadata.gz: ac74bfa8b5ff5c094021067e27896af6d86388b214baa07815257fed2e529f13a2c3eaeafe417977d623bb86829db9407ff1785b0131e7bf8ee7ed20d53d2b72
7
- data.tar.gz: d239b23e7279cbbe34a2b006c4e67b93465912c368cc1250ce4372d1f6f6ce2a7cb2d16a03f1d72600d25e9073314b229d37a6eed3e7a3ff58cabab64432a38c
6
+ metadata.gz: 54235488982d377d828a5eebdd7e4d1c8979b042dbd95ca6949ba8f19771e6a0c1a14550a2986a87c5cc55a5ee9789b9d3bab105aef851fa99a29109dec8915d
7
+ data.tar.gz: 4faa0f624093834b1fac0f65340f03a5d617f027d4546a1ac7c9234c02afd3f3c78b1a0a8a5d812decdfc20058d0df0aedbe2327a67206ea894366849f7ed824
data/bin/nodegrep CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'nodegrep'
3
5
 
4
6
  recurse = false
@@ -6,20 +8,19 @@ line_numbers = false
6
8
  lazy = false
7
9
 
8
10
  helpmesg = <<~HELP
9
- nodegrep - find code that matches NodePattern DSL
11
+ nodegrep - find code that matches NodePattern DSL
10
12
 
11
- USAGE
13
+ USAGE
12
14
 
13
- nodegrep [flags] pattern files
15
+ nodegrep [flags] pattern files
14
16
 
15
- Available flags:
17
+ Available flags:
16
18
 
17
- -l\tLazy evaluation - stop at the first match
18
- -n\tTurn on line number output
19
- -r\tRecurse into directories
19
+ -l\tLazy evaluation - stop at the first match
20
+ -n\tTurn on line number output
21
+ -r\tRecurse into directories
20
22
  HELP
21
23
 
22
-
23
24
  # nodegrep [flags] pattern file(s)
24
25
 
25
26
  # process flags
@@ -28,10 +29,11 @@ arg = ''
28
29
  loop do
29
30
  arg = ARGV.shift
30
31
  if arg.nil?
31
- print helpmesg
32
- exit -1
32
+ print helpmesg
33
+ exit(-1)
33
34
  end
34
35
  break if arg[0] != '-'
36
+
35
37
  case arg[1]
36
38
  when 'l'
37
39
  lazy = true
@@ -42,7 +44,7 @@ loop do
42
44
  else
43
45
  puts "Error - Illegal flag: -#{arg[1]}".red
44
46
  print helpmesg
45
- exit -1
47
+ exit(-1)
46
48
  end
47
49
  end
48
50
 
@@ -52,25 +54,26 @@ pattern = arg
52
54
 
53
55
  # The rest of the args are filenames
54
56
 
55
- if ARGV.length == 0 && !recurse
56
- puts "Error - no files to process".red
57
- exit -1
57
+ if ARGV.length.zero? && !recurse
58
+ puts 'Error - no files to process'.red
59
+ exit(-1)
58
60
  end
59
61
 
60
62
  files_to_process = []
61
63
 
62
64
  if recurse
63
- if ARGV.length == 0
65
+ case ARGV.length
66
+ when 0
64
67
  files_to_process = Dir.glob('**/*.rb', base: Dir.getwd)
65
- elsif ARGV.length == 1
68
+ when 1
66
69
  unless File.directory?(ARGV[0])
67
70
  puts "Error - value #{ARGV[0]} is not a directory"
68
- exit -1
71
+ exit(-1)
69
72
  end
70
- files_to_process = Dir.glob('**/*.rb', base: ARGV[0]).map{ |f| File.join(ARGV[0], f) }
73
+ files_to_process = Dir.glob('**/*.rb', base: ARGV[0]).map { |f| File.join(ARGV[0], f) }
71
74
  else
72
- puts "Error - cannot recursively process more than one directory"
73
- exit -1
75
+ puts 'Error - cannot recursively process more than one directory'
76
+ exit(-1)
74
77
  end
75
78
  else
76
79
  files_to_process = ARGV
@@ -87,10 +90,9 @@ files_to_process.each do |f|
87
90
  pres = NodeGrep::Presenter.new(source)
88
91
  pres.line_numbers = line_numbers
89
92
  matches = m.matching_nodes(pattern)
90
- puts " *** #{f}".green if matches.length > 0
93
+ puts " *** #{f}".green if matches.length.positive?
91
94
  matches.each do |match|
92
95
  puts pres.get_lines(match.first_line, match.last_line)
93
96
  exit if lazy
94
97
  end
95
98
  end
96
-
@@ -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
@@ -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
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'nodegrep/matcher'
2
- require 'nodegrep/presenter'
4
+ require 'nodegrep/presenter'
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.1
4
+ version: 0.0.2
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-09 00:00:00.000000000 Z
11
+ date: 2022-12-12 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: colorize
42
+ name: pry
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0.8'
34
- type: :runtime
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.8'
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: pry
70
+ name: rubocop-rspec
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '0.14'
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: '0.14'
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: {}