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 +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +8 -0
- data/lib/querly.rb +1 -1
- data/lib/querly/analyzer.rb +7 -3
- data/lib/querly/cli.rb +2 -1
- data/lib/querly/cli/console.rb +1 -1
- data/lib/querly/cli/formatter.rb +1 -1
- data/lib/querly/cli/test.rb +2 -2
- data/lib/querly/pattern/kind.rb +2 -0
- data/lib/querly/preprocessor.rb +24 -2
- data/lib/querly/script_enumerator.rb +2 -2
- data/lib/querly/version.rb +1 -1
- data/manual/patterns.md +21 -0
- data/sample.yaml +0 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a98ed1029750241af4e9b51f823e58742290ec6
|
4
|
+
data.tar.gz: 58cddad4c97eeef01447dcc0cc0751a8c9483176
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21906e1368f509bd343621ee669ab215b8509e591d268d4731bf01db7b4839fc36cc5c95e66f7a6013799ee4cd7c5896d5524248b30c3fc1aedb398991eac100
|
7
|
+
data.tar.gz: 9c685311e79b68e507d8167171523f3f3e979032ae67068ee07dbd8f53e2d4c74006bccae19c156e9e99a4fd16a51259616a324aa399fb2d7ef6b38c206b8bba
|
data/.travis.yml
CHANGED
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
data/lib/querly/analyzer.rb
CHANGED
@@ -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.
|
20
|
-
|
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
|
data/lib/querly/cli/console.rb
CHANGED
@@ -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
|
data/lib/querly/cli/formatter.rb
CHANGED
data/lib/querly/cli/test.rb
CHANGED
@@ -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::
|
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
|
data/lib/querly/pattern/kind.rb
CHANGED
data/lib/querly/preprocessor.rb
CHANGED
@@ -19,8 +19,30 @@ module Querly
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def run!(source_code)
|
22
|
-
|
23
|
-
|
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::
|
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
|
data/lib/querly/version.rb
CHANGED
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
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.
|
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-
|
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.
|
209
|
+
rubygems_version: 2.6.8
|
210
210
|
signing_key:
|
211
211
|
specification_version: 4
|
212
212
|
summary: Pattern Based Checking Tool for Ruby
|