rubocop-grape 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +9 -0
- data/lib/rubocop/cop/grape/field_name.rb +69 -0
- data/lib/rubocop/cop/grape_cops.rb +1 -0
- data/lib/rubocop/grape/grape_files.rb +39 -0
- data/lib/rubocop/grape/version.rb +1 -1
- data/lib/rubocop-grape.rb +2 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92c8005ffcb25101074781a0e8ef2dde2eec522fe78d8c8a56c2b4bc19f0ecec
|
4
|
+
data.tar.gz: 91e7e2fa44a245223f72235c9655a9d124232f09ecb27eb32bae8a7d01725294
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6becb4f74dcfaa3c922a5c4aab58f4b540286f412c2d4c697aea3bfe69ce16d32ce795b0944b7e1401fd8ed98aa0f779a95d54ce7a1e51b053084cf4bafcd8d9
|
7
|
+
data.tar.gz: 507a763177ce9a01c1b50fbe067a37c40673c673a469daea3d3c6180dedeac16671e87bbbb3c2b64c625be599dcc020ebacd964804dad6d26f6206915038a864
|
data/config/default.yml
CHANGED
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Grape
|
6
|
+
# @example EnforcedStyle: snake_case (default)
|
7
|
+
# # bad
|
8
|
+
# params do
|
9
|
+
# requires :userName
|
10
|
+
# optional :phoneNumber
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# params do
|
15
|
+
# requires :user_name
|
16
|
+
# optional :phone_number
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# @example EnforcedStyle: camelCase
|
20
|
+
# # bad
|
21
|
+
# params do
|
22
|
+
# requires :user_name
|
23
|
+
# optional :phone_number
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# # good
|
27
|
+
# params do
|
28
|
+
# requires :userName
|
29
|
+
# optional :phoneNumber
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
class FieldName < Base
|
33
|
+
include ConfigurableNaming
|
34
|
+
include RangeHelp
|
35
|
+
|
36
|
+
MSG = 'Use %<style>s for field names.'
|
37
|
+
|
38
|
+
def_node_matcher :params_block?, <<~PATTERN
|
39
|
+
(block (send _ :params) _ $_)
|
40
|
+
PATTERN
|
41
|
+
|
42
|
+
def_node_matcher :field_name, <<~PATTERN
|
43
|
+
(send _ {:requires :optional} (sym $_) ...)
|
44
|
+
PATTERN
|
45
|
+
|
46
|
+
def on_block(node)
|
47
|
+
return unless (body = params_block?(node))
|
48
|
+
|
49
|
+
if body.type == :begin
|
50
|
+
body.children.each(&method(:check_field_name))
|
51
|
+
else
|
52
|
+
check_field_name(body)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def check_field_name(node)
|
59
|
+
field = node.children[2]
|
60
|
+
check_name(node, field_name(node), field.source_range)
|
61
|
+
end
|
62
|
+
|
63
|
+
def message(style)
|
64
|
+
format(MSG, style: style)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Grape
|
6
|
+
# This is a monkey patch for RuboCop
|
7
|
+
# which makes rubocop-grape cops adapted only for grape files.
|
8
|
+
module GrapeFile
|
9
|
+
DEFAULT_GRAPE_DIR = 'app/api'
|
10
|
+
|
11
|
+
def grape_dir
|
12
|
+
@grape_dir ||= load_grape_file_from_config || DEFAULT_GRAPE_DIR
|
13
|
+
end
|
14
|
+
|
15
|
+
def grape_files
|
16
|
+
@grape_files ||= Dir.glob('**/*.rb', base: grape_dir).map do |relative_path|
|
17
|
+
File.absolute_path(relative_path, grape_dir)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Team.prepend self
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def load_grape_file_from_config
|
26
|
+
@config.for_all_cops['GrapeDir']
|
27
|
+
end
|
28
|
+
|
29
|
+
def roundup_relevant_cops(filename)
|
30
|
+
super.select do |cop|
|
31
|
+
next true unless cop.class.name.match?(/RuboCop::Cop::Grape::.+$/)
|
32
|
+
|
33
|
+
grape_files.include?(filename)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/rubocop-grape.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akito Hikasa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -44,11 +44,13 @@ files:
|
|
44
44
|
- bin/console
|
45
45
|
- config/default.yml
|
46
46
|
- lib/rubocop-grape.rb
|
47
|
+
- lib/rubocop/cop/grape/field_name.rb
|
47
48
|
- lib/rubocop/cop/grape/ivar.rb
|
48
49
|
- lib/rubocop/cop/grape/params_position.rb
|
49
50
|
- lib/rubocop/cop/grape/route_param_type.rb
|
50
51
|
- lib/rubocop/cop/grape_cops.rb
|
51
52
|
- lib/rubocop/grape.rb
|
53
|
+
- lib/rubocop/grape/grape_files.rb
|
52
54
|
- lib/rubocop/grape/inject.rb
|
53
55
|
- lib/rubocop/grape/version.rb
|
54
56
|
homepage: https://github.com/kakubin/rubocop-grape
|
@@ -74,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
76
|
- !ruby/object:Gem::Version
|
75
77
|
version: '0'
|
76
78
|
requirements: []
|
77
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.2.33
|
78
80
|
signing_key:
|
79
81
|
specification_version: 4
|
80
82
|
summary: Automatice Grape code style checking tool.
|