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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 278d6249e0070a8df23463f5a87e192723582d9b
4
- data.tar.gz: 7f25f0bec22cc8fa8dc715aaa1c151f917ddbe1a
3
+ metadata.gz: 4f3f39b82c237a02443b2af98cf6cf6fc756efaf
4
+ data.tar.gz: c22eab0318c79b835b5f58d000c9665dc807db8a
5
5
  SHA512:
6
- metadata.gz: 3fce9e93f1b3656ab76379d105eb5812694ebd21d812d3db673bc7d62c8ca8b1ddb57adc4500cf111c9c9bd29aafd37d7cb48b827806fb4cb130bd0ca8470893
7
- data.tar.gz: 406d47ca60ac29da0d1adae7c239e327fa71640bc713fc4cbc2fd2ef1488ba6a0154cc3619ab7c45ac1aa2b67cc75cc786efdfcd38cb056c999e73f3f44c3e2d
6
+ metadata.gz: 65e67f8456628399a50129d351920fdf122bcda0c5550516e883e5300f4152cef6b223dc3a91fdbe83b02c8c3fe245eb685efd0c47e76571e99b1f269c8f1dce
7
+ data.tar.gz: 01a4612dac5af8cd3de0c6ae7322c11f51d716fd3d68af287f497ec32e2b244a053bb47bf80801e2a44f25102387c04a181dde8a14b88e913ae4409d04106173
data/CHANGELOG.md CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  ## 0.3.0
6
6
 
7
+ * Allow `require` rules from config file
7
8
  * Add `version` command
8
9
  * Fix *with block* and *without block* pattern parsing
9
10
  * Prettier backtrace printing
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")
@@ -1,3 +1,3 @@
1
1
  module Querly
2
- VERSION = "0.3.0.beta.1"
2
+ VERSION = "0.3.0.beta.2"
3
3
  end
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
- # Your code goes here...
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
@@ -130,7 +130,8 @@ preprocessor:
130
130
  .slim: slimrb --compile
131
131
 
132
132
  import:
133
- - load: rules/*.yml
133
+ - load: querly/rules/*.yml
134
+ - require: querly/rules/sample
134
135
 
135
136
  check:
136
137
  - path: /
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.1
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: []