rubocop-iotventure 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +9 -5
- data/lib/rubocop/cop/iotventure/schema_definition_per_response.rb +40 -0
- data/lib/rubocop/iotventure/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b8a1f840812e93ae9174569844d2aa5d0f76aa7992bb3644d952c062e6182df
|
4
|
+
data.tar.gz: 3991d6ec7f5d7ffce8ac15f6f774b1693ffaa793cee07c2fc6928acfbf78bf49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03cd8ba07eff16ae6291f202f3f9de70e8eead68bcfe15623edcdaf9a832ae370f4d3b4a316282162b2a5ee3db92adc636a68058a18c37318a11303548dbdbb3
|
7
|
+
data.tar.gz: 77de6184ef30e9ccd0473c16e5e9a75ad618df38bf57eb3c7a779f853c8bd8989499fb3ce12daccd64477eb5f6f7e1208f354fe43f9049189acd96a759197de3
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -12,11 +12,15 @@ gem 'rubocop-iotventure', require: false
|
|
12
12
|
|
13
13
|
And then execute:
|
14
14
|
|
15
|
-
|
15
|
+
```shell
|
16
|
+
bundle install
|
17
|
+
```
|
16
18
|
|
17
|
-
Or install it yourself
|
19
|
+
Or install it yourself using:
|
18
20
|
|
19
|
-
|
21
|
+
```shell
|
22
|
+
gem install rubocop-iotventure
|
23
|
+
```
|
20
24
|
|
21
25
|
## Usage
|
22
26
|
|
@@ -69,7 +73,7 @@ response 200, 'response description' do
|
|
69
73
|
end
|
70
74
|
```
|
71
75
|
|
72
|
-
This cop checks that there is exactly one top-level schema definition per response block
|
76
|
+
This cop checks that there is exactly one top-level schema definition per response block (except 204 No Content blocks, those should not have any schema definitions). Multiple or misplaced schema definitions might overwrite each other.
|
73
77
|
|
74
78
|
## Development
|
75
79
|
|
@@ -79,7 +83,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
79
83
|
|
80
84
|
## Contributing
|
81
85
|
|
82
|
-
Bug reports and pull requests are welcome on Bitbucket at https://bitbucket.org/iotventure/rubocop-iotventure
|
86
|
+
Bug reports and pull requests are welcome on Bitbucket at <https://bitbucket.org/iotventure/rubocop-iotventure>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://bitbucket.org/iotventure/rubocop-iotventure/src/master/CODE_OF_CONDUCT.md).
|
83
87
|
|
84
88
|
## License
|
85
89
|
|
@@ -43,6 +43,15 @@ module RuboCop
|
|
43
43
|
#
|
44
44
|
# @example
|
45
45
|
#
|
46
|
+
# # bad
|
47
|
+
#
|
48
|
+
# response 204, 'response description' do
|
49
|
+
# schema '$ref' => '#/components/schemas/object'
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
#
|
46
55
|
# # good
|
47
56
|
#
|
48
57
|
# response 200, 'response description' do
|
@@ -50,6 +59,14 @@ module RuboCop
|
|
50
59
|
# end
|
51
60
|
#
|
52
61
|
#
|
62
|
+
# @example
|
63
|
+
#
|
64
|
+
# # good
|
65
|
+
#
|
66
|
+
# response 204, 'response description' do
|
67
|
+
# end
|
68
|
+
#
|
69
|
+
#
|
53
70
|
class SchemaDefinitionPerResponse < Base
|
54
71
|
MISSING_MSG = 'Schema definition is missing for response declaration at %<current>s.'
|
55
72
|
DUPLICATED_MSG = 'Schema definition is defined both at %<first>s and %<second>s '\
|
@@ -58,6 +75,8 @@ module RuboCop
|
|
58
75
|
'but should be defined immediately after response declaration at %<other>s.'
|
59
76
|
MISPLACED_WITHOUT_RESPONSE_DEFINITION_MSG = 'Schema definition for %<schema_name>s is '\
|
60
77
|
'outside of response declaration.'
|
78
|
+
NO_CONTENT_SCHEMA_MSG = 'Schema definition for %<schema_name>s is defined at %<current>s, '\
|
79
|
+
'but 204 response should not have schema.'
|
61
80
|
|
62
81
|
# @!method response_block?(node)
|
63
82
|
def_node_matcher :response_block, <<~PATTERN
|
@@ -69,6 +88,18 @@ module RuboCop
|
|
69
88
|
)
|
70
89
|
PATTERN
|
71
90
|
|
91
|
+
# @!method no_content_response(node)
|
92
|
+
def_node_matcher :no_content_response, <<~PATTERN
|
93
|
+
(block
|
94
|
+
(send nil? :response
|
95
|
+
(:int 204)
|
96
|
+
(:str _)
|
97
|
+
...
|
98
|
+
)
|
99
|
+
...
|
100
|
+
)
|
101
|
+
PATTERN
|
102
|
+
|
72
103
|
# @!method schema_definition?(node)
|
73
104
|
def_node_matcher :schema_definition, <<~PATTERN
|
74
105
|
(send nil? :schema
|
@@ -119,6 +150,7 @@ module RuboCop
|
|
119
150
|
# that will be picked up by check_for_misplaced_schema
|
120
151
|
def check_schema_definition_count(node)
|
121
152
|
schema_definitions = schema_definitions(node)
|
153
|
+
return check_no_schemas(schema_definitions) if no_content_response(node)
|
122
154
|
|
123
155
|
return if schema_definitions.count == 1
|
124
156
|
|
@@ -127,6 +159,14 @@ module RuboCop
|
|
127
159
|
add_duplicated_offense(node, schema_definitions)
|
128
160
|
end
|
129
161
|
|
162
|
+
def check_no_schemas(schema_definitions)
|
163
|
+
schema_definitions.each do |schema_definition|
|
164
|
+
message = format(NO_CONTENT_SCHEMA_MSG, schema_name: find_schema_name(schema_definition),
|
165
|
+
current: source_location(schema_definition))
|
166
|
+
add_offense(schema_definition.loc.expression, message: message)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
130
170
|
def add_missing_offense(node)
|
131
171
|
message = format(MISSING_MSG, current: source_location(node))
|
132
172
|
add_offense(node.loc.expression, message: message)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-iotventure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fynn Starke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
161
|
requirements: []
|
162
|
-
rubygems_version: 3.3
|
162
|
+
rubygems_version: 3.2.3
|
163
163
|
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: Rswag cops.
|