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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da4431fc2e5dd61c47c41cc3e600a32dfdedbd9910fce42f83826ad1ae7a4901
4
- data.tar.gz: 5a3e6f1865866d306b64c3e7273919f7b86ae75fbbcf3c76a2c2d7102c7fe8ff
3
+ metadata.gz: 5088d5c0f8a597d082572e25832ca5f401a3e6487b8d944b606fd7162a612f90
4
+ data.tar.gz: 4791d465fddfc8c8a363a4fa9078cac6bf20655ec356c5f3ff8c075e96a9b51c
5
5
  SHA512:
6
- metadata.gz: 6982d5c1a949cda60701aecc3dedb3db9d1d7ddad288d5a99f573a803cf3a5a79af0a9779f0b84cb8ae55b07d0fc39a661441692f5d5bca909f55f8f49d52f8a
7
- data.tar.gz: '0129159bc386f8426e2135844a53e21c2c320b0145d2d10444abccc89c9ba271949f57563c2705ef03a48f3133c361fb8c5a060519b6a666b7d50f9e36c3157e'
6
+ metadata.gz: 434b1a3bd1911a39bfc0a5eb54ecb553fcd437ddb50d5892745f272e9fe241402a01d9e9a6de927b720bfa280364d30dc3392200bdcaea3be77c66c2c3e1b662
7
+ data.tar.gz: df1a0a656f781d196bd0cae1900bc5224cf8dea75af518cde5b3fcb4721f1fdbd16b0bda2898125ae1bb4e0682c052d7a2c9cb9a6349608970b3b58f2a8c8659
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.7.1
1
+ 2.8.0
data/config/default.yml CHANGED
@@ -11,6 +11,10 @@ Boxt/ApiPathFormat:
11
11
  Description: 'Ensure that the API path uses kebab case'
12
12
  Enabled: false
13
13
 
14
+ Boxt/ApiTypeParameters:
15
+ Description: 'Ensure that API parameters are typed'
16
+ Enabled: false
17
+
14
18
  Layout/ClassStructure:
15
19
  Enabled: true
16
20
 
@@ -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
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "boxt/api_path_format"
4
+ require_relative "boxt/api_type_parameters"
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.7.1
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-13 00:00:00.000000000 Z
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.9
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