rubocop-grape 0.3.0 → 0.4.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: f4f465c44799edf9ecb17a837d1e85bde5b628c29cb15aad03131878f9c46760
4
- data.tar.gz: 8b788b780a6503f2ee4fd540271221c88d644a3616d8f21f0c3033a151a80e2e
3
+ metadata.gz: d1ddcfa8ca8f07c8b82d051f1b962d106b7e9390f505bce166901deb3d9421c4
4
+ data.tar.gz: c7de3f5ff9600b83a730d347278e52d0f3f4553389c184b2c04be425193079b3
5
5
  SHA512:
6
- metadata.gz: c17941eb7ca48f32fbc0d3f53654a8917c847b00df6b1145aab1093ef86be29e628bec85c3d35400208ebc7c19374dc15f8649568506564d9749202875232539
7
- data.tar.gz: 0f2163c4f45959cce98ce8682ddc4f188ff642559e62085bcd09fd0b32b764f2d983e1830aae338e1cb510e83923349886d7185e6cf5cb1b0edd61b0b23265e6
6
+ metadata.gz: 204e3c444825e10ab0c90bdfbb3dac71db90d5aeb56a718a6124ef1b19a3883e93e5815131aefbc8bcc8ba5c20d46c2bdf987f145914167299a33f7cbf95fd44
7
+ data.tar.gz: 02ebbff3326f417c71983683ed98aa7a414e9a2d3456b671b4a5fe7f19ae4cb84ccb42723f47ee1ed5085f359d6fb70557b1703045f053430e4726c32417f80a
data/config/default.yml CHANGED
@@ -1,6 +1,18 @@
1
1
  AllCops:
2
2
  GrapeDir: 'app/api'
3
3
 
4
+ Grape/AbcSize:
5
+ Description: >-
6
+ A calculated magnitude based on number of assignments,
7
+ branches, and conditions.
8
+ Reference:
9
+ - http://c2.com/cgi/wiki?AbcMetric
10
+ - https://en.wikipedia.org/wiki/ABC_Software_Metric
11
+ - https://www.rubydoc.info/gems/rubocop/0.27.0/RuboCop/Cop/Metrics/AbcSize
12
+ Enabled: true
13
+ Max: 20
14
+ CountRepeatedAttributes: true
15
+
4
16
  Grape/FieldName:
5
17
  EnforcedStyle: snake_case
6
18
  SupportedStyles:
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Grape
6
+ # Checks that the ABC size of endpoints is not higher than the
7
+ # configured maximum. The ABC size is based on assignments, branches
8
+ # (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
9
+ # and https://en.wikipedia.org/wiki/ABC_Software_Metric.
10
+ class AbcSize < Base
11
+ extend ExcludeLimit
12
+
13
+ exclude_limit 'Max'
14
+
15
+ MSG = 'Assignment Branch Condition size is too high. [%<abc_vector>s %<complexity>d/%<max>d]'
16
+
17
+ def_node_matcher :http_method_node?, <<~PATTERN
18
+ (block (send _ {:get :post :put :patch :delete} ...) ...)
19
+ PATTERN
20
+
21
+ def on_block(node)
22
+ return unless http_method_node?(node)
23
+
24
+ check_complexity(node)
25
+ end
26
+
27
+ def check_complexity(node)
28
+ return unless node.body
29
+
30
+ max = cop_config['Max']
31
+ complexity, abc_vector = complexity(node.body)
32
+ return unless complexity > max
33
+
34
+ msg = format(self.class::MSG, abc_vector: abc_vector, complexity: complexity, max: max)
35
+ add_offense(node, message: msg) { self.max = complexity.ceil }
36
+ end
37
+
38
+ def complexity(node)
39
+ Metrics::Utils::AbcSizeCalculator.calculate(
40
+ node,
41
+ discount_repeated_attributes: !cop_config['CountRepeatedAttributes']
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'grape/abc_size'
3
4
  require_relative 'grape/field_name'
4
5
  require_relative 'grape/ivar'
5
6
  require_relative 'grape/params_position'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Grape
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akito Hikasa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-15 00:00:00.000000000 Z
11
+ date: 2023-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -44,6 +44,7 @@ files:
44
44
  - bin/console
45
45
  - config/default.yml
46
46
  - lib/rubocop-grape.rb
47
+ - lib/rubocop/cop/grape/abc_size.rb
47
48
  - lib/rubocop/cop/grape/field_name.rb
48
49
  - lib/rubocop/cop/grape/ivar.rb
49
50
  - lib/rubocop/cop/grape/params_position.rb