querly 0.7.0 → 0.8.0

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
  SHA1:
3
- metadata.gz: 2a7dfd2ae45b1173ea9e23967e5c39b211bebffb
4
- data.tar.gz: d014023c1f6e4d6989d04ea688dbaad0fed475ba
3
+ metadata.gz: 4a98ed1029750241af4e9b51f823e58742290ec6
4
+ data.tar.gz: 58cddad4c97eeef01447dcc0cc0751a8c9483176
5
5
  SHA512:
6
- metadata.gz: 54969626459f41a814877e188ee487a911f01cbe9a17fe83ed2ed8b110736be3088994c2c0e73754c418c93e37e640fe409707740edd9245f63adc7d09045cf0
7
- data.tar.gz: 100d7dbc6eb4dc7a6edadd86c08760782aa4ab65f1b4958d1b1e3f6360a2db28b00b748297367dd7df47caef9259b7b93f13b3a4f6ffc57dc694c785dcb49332
6
+ metadata.gz: 21906e1368f509bd343621ee669ab215b8509e591d268d4731bf01db7b4839fc36cc5c95e66f7a6013799ee4cd7c5896d5524248b30c3fc1aedb398991eac100
7
+ data.tar.gz: 9c685311e79b68e507d8167171523f3f3e979032ae67068ee07dbd8f53e2d4c74006bccae19c156e9e99a4fd16a51259616a324aa399fb2d7ef6b38c206b8bba
data/.travis.yml CHANGED
@@ -4,3 +4,6 @@ rvm:
4
4
  - 2.3.3
5
5
  - 2.4.0
6
6
  before_install: gem install bundler -v 1.12.5
7
+ script:
8
+ - bundle exec rake test
9
+ - bundle exec querly test --config=sample.yaml
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.8.0 (2017-12-19)
6
+
7
+ * Make `[conditional]` be aware of safe-navigation-operator (@pocke) #30
8
+ * Make preprocessors be aware of `bundle exec`.
9
+ When `querly` is invoked with `bundle exec`, so are preprocessors, and vice vesa.
10
+ * Add `--rule` option for `querly check` to filter rules to test
11
+ * Print rule id in text output
12
+
5
13
  ## 0.7.0 (2017-08-22)
6
14
 
7
15
  * Add Wiki pages to repository in manual directory #25
data/lib/querly.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'pathname'
2
2
  require "yaml"
3
3
  require "rainbow"
4
- require "parser/current"
4
+ require "parser/ruby24"
5
5
  require "set"
6
6
  require "open3"
7
7
  require "active_support/inflector"
@@ -2,10 +2,12 @@ module Querly
2
2
  class Analyzer
3
3
  attr_reader :config
4
4
  attr_reader :scripts
5
+ attr_reader :rule
5
6
 
6
- def initialize(config:)
7
+ def initialize(config:, rule:)
7
8
  @config = config
8
9
  @scripts = []
10
+ @rule = rule
9
11
  end
10
12
 
11
13
  #
@@ -16,8 +18,10 @@ module Querly
16
18
  rules = config.rules_for_path(script.path)
17
19
  script.root_pair.each_subpair do |node_pair|
18
20
  rules.each do |rule|
19
- if rule.patterns.any? {|pattern| test_pair(node_pair, pattern) }
20
- yield script, rule, node_pair
21
+ if rule.match?(identifier: self.rule)
22
+ if rule.patterns.any? {|pattern| test_pair(node_pair, pattern) }
23
+ yield script, rule, node_pair
24
+ end
21
25
  end
22
26
  end
23
27
  end
data/lib/querly/cli.rb CHANGED
@@ -7,6 +7,7 @@ module Querly
7
7
  option :config, default: "querly.yml"
8
8
  option :root
9
9
  option :format, default: "text", type: :string, enum: %w(text json)
10
+ option :rule, type: :string
10
11
  def check(*paths)
11
12
  require 'querly/cli/formatter'
12
13
 
@@ -38,7 +39,7 @@ Specify configuration file by --config option.
38
39
  exit
39
40
  end
40
41
 
41
- analyzer = Analyzer.new(config: config)
42
+ analyzer = Analyzer.new(config: config, rule: options[:rule])
42
43
 
43
44
  ScriptEnumerator.new(paths: paths.empty? ? [Pathname.pwd] : paths.map {|path| Pathname(path) }, config: config).each do |path, script|
44
45
  case script
@@ -35,7 +35,7 @@ Querly #{VERSION}, interactive console
35
35
  def analyzer
36
36
  return @analyzer if @analyzer
37
37
 
38
- @analyzer = Analyzer.new(config: nil)
38
+ @analyzer = Analyzer.new(config: nil, rule: nil)
39
39
 
40
40
  ScriptEnumerator.new(paths: paths, config: nil).each do |path, script|
41
41
  case script
@@ -56,7 +56,7 @@ module Querly
56
56
  col = pair.node.loc.column
57
57
  message = rule.messages.first.split(/\n/).first
58
58
 
59
- STDOUT.puts "#{path}:#{line}:#{col}\t#{src}\t#{message}"
59
+ STDOUT.puts "#{path}:#{line}:#{col}\t#{src}\t#{message} (#{rule.id})"
60
60
  end
61
61
  end
62
62
 
@@ -136,11 +136,11 @@ module Querly
136
136
  end
137
137
 
138
138
  def test_pattern(pattern, example, expected:)
139
- analyzer = Analyzer.new(config: nil)
139
+ analyzer = Analyzer.new(config: nil, rule: nil)
140
140
 
141
141
  found = false
142
142
 
143
- node = Parser::CurrentRuby.parse(example)
143
+ node = Parser::Ruby24.parse(example)
144
144
  NodePair.new(node: node).each_subpair do |pair|
145
145
  if analyzer.test_pair(pair, pattern)
146
146
  found = true
@@ -44,6 +44,8 @@ module Querly
44
44
  node.equal? parent.children.first
45
45
  when :or
46
46
  node.equal? parent.children.first
47
+ when :csend
48
+ node.equal? parent.children.first
47
49
  else
48
50
  false
49
51
  end
@@ -19,8 +19,30 @@ module Querly
19
19
  end
20
20
 
21
21
  def run!(source_code)
22
- output, status = Open3.capture2({ 'RUBYOPT' => nil }, command, stdin_data: source_code)
23
- raise Error.new(status: status, command: command) unless status.success?
22
+ stdin_read, stdin_write = IO.pipe
23
+ stdout_read, stdout_write = IO.pipe
24
+
25
+ writer = Thread.new do
26
+ stdin_write.print source_code
27
+ stdin_write.close
28
+ end
29
+
30
+ output = ""
31
+
32
+ reader = Thread.new do
33
+ while (line = stdout_read.gets)
34
+ output << line
35
+ end
36
+ end
37
+
38
+ succeeded = system(command, in: stdin_read, out: stdout_write)
39
+ stdout_write.close
40
+
41
+ writer.join
42
+ reader.join
43
+
44
+ raise Error.new(status: $?, command: command) unless succeeded
45
+
24
46
  output
25
47
  end
26
48
  end
@@ -56,7 +56,7 @@ module Querly
56
56
  end
57
57
 
58
58
  def parser
59
- Parser::CurrentRuby.new(Builder.new).tap do |parser|
59
+ Parser::Ruby24.new(Builder.new).tap do |parser|
60
60
  parser.diagnostics.all_errors_are_fatal = true
61
61
  parser.diagnostics.ignore_warnings = true
62
62
  end
@@ -106,7 +106,7 @@ module Querly
106
106
  def string_value(token)
107
107
  value(token)
108
108
  end
109
-
109
+
110
110
  def emit_lambda
111
111
  true
112
112
  end
@@ -1,3 +1,3 @@
1
1
  module Querly
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
data/manual/patterns.md CHANGED
@@ -143,6 +143,27 @@ def f()
143
143
  end
144
144
  ```
145
145
 
146
+ # Interpolation Syntax
147
+
148
+ If you want to describe a pattern that can not be described with adove syntax, you can use interpolation as follows:
149
+
150
+ ```rb
151
+ id: find_by_abc_and_def
152
+ pattern:
153
+ subject: "'finder(...)"
154
+ where:
155
+ finder:
156
+ - /find_by_\w+\_.*/
157
+ - find_by_id
158
+ ```
159
+
160
+ It matches with `find_by_email_and_name(...)`.
161
+
162
+ - Meta variables `'finder` can occur only as method name
163
+ - Unused meta var definition i1s okay, but undefined meta var reference raises an error
164
+ - If value of meta var is a string `foo`, it matches send nodes with exactly same method name
165
+ - If value of meta var is a regexp `/foo/`, it matches send nodes with method name which `=~` the regexp
166
+
146
167
  # Difference from Ruby
147
168
 
148
169
  * Method call parenthesis cannot be omitted (if omitted, it means *any arguments*)
data/sample.yaml CHANGED
@@ -143,8 +143,6 @@ rules:
143
143
  after: "[].size"
144
144
  - after: "[].count(:x)"
145
145
  - after: "[].count {|x| x > 3 }"
146
- - before: "[].count(x)"
147
- after: "[].count"
148
146
 
149
147
  preprocessor:
150
148
  .slim: slimrb --compile
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: querly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.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: 2017-08-22 00:00:00.000000000 Z
11
+ date: 2017-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  version: '0'
207
207
  requirements: []
208
208
  rubyforge_project:
209
- rubygems_version: 2.6.10
209
+ rubygems_version: 2.6.8
210
210
  signing_key:
211
211
  specification_version: 4
212
212
  summary: Pattern Based Checking Tool for Ruby