boxt_rubocop 2.7.0 → 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: 53fbb5f4de20cff58d51ab86564d09b454e510592e5cfce2d113e62833459140
4
- data.tar.gz: f8d793d8ce433d629e79b374cb9e0ee11c3875bed04a3abeba8bc34db0bfe2a2
3
+ metadata.gz: 5088d5c0f8a597d082572e25832ca5f401a3e6487b8d944b606fd7162a612f90
4
+ data.tar.gz: 4791d465fddfc8c8a363a4fa9078cac6bf20655ec356c5f3ff8c075e96a9b51c
5
5
  SHA512:
6
- metadata.gz: dfbb25c1d4919cf0d135afc1b250b145c030c2200ce1dd6834736b9b5542d1adffa25492949230e2dd9a1286a0939a808ef628db5e0b704e13e40f7442b51e1b
7
- data.tar.gz: f4eef4fc7bb2f091a8a90a561cbf29fa3602314a852a21c194b16a1620c8af6fc6aaef39a32bb0df2318f3d3bc9cade74bea2b76711da1d0e3e0e3d362bc36db
6
+ metadata.gz: 434b1a3bd1911a39bfc0a5eb54ecb553fcd437ddb50d5892745f272e9fe241402a01d9e9a6de927b720bfa280364d30dc3392200bdcaea3be77c66c2c3e1b662
7
+ data.tar.gz: df1a0a656f781d196bd0cae1900bc5224cf8dea75af518cde5b3fcb4721f1fdbd16b0bda2898125ae1bb4e0682c052d7a2c9cb9a6349608970b3b58f2a8c8659
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.7.0
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.0
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-04 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
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 2.30.0
89
+ version: 2.31.0
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: 2.30.0
96
+ version: 2.31.0
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.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