querly 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d2f7b1ba2cfc19fc71ac84ab1f2b65e6f50fab63
4
- data.tar.gz: 270c4fbe0609fae2af52c9f5bc0d1b70f00304e5
2
+ SHA256:
3
+ metadata.gz: e84d868d2fc893c8ca087565a483bf0ad7aa2088d6ff7e4c890584bcf5deb2a3
4
+ data.tar.gz: 1c2836c3c6b87b0ddc9195d0b8af9a242bc8a31b12a7a9f4c758d3e0c0815229
5
5
  SHA512:
6
- metadata.gz: 4808003cfd6d836c4a627bce6b31bb88115f301a0d41347c7e56f352b22fec95d4469a1d94eed904335f842f21517ce1fa09234add15e79a42423146035e8925
7
- data.tar.gz: 624cf0658f0f4badf70aa4297d1f2e0fef84c576bad0f43e6aae9350536fe4003a530fb47bb84b24aab45532927823d706cee9e31d30c0f3268887922ec1ddc0
6
+ metadata.gz: ee0e9bde00fe3052ac30d60da5a73f18270e5e800460d36e3304dd0b3ec791b6233560dc16731f99f28e6cc1482f915607453b66fd2d418ab0c1e7e00fdc9c12
7
+ data.tar.gz: 0e17feb0be475e457946c465930e5254e3b3618e06ec9305f68b4d7a047bdfff1849069b6827519358ee2d34e392cf11c175e58440dbac2e3c8c78c5bcc7ccb6
@@ -1,10 +1,10 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3.6
5
- - 2.4.3
6
- - 2.5.0
7
- before_install: gem install bundler -v 1.12.5
4
+ - 2.4.5
5
+ - 2.5.3
6
+ - 2.6.0
7
+ before_install: gem install bundler
8
8
  script:
9
9
  - bundle exec rake test
10
10
  - bundle exec querly test --config=sample.yaml
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.14.0 (2019-01-22)
6
+
7
+ * Allow having `...` pattens anywhere positional argument patterns are valid #54
8
+ * Add `querly find` command (@gfx) #49
9
+
5
10
  ## 0.13.0 (2018-08-27)
6
11
 
7
12
  * Make history file location configurable through `QUERLY_HOME` (defaults to `~/.querly`)
@@ -83,6 +83,16 @@ Specify configuration file by --config option.
83
83
  ).start
84
84
  end
85
85
 
86
+ desc "find pattern [paths]", "Find for the pattern in given paths"
87
+ def find(pattern, *paths)
88
+ require 'querly/cli/find'
89
+
90
+ Find.new(
91
+ pattern: pattern,
92
+ paths: paths.empty? ? [Pathname.pwd] : paths.map {|path| Pathname(path) },
93
+ ).start
94
+ end
95
+
86
96
  desc "test", "Check configuration"
87
97
  option :config, default: "querly.yml"
88
98
  def test()
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Querly
4
+ class CLI
5
+ class Find
6
+ include Concerns::BacktraceFormatter
7
+
8
+ attr_reader :pattern_str
9
+ attr_reader :paths
10
+
11
+ def initialize(pattern:, paths:)
12
+ @pattern_str = pattern
13
+ @paths = paths
14
+ end
15
+
16
+ def start
17
+ count = 0
18
+
19
+ analyzer.find(pattern) do |script, pair|
20
+ path = script.path.to_s
21
+ line_no = pair.node.loc.first_line
22
+ range = pair.node.loc.expression
23
+ start_col = range.column
24
+ end_col = range.last_column
25
+
26
+ src = range.source_buffer.source_lines[line_no-1]
27
+ src = Rainbow(src[0...start_col]).blue +
28
+ Rainbow(src[start_col...end_col]).bright.blue.bold +
29
+ Rainbow(src[end_col..-1]).blue
30
+
31
+ puts " #{path}:#{line_no}:#{start_col}\t#{src}"
32
+
33
+ count += 1
34
+ end
35
+
36
+ puts "#{count} results"
37
+ rescue => exn
38
+ STDOUT.puts Rainbow("Error: #{exn}").red
39
+ STDTOU.puts "pattern: #{pattern_str}"
40
+ STDOUT.puts "Backtrace:"
41
+ STDOUT.puts format_backtrace(exn.backtrace)
42
+ end
43
+
44
+ def pattern
45
+ Pattern::Parser.parse(pattern_str, where: {})
46
+ end
47
+
48
+ def analyzer
49
+ return @analyzer if @analyzer
50
+
51
+ @analyzer = Analyzer.new(config: nil, rule: nil)
52
+
53
+ ScriptEnumerator.new(paths: paths, config: nil).each do |path, script|
54
+ case script
55
+ when Script
56
+ @analyzer.scripts << script
57
+ when StandardError
58
+ p path: path, script: script.inspect
59
+ puts script.backtrace
60
+ end
61
+ end
62
+
63
+ @analyzer
64
+ end
65
+ end
66
+ end
67
+ end
@@ -200,7 +200,8 @@ module Querly
200
200
 
201
201
  case args
202
202
  when Argument::AnySeq
203
- if args.tail
203
+ case args.tail
204
+ when Argument::KeyValue
204
205
  if first_node
205
206
  case
206
207
  when nodes.last.type == :kwsplat
@@ -214,6 +215,10 @@ module Querly
214
215
  else
215
216
  test_hash_args({}, args.tail)
216
217
  end
218
+ when Argument::Expr
219
+ nodes.size.times.any? do |i|
220
+ test_args(nodes.drop(i), args.tail)
221
+ end
217
222
  else
218
223
  true
219
224
  end
@@ -40,6 +40,7 @@ args: { result = nil }
40
40
  | AMP expr { result = Argument::BlockPass.new(expr: val[1]) }
41
41
  | kw_args
42
42
  | DOTDOTDOT { result = Argument::AnySeq.new }
43
+ | DOTDOTDOT COMMA args { result = Argument::AnySeq.new(tail: val[2]) }
43
44
  | DOTDOTDOT COMMA kw_args { result = Argument::AnySeq.new(tail: val[2]) }
44
45
 
45
46
  kw_args: { result = nil }
@@ -1,3 +1,3 @@
1
1
  module Querly
2
- VERSION = "0.13.0"
2
+ VERSION = "0.14.0"
3
3
  end
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_development_dependency "bundler", "~> 1.12"
25
+ spec.add_development_dependency "bundler", ">= 1.12"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
27
  spec.add_development_dependency "minitest", "~> 5.0"
28
28
  spec.add_development_dependency "racc", "= 1.4.14"
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: querly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-27 00:00:00.000000000 Z
11
+ date: 2019-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.12'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.12'
27
27
  - !ruby/object:Gem::Dependency
@@ -169,6 +169,7 @@ files:
169
169
  - lib/querly/check.rb
170
170
  - lib/querly/cli.rb
171
171
  - lib/querly/cli/console.rb
172
+ - lib/querly/cli/find.rb
172
173
  - lib/querly/cli/formatter.rb
173
174
  - lib/querly/cli/rules.rb
174
175
  - lib/querly/cli/test.rb
@@ -214,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
215
  version: '0'
215
216
  requirements: []
216
217
  rubyforge_project:
217
- rubygems_version: 2.6.8
218
+ rubygems_version: 2.7.6
218
219
  signing_key:
219
220
  specification_version: 4
220
221
  summary: Pattern Based Checking Tool for Ruby