boxt_rubocop 0.0.46 → 0.0.47

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa5d1260e94c7453988486a997b27b365683b5d3d7882790a16ed1e2f01379dd
4
- data.tar.gz: 16d46fc9f195a2202aee79dfa07843646becc222b5f149708cda9c7bed7be360
3
+ metadata.gz: 231009180ee1b9b0868430b15b773ca50a8101ffb8a66a1398e5b1bb78f366fb
4
+ data.tar.gz: bdc82cf8a6f8bf3a928c088bd260b22bafbc4ed26db8e2a43b4b6fef3acbadde
5
5
  SHA512:
6
- metadata.gz: 44f9204e8bc18bf304f0fd1ac76838a112ee77deed65352cde3a621abc15b61a7a7480e84cb41616cd28e3f0b7859ed04a1179207153f98d6a362965e560ddd8
7
- data.tar.gz: '085b6047775c0413aefbf1fba1d118bb9ac063ac2e9d0c91915d04462700c2d0b374a974b4e1b4ce8c12b60801531cd813087a824af0e348efcd28fd58faba28'
6
+ metadata.gz: ffc8ad1b40e20af26e8075a98e8bea4dec62c049d7bf2fe5af26df988748a710ebcd4ca121ad698a95a2b61e0c312161296c8a500fc1e2a75c4ad9f4e8047ebc
7
+ data.tar.gz: 87b2a5ef84b0c422310df7b798b7a436b130869f80ff4588ec649c3808b22c18cac971bfc4e67b81a0286a8f827397bfbb3034aee947c06b47996c23ea675dc8
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.46
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.46
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-09-19 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
@@ -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