boxt_rubocop 2.7.1 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/config/default.yml +4 -0
- data/lib/rubocop/cop/boxt/api_type_parameters.rb +65 -0
- data/lib/rubocop/cop/boxt_cops.rb +1 -0
- 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: 5088d5c0f8a597d082572e25832ca5f401a3e6487b8d944b606fd7162a612f90
|
4
|
+
data.tar.gz: 4791d465fddfc8c8a363a4fa9078cac6bf20655ec356c5f3ff8c075e96a9b51c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 434b1a3bd1911a39bfc0a5eb54ecb553fcd437ddb50d5892745f272e9fe241402a01d9e9a6de927b720bfa280364d30dc3392200bdcaea3be77c66c2c3e1b662
|
7
|
+
data.tar.gz: df1a0a656f781d196bd0cae1900bc5224cf8dea75af518cde5b3fcb4721f1fdbd16b0bda2898125ae1bb4e0682c052d7a2c9cb9a6349608970b3b58f2a8c8659
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.8.0
|
data/config/default.yml
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Boxt
|
6
|
+
# This cop ensures that each parameter in a Grape API has a type specified.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# requires :name
|
11
|
+
# optional :age
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# requires :name, type: String
|
15
|
+
# optional :age, type: Integer
|
16
|
+
#
|
17
|
+
class ApiTypeParameters < Cop
|
18
|
+
API_MESSAGE = "Ensure each parameter has a type specified, e.g., `type: String`."
|
19
|
+
ENTITY_MESSAGE = "Ensure each parameter has a type specified, e.g., `documentation: { type: String }`."
|
20
|
+
|
21
|
+
def_node_matcher :param_declaration, <<-PATTERN
|
22
|
+
(send nil? {:optional :requires :expose} _ $...)
|
23
|
+
PATTERN
|
24
|
+
|
25
|
+
def_node_search :param_with_type, <<-PATTERN
|
26
|
+
(send nil? {:optional :requires} _ (hash <(pair (sym :type) $_)>))
|
27
|
+
PATTERN
|
28
|
+
|
29
|
+
def_node_search :entity_with_type_documentation, <<-PATTERN
|
30
|
+
(send nil? :expose _ (hash <(pair (sym :documentation) (hash <(pair (sym :type) $_)>)) ...>))
|
31
|
+
PATTERN
|
32
|
+
|
33
|
+
def on_send(node)
|
34
|
+
param_declaration(node) do
|
35
|
+
next unless grape_api_class?(node) || grape_entity_class?(node)
|
36
|
+
|
37
|
+
if grape_api_class?(node) && param_with_type(node).none?
|
38
|
+
add_offense(node, message: API_MESSAGE)
|
39
|
+
elsif grape_entity_class?(node) && entity_with_type_documentation(node).none?
|
40
|
+
add_offense(node, message: ENTITY_MESSAGE)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def grape_api_class?(node)
|
48
|
+
grape_parent_class?(node, "Grape::API")
|
49
|
+
end
|
50
|
+
|
51
|
+
def grape_entity_class?(node)
|
52
|
+
grape_parent_class?(node, "Grape::Entity")
|
53
|
+
end
|
54
|
+
|
55
|
+
def grape_parent_class?(node, class_name)
|
56
|
+
node.each_ancestor(:class).any? do |ancestor|
|
57
|
+
ancestor.children.any? do |child|
|
58
|
+
child&.source == class_name
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boxt_rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boxt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/rubocop/boxt/inject.rb
|
112
112
|
- lib/rubocop/boxt/version.rb
|
113
113
|
- lib/rubocop/cop/boxt/api_path_format.rb
|
114
|
+
- lib/rubocop/cop/boxt/api_type_parameters.rb
|
114
115
|
- lib/rubocop/cop/boxt_cops.rb
|
115
116
|
- rails.yml
|
116
117
|
- rspec.yml
|
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
135
|
- !ruby/object:Gem::Version
|
135
136
|
version: '0'
|
136
137
|
requirements: []
|
137
|
-
rubygems_version: 3.5.
|
138
|
+
rubygems_version: 3.5.11
|
138
139
|
signing_key:
|
139
140
|
specification_version: 4
|
140
141
|
summary: Base Rubocop settings for all Boxt Ruby projects
|