Class: RuboCop::Cop::Boxt::ApiPathFormat

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/boxt/api_path_format.rb

Overview

Clients expect to interface with our API using kebab-case.

This cop ensures that our API paths are formatted using the correct case.

Underscores are acceptable in path variables (e.g. “/path/:path_id/update”)

API style guide: github.com/boxt/boxt-docs/blob/main/coding-styles/api.md#camel-cased-endpoints

Examples:

# bad
post "/admin/orders/:order_id/contact_details/update"
get  "/installation_days"
namespace "password_resets"
namespace :password_resets

# good
post "/admin/orders/:order_id/contact-details/update"
get  "/installation-days"
namespace "password-resets"

Constant Summary collapse

MSG =
"Use kebab-case for the API path"

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/rubocop/cop/boxt/api_path_format.rb', line 37

def on_send(node)
  path_defining_method_with_string_path(node) do |path|
    add_offense(node) if path_name_does_not_follow_kebab_case?(path)
  end

  namespace_with_symbol(node) do |path|
    add_offense(node) if path.to_s.include?("_")
  end
end