boxt_rubocop 0.0.46 → 0.0.47
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/default.yml +3 -0
- data/lib/boxt_rubocop.rb +3 -0
- data/lib/rubocop/cop/boxt/api_path_format.rb +57 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 231009180ee1b9b0868430b15b773ca50a8101ffb8a66a1398e5b1bb78f366fb
|
4
|
+
data.tar.gz: bdc82cf8a6f8bf3a928c088bd260b22bafbc4ed26db8e2a43b4b6fef3acbadde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffc8ad1b40e20af26e8075a98e8bea4dec62c049d7bf2fe5af26df988748a710ebcd4ca121ad698a95a2b61e0c312161296c8a500fc1e2a75c4ad9f4e8047ebc
|
7
|
+
data.tar.gz: 87b2a5ef84b0c422310df7b798b7a436b130869f80ff4588ec649c3808b22c18cac971bfc4e67b81a0286a8f827397bfbb3034aee947c06b47996c23ea675dc8
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.47
|
data/default.yml
CHANGED
data/lib/boxt_rubocop.rb
CHANGED
@@ -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.
|
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-
|
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
|