rubocop-grape 0.2.1 → 0.3.0
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 +6 -0
- data/lib/rubocop/cop/grape/field_name.rb +78 -0
- data/lib/rubocop/cop/grape_cops.rb +1 -0
- data/lib/rubocop/grape/grape_files.rb +2 -2
- data/lib/rubocop/grape/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4f465c44799edf9ecb17a837d1e85bde5b628c29cb15aad03131878f9c46760
|
4
|
+
data.tar.gz: 8b788b780a6503f2ee4fd540271221c88d644a3616d8f21f0c3033a151a80e2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c17941eb7ca48f32fbc0d3f53654a8917c847b00df6b1145aab1093ef86be29e628bec85c3d35400208ebc7c19374dc15f8649568506564d9749202875232539
|
7
|
+
data.tar.gz: 0f2163c4f45959cce98ce8682ddc4f188ff642559e62085bcd09fd0b32b764f2d983e1830aae338e1cb510e83923349886d7185e6cf5cb1b0edd61b0b23265e6
|
data/config/default.yml
CHANGED
@@ -0,0 +1,78 @@
|
|
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
|
+
find_field_node(body)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def find_field_node(node)
|
55
|
+
case node.type
|
56
|
+
when :begin
|
57
|
+
node.each_child_node(&method(:find_field_node))
|
58
|
+
when :block
|
59
|
+
find_field_node(node.send_node)
|
60
|
+
find_field_node(node.body)
|
61
|
+
else
|
62
|
+
check_field_name(node)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def check_field_name(node)
|
67
|
+
return unless (field_name = field_name(node))
|
68
|
+
|
69
|
+
check_name(node, field_name, node.first_argument.source_range)
|
70
|
+
end
|
71
|
+
|
72
|
+
def message(style)
|
73
|
+
format(MSG, style: style)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -26,11 +26,11 @@ module RuboCop
|
|
26
26
|
@config.for_all_cops['GrapeDir']
|
27
27
|
end
|
28
28
|
|
29
|
-
def roundup_relevant_cops(
|
29
|
+
def roundup_relevant_cops(processed_source)
|
30
30
|
super.select do |cop|
|
31
31
|
next true unless cop.class.name.match?(/RuboCop::Cop::Grape::.+$/)
|
32
32
|
|
33
|
-
grape_files.include?(
|
33
|
+
grape_files.include?(processed_source.path)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
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.3.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: 2023-
|
11
|
+
date: 2023-04-15 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/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
|
@@ -75,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
76
|
- !ruby/object:Gem::Version
|
76
77
|
version: '0'
|
77
78
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.2.33
|
79
80
|
signing_key:
|
80
81
|
specification_version: 4
|
81
82
|
summary: Automatice Grape code style checking tool.
|