boxt_rubocop 0.0.45 → 0.0.47

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: 17e079e65f94c9d1e35fcefbc01e6a34d4b8fcf5a5a9ede2d649b234989e6140
4
- data.tar.gz: 49c0000d511c4625d0b0f925f66c1169d414af8ec3948cd370a4dc693b762b76
3
+ metadata.gz: 231009180ee1b9b0868430b15b773ca50a8101ffb8a66a1398e5b1bb78f366fb
4
+ data.tar.gz: bdc82cf8a6f8bf3a928c088bd260b22bafbc4ed26db8e2a43b4b6fef3acbadde
5
5
  SHA512:
6
- metadata.gz: ec2e8aa35dd5ca47b6dbe074bb9a44d16291eccfa97c2f0b52e96ee27a030635c7c5cb68eda4d488102805f17e53d44ebec1aca907879dd49714b7150b4b2ba4
7
- data.tar.gz: 0420b40f55772a41f3a3d977de867e8a7db4d917ea10f07726471ebd2f3d045f34cb9c359e2fa9722a4fc7aa93adb98aa52d6721e25c887c0e486fceeb273cc8
6
+ metadata.gz: ffc8ad1b40e20af26e8075a98e8bea4dec62c049d7bf2fe5af26df988748a710ebcd4ca121ad698a95a2b61e0c312161296c8a500fc1e2a75c4ad9f4e8047ebc
7
+ data.tar.gz: 87b2a5ef84b0c422310df7b798b7a436b130869f80ff4588ec649c3808b22c18cac971bfc4e67b81a0286a8f827397bfbb3034aee947c06b47996c23ea675dc8
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.45
1
+ 0.0.47
data/default.yml CHANGED
@@ -1,3 +1,6 @@
1
+ require:
2
+ - ./lib/rubocop/cop/boxt/api_path_format.rb
3
+
1
4
  AllCops:
2
5
  Exclude:
3
6
  - "**/*/schema.rb"
data/lib/boxt_rubocop.rb CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  require "boxt_rubocop/version"
4
4
 
5
+ # Require all custom cops defined in rubocop/cop/**/*.rb
6
+ Dir[File.join(__dir__, "rubocop", "cop", "**", "*.rb")].sort.each { |file| require file }
7
+
5
8
  module BoxtRubocop
6
9
  module_function
7
10
 
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Boxt
8
+ # Clients expect to interface with our API using kebab-case.
9
+ #
10
+ # This cop ensures that our API paths are formatted using the correct case.
11
+ #
12
+ # Underscores are acceptable in path variables (e.g. "/path/:path_id/update")
13
+ #
14
+ # API style guide: https://github.com/boxt/boxt-docs/blob/main/coding-styles/api.md#camel-cased-endpoints
15
+ #
16
+ # @example
17
+ # # bad
18
+ # post "/admin/orders/:order_id/contact_details/update"
19
+ # get "/installation_days"
20
+ # namespace "password_resets"
21
+ # namespace :password_resets
22
+ #
23
+ # # good
24
+ # post "/admin/orders/:order_id/contact-details/update"
25
+ # get "/installation-days"
26
+ # namespace "password-resets"
27
+ #
28
+ class ApiPathFormat < ::RuboCop::Cop::Base
29
+ def_node_matcher :path_defining_method_with_string_path, <<~PATTERN
30
+ (send nil? {:post | :get | :namespace} (:str $_))
31
+ PATTERN
32
+
33
+ def_node_matcher :namespace_with_symbol, <<~PATTERN
34
+ (send nil? :namespace (:sym $_))
35
+ PATTERN
36
+
37
+ MSG = "Use kebab-case for the API path"
38
+
39
+ def on_send(node)
40
+ path_defining_method_with_string_path(node) do |path|
41
+ add_offense(node) if path_name_does_not_follow_kebab_case?(path)
42
+ end
43
+
44
+ namespace_with_symbol(node) do |path|
45
+ add_offense(node) if path.to_s.include?("_")
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def path_name_does_not_follow_kebab_case?(path)
52
+ path.split("/").any? { |split| !split.start_with?(":") && split.include?("_") }
53
+ end
54
+ end
55
+ end
56
+ end
57
+ 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: 0.0.45
4
+ version: 0.0.47
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boxt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-24 00:00:00.000000000 Z
11
+ date: 2023-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.56.1
19
+ version: 1.56.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 1.56.1
26
+ version: 1.56.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubocop-faker
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 1.19.0
47
+ version: 1.19.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.19.0
54
+ version: 1.19.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop-rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 2.20.2
61
+ version: 2.21.1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 2.20.2
68
+ version: 2.21.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop-rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 2.23.2
89
+ version: 2.24.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.23.2
96
+ version: 2.24.0
97
97
  description: Base Rubocop settings for all Boxt Ruby projects
98
98
  email:
99
99
  - developers@boxt.co.uk
@@ -108,6 +108,7 @@ files:
108
108
  - default.yml
109
109
  - lib/boxt_rubocop.rb
110
110
  - lib/boxt_rubocop/version.rb
111
+ - lib/rubocop/cop/boxt/api_path_format.rb
111
112
  - rails.yml
112
113
  - rspec.yml
113
114
  homepage: https://github.com/boxt/boxt_rubocop