boxt_rubocop 2.7.1 → 2.9.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 +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efbb89d5e5ebcae88178adc5256bd18f0c5faa4b8857e5e670484c9f4b19ec0b
|
4
|
+
data.tar.gz: 55d39a7885b15dd4af2da827c487f47d719133c853a40ff6676ddb6cda160595
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f339f801d1c2bccb817933d83febb732547a84cd8e0c2e123dc3d53924312810d85f52e06d5f98452212b6127ee9a84efaff048af80e3f1db3a6082b68b35f73
|
7
|
+
data.tar.gz: 5b58de10c91b936bbe5ab9f58fcf3992a994d95f0fc80551e3ded6b65c842c36f1e9b99044d134ad4e297790ea485837c7caf9c30d4e6b5d5338b4fbca772d11
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.9.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.9.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-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.21.
|
47
|
+
version: 1.21.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.21.
|
54
|
+
version: 1.21.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rubocop-rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - '='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 3.0.1
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 3.0.1
|
97
97
|
description: Base Rubocop settings for all Boxt Ruby projects
|
98
98
|
email:
|
99
99
|
- developers@boxt.co.uk
|
@@ -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
|