rubocop-grape 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -11
- data/lib/rubocop/cop/grape/ivar.rb +35 -0
- data/lib/rubocop/cop/grape/params_position.rb +4 -4
- data/lib/rubocop/cop/grape_cops.rb +1 -0
- data/lib/rubocop/grape/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e2ad9ec7a76a877cde28f025cccbff00e561a5ce9678892cb36d84583f4cdb7
|
4
|
+
data.tar.gz: 0ddb3542ef0b046ff88328c2813626c19749541b5b760161d6df6d3c985fece3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cc9262ee02e74a134f7e0917ef9ba6fea99fe09c397b65ebb9d8c94c1f138a1cc44aef6d6995aee82689f791faca506c54f53a414618494298adb684b837252
|
7
|
+
data.tar.gz: 3d997bee7403959125be792b5e496d7280fdfad2273aafa5f55c3ce2e0554841aeac5e6de7841a6f88bcddcb44b574ad85e73dc8d507038a4c92ccf37bfd4588
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# RuboCop
|
1
|
+
# RuboCop Grape
|
2
2
|
|
3
|
-
|
3
|
+
[![Actions Status](https://github.com/kakubin/rubocop-grape/workflows/Ruby/badge.svg?branch=main)](https://github.com/kakubin/rubocop-grape/actions?query=workflow%3ARuby)
|
4
4
|
|
5
|
-
|
5
|
+
[RuboCop](https://github.com/rubocop/rubocop) extension for [Grape](https://rubygems.org/gems/grape/versions/0.16.2).
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -16,20 +16,30 @@ And then execute:
|
|
16
16
|
|
17
17
|
$ bundle install
|
18
18
|
|
19
|
-
|
19
|
+
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
You need to tell RuboCop to load the Grape extension. There are three
|
22
|
+
ways to do this:
|
22
23
|
|
23
|
-
|
24
|
+
### RuboCop configuration file
|
24
25
|
|
25
|
-
|
26
|
+
Put this into your `.rubocop.yml`.
|
26
27
|
|
27
|
-
|
28
|
+
```yaml
|
29
|
+
require: rubocop-grape
|
30
|
+
```
|
28
31
|
|
29
|
-
|
32
|
+
Alternatively, use the following array notation when specifying multiple extensions.
|
33
|
+
|
34
|
+
```yaml
|
35
|
+
require:
|
36
|
+
- rubocop-other-extension
|
37
|
+
- rubocop-grape
|
38
|
+
```
|
30
39
|
|
31
|
-
|
40
|
+
Now you can run `rubocop` and it will automatically load the RuboCop Grape
|
41
|
+
cops together with the standard cops.
|
32
42
|
|
33
43
|
## Contributing
|
34
44
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kakubin/rubocop-grape.
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Grape
|
6
|
+
# @example
|
7
|
+
# # bad
|
8
|
+
# ActiveRecord.with_readonly do
|
9
|
+
# @ivar = User.find(params[:user_id])
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# # good
|
13
|
+
# var = ActiveRecord.with_readonly do
|
14
|
+
# User.find(params[:user_id]
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# office = nil
|
19
|
+
# user = nil
|
20
|
+
#
|
21
|
+
# ActiveRecord.with_readonly do
|
22
|
+
# user = User.find(params[:user_id])
|
23
|
+
# office = user.office
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
class Ivar < Base
|
27
|
+
MSG = "Don't use instance_variable"
|
28
|
+
|
29
|
+
def on_ivasgn(node)
|
30
|
+
add_offense(node)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -27,20 +27,20 @@ module RuboCop
|
|
27
27
|
PATTERN
|
28
28
|
|
29
29
|
def_node_matcher :http_method_node?, <<~PATTERN
|
30
|
-
(block (send _ :get) ...)
|
30
|
+
(block (send _ {:get :post :put :patch :delete} ...) ...)
|
31
31
|
PATTERN
|
32
32
|
|
33
33
|
def on_block(node)
|
34
34
|
return unless http_method_node?(node)
|
35
35
|
|
36
|
-
|
36
|
+
collect_violating_nodes(node).each(&method(:add_offense))
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
39
|
+
def collect_violating_nodes(node, collector = [])
|
40
40
|
collector.push(node) if node.type == :block && params_block?(node)
|
41
41
|
|
42
42
|
node.children.each do |descendant|
|
43
|
-
|
43
|
+
collect_violating_nodes(descendant, collector) if descendant.is_a?(Parser::AST::Node)
|
44
44
|
end
|
45
45
|
|
46
46
|
collector
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-grape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akito Hikasa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- bin/console
|
45
45
|
- config/default.yml
|
46
46
|
- lib/rubocop-grape.rb
|
47
|
+
- lib/rubocop/cop/grape/ivar.rb
|
47
48
|
- lib/rubocop/cop/grape/params_position.rb
|
48
49
|
- lib/rubocop/cop/grape/route_param_type.rb
|
49
50
|
- lib/rubocop/cop/grape_cops.rb
|