querly 0.3.0.beta.1 → 0.3.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/README.md +21 -0
- data/lib/querly/config.rb +7 -0
- data/lib/querly/rules/sample.rb +1 -0
- data/lib/querly/version.rb +1 -1
- data/lib/querly.rb +14 -1
- data/rules/sample.yml +34 -0
- data/sample.yaml +2 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f3f39b82c237a02443b2af98cf6cf6fc756efaf
|
4
|
+
data.tar.gz: c22eab0318c79b835b5f58d000c9665dc807db8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65e67f8456628399a50129d351920fdf122bcda0c5550516e883e5300f4152cef6b223dc3a91fdbe83b02c8c3fe245eb685efd0c47e76571e99b1f269c8f1dce
|
7
|
+
data.tar.gz: 01a4612dac5af8cd3de0c6ae7322c11f51d716fd3d68af287f497ec32e2b244a053bb47bf80801e2a44f25102387c04a181dde8a14b88e913ae4409d04106173
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -94,6 +94,27 @@ Visit our wiki pages for configuration and query language reference.
|
|
94
94
|
|
95
95
|
Use `querly console` command to test patterns interactively.
|
96
96
|
|
97
|
+
## Requiring Rules
|
98
|
+
|
99
|
+
`import` section in config file now allows accepts `require` command.
|
100
|
+
|
101
|
+
```yaml
|
102
|
+
import:
|
103
|
+
- require: querly/rules/sample
|
104
|
+
- require: your_library/querly/rules
|
105
|
+
```
|
106
|
+
|
107
|
+
Querly ships with `querly/rules/sample` rule set. Check `lib/querly/rules/sample.rb` and `rules/sample.yml` for detail.
|
108
|
+
|
109
|
+
### Publishing Gems with Querly Rules
|
110
|
+
|
111
|
+
Querly provides `Querly.load_rule` API to allow publishing your rules as part of Ruby library.
|
112
|
+
Put rules YAML file in your gem, and add Ruby script in some directory like `lib/your_library/querly/rules.rb`.
|
113
|
+
|
114
|
+
```
|
115
|
+
Querly.load_rules File.join(__dir__, relative_path_to_yaml_file)
|
116
|
+
```
|
117
|
+
|
97
118
|
## Notes
|
98
119
|
|
99
120
|
### Querly's analysis is syntactic
|
data/lib/querly/config.rb
CHANGED
@@ -77,8 +77,15 @@ module Querly
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
80
|
+
|
81
|
+
if import["require"]
|
82
|
+
stderr.puts "Require rules from #{import["require"]}..."
|
83
|
+
require import["require"]
|
84
|
+
end
|
80
85
|
end
|
81
86
|
|
87
|
+
rules.concat Querly.required_rules
|
88
|
+
|
82
89
|
checks = Array(yaml["check"]).map {|hash| Check.load(hash) }
|
83
90
|
|
84
91
|
Config.new(rules: rules, preprocessors: preprocessors, checks: checks, root_dir: root_dir)
|
@@ -0,0 +1 @@
|
|
1
|
+
Querly.load_rule File.join(__dir__, "../../../rules/sample.yml")
|
data/lib/querly/version.rb
CHANGED
data/lib/querly.rb
CHANGED
@@ -23,5 +23,18 @@ require "querly/check"
|
|
23
23
|
require "querly/concerns/backtrace_formatter"
|
24
24
|
|
25
25
|
module Querly
|
26
|
-
|
26
|
+
@@required_rules = []
|
27
|
+
|
28
|
+
def self.required_rules
|
29
|
+
@@required_rules
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.load_rule(*files)
|
33
|
+
files.each do |file|
|
34
|
+
path = Pathname(file)
|
35
|
+
yaml = YAML.load(path.read)
|
36
|
+
rules = yaml.map {|hash| Rule.load(hash) }
|
37
|
+
required_rules.concat rules
|
38
|
+
end
|
39
|
+
end
|
27
40
|
end
|
data/rules/sample.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
- id: sample.ruby.pathname
|
2
|
+
pattern: Pathname.new
|
3
|
+
message: |
|
4
|
+
Did you mean `Pathname` method?
|
5
|
+
|
6
|
+
- id: sample.ruby.file.dir
|
7
|
+
pattern: "File.dirname(:string:)"
|
8
|
+
message: |
|
9
|
+
Did you mean `__dir__`?
|
10
|
+
|
11
|
+
- id: sample.ruby.file.open
|
12
|
+
pattern: File.open(...) !{}
|
13
|
+
message: |
|
14
|
+
Using block is better in Ruby
|
15
|
+
|
16
|
+
- id: sample.ruby.debug_print
|
17
|
+
pattern:
|
18
|
+
- self.p
|
19
|
+
- self.pp
|
20
|
+
message: |
|
21
|
+
Delete debug print
|
22
|
+
|
23
|
+
- id: sample.ruby.clone
|
24
|
+
pattern:
|
25
|
+
- clone()
|
26
|
+
- "clone(!freeze: _)"
|
27
|
+
message: |
|
28
|
+
Did you mean `dup`?
|
29
|
+
|
30
|
+
`clone` returns frozen object when receiver is frozen.
|
31
|
+
|
32
|
+
* If object is frozen, you usually does not need to clone it
|
33
|
+
* When you need a copy of a object, you provablly want to modify that; did you mean dup?
|
34
|
+
* Ruby 2.4 accepts freeze keyword and returns not frozen object
|
data/sample.yaml
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: querly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.0.beta.
|
4
|
+
version: 0.3.0.beta.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Soutaro Matsumoto
|
@@ -162,10 +162,12 @@ files:
|
|
162
162
|
- lib/querly/pp/cli.rb
|
163
163
|
- lib/querly/preprocessor.rb
|
164
164
|
- lib/querly/rule.rb
|
165
|
+
- lib/querly/rules/sample.rb
|
165
166
|
- lib/querly/script.rb
|
166
167
|
- lib/querly/script_enumerator.rb
|
167
168
|
- lib/querly/version.rb
|
168
169
|
- querly.gemspec
|
170
|
+
- rules/sample.yml
|
169
171
|
- sample.yaml
|
170
172
|
homepage: https://github.com/soutaro/querly
|
171
173
|
licenses: []
|