Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 5 additions & 166 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
# Use Shopify's Rubocop config as a baseline.
inherit_gem:
rubocop-shopify: rubocop.yml
rubocop-rails-omakase: rubocop.yml

AllCops:
Exclude:
- test/db/schema.rb
- test/db/queue_schema.rb
- test/db/*schema.rb
- vendor
SuggestExtensions: false
NewCops: disable
TargetRubyVersion: 3.2

# Layout

Layout/ArgumentAlignment:
Enabled: true
EnforcedStyle: with_fixed_indentation

Layout/ArrayAlignment:
Enabled: true
EnforcedStyle: with_fixed_indentation

Layout/FirstMethodArgumentLineBreak:
Enabled: true

Layout/FirstMethodParameterLineBreak:
Enabled: true

Layout/LineLength:
Enabled: true
Expand All @@ -34,148 +14,6 @@ Layout/LineLength:
# Allow long comments.
- "^#.*"

Layout/EndAlignment:
Enabled: true
EnforcedStyleAlignWith: start_of_line

Layout/ExtraSpacing:
Enabled: true
AllowForAlignment: false
AllowBeforeTrailingComments: true

Layout/MultilineAssignmentLayout:
Enabled: true
EnforcedStyle: same_line

Layout/MultilineHashBraceLayout:
Enabled: true
EnforcedStyle: new_line

Layout/MultilineHashKeyLineBreaks:
Enabled: true

Layout/MultilineMethodArgumentLineBreaks:
Enabled: true

Layout/MultilineMethodCallBraceLayout:
Enabled: true
EnforcedStyle: new_line

Layout/SpaceAroundEqualsInParameterDefault:
Enabled: true
EnforcedStyle: no_space

Layout/SpaceInLambdaLiteral:
Enabled: true
EnforcedStyle: require_no_space

Layout/SpaceInsideArrayLiteralBrackets:
Enabled: true
EnforcedStyle: no_space

Layout/SpaceInsideArrayPercentLiteral:
Enabled: true

Layout/SpaceInsideBlockBraces:
Enabled: true
EnforcedStyle: space
EnforcedStyleForEmptyBraces: no_space
SpaceBeforeBlockParameters: true

Layout/SpaceInsideHashLiteralBraces:
Enabled: true
EnforcedStyle: no_space

Layout/SpaceInsideParens:
Enabled: true
EnforcedStyle: no_space

Layout/SpaceInsidePercentLiteralDelimiters:
Enabled: true

Layout/SpaceInsideRangeLiteral:
Enabled: true

Layout/SpaceInsideReferenceBrackets:
Enabled: true
EnforcedStyle: no_space

Layout/SpaceInsideStringInterpolation:
Enabled: true
EnforcedStyle: no_space

# Linting

Lint/AssignmentInCondition:
Enabled: false

Lint/SuppressedException:
Enabled: false

# Metrics

Metrics/BlockNesting:
Enabled: false

# Naming

Naming/AccessorMethodName:
Enabled: false

Naming/InclusiveLanguage:
Enabled: false

Naming/PredicateName:
Enabled: false

# Style

Style/BlockDelimiters:
Enabled: false

Style/ClassAndModuleChildren:
Enabled: false

Style/ClassMethodsDefinitions:
Enabled: false

Style/CommandLiteral:
Enabled: false

Style/ConditionalAssignment:
Enabled: false

Style/DateTime:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false

Style/IfInsideElse:
Enabled: false

Style/MultilineTernaryOperator:
Enabled: false

Style/NestedTernaryOperator:
Enabled: false

Style/RedundantReturn:
Enabled: false

Style/RedundantSelf:
Enabled: false

Style/RegexpLiteral:
Enabled: false

Style/ReturnNil:
Enabled: false

Style/TrailingCommaInArguments:
Enabled: true
EnforcedStyleForMultiline: comma

Style/TrailingCommaInArrayLiteral:
Enabled: true
EnforcedStyleForMultiline: comma
Expand All @@ -184,5 +22,6 @@ Style/TrailingCommaInHashLiteral:
Enabled: true
EnforcedStyleForMultiline: comma

Style/WordArray:
Enabled: false
Style/TrailingCommaInArguments:
Enabled: true
EnforcedStyleForMultiline: comma
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ group :development do
gem "foreman"
gem "listen"
gem "pry-rails"
gem "rubocop-shopify", require: false
gem "rubocop-rails-omakase", require: false
gem "ruby-lsp", require: false
gem "web-console"

Expand Down
20 changes: 16 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,20 @@ GEM
rubocop-ast (1.44.1)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-shopify (2.17.0)
rubocop (~> 1.62)
rubocop-performance (1.25.0)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
rubocop-rails (2.31.0)
activesupport (>= 4.2.0)
lint_roller (~> 1.1)
rack (>= 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
rubocop-rails-omakase (1.1.0)
rubocop (>= 1.72)
rubocop-performance (>= 1.24)
rubocop-rails (>= 2.30)
ruby-lsp (0.23.17)
language_server-protocol (~> 3.17.0)
prism (>= 1.2, < 2.0)
Expand Down Expand Up @@ -324,7 +336,7 @@ GEM
fugit (~> 1.11.0)
railties (>= 7.1)
thor (~> 1.3.1)
sorbet-runtime (0.5.12070)
sorbet-runtime (0.5.12079)
sqlite3 (2.6.0-arm64-darwin)
sqlite3 (2.6.0-x86_64-darwin)
sqlite3 (2.6.0-x86_64-linux-gnu)
Expand Down Expand Up @@ -389,7 +401,7 @@ DEPENDENCIES
rake
ransack (>= 4.0)
rest_framework!
rubocop-shopify
rubocop-rails-omakase
ruby-lsp
sentry-rails
simplecov
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ task :maintain_assets do
assets_dir = File.expand_path("vendor/assets", __dir__)

# First, delete js/css directories.
["javascripts", "stylesheets"].each do |path_type|
[ "javascripts", "stylesheets" ].each do |path_type|
FileUtils.rm_rf(File.expand_path("#{path_type}/rest_framework", assets_dir))
Dir.mkdir(File.expand_path("#{path_type}/rest_framework", assets_dir))
end
Expand Down
18 changes: 9 additions & 9 deletions lib/rest_framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ module RESTFramework
BUILTIN_MEMBER_ACTIONS = {
show: :get,
edit: :get,
update: [:put, :patch].freeze,
update: [ :put, :patch ].freeze,
destroy: :delete,
}.freeze
RRF_BUILTIN_ACTIONS = {
options: :options,
}.freeze
RRF_BUILTIN_BULK_ACTIONS = {
update_all: [:put, :patch].freeze,
update_all: [ :put, :patch ].freeze,
destroy_all: :delete,
}.freeze

Expand Down Expand Up @@ -65,12 +65,12 @@ module RESTFramework
"highlight-a11y-dark.min.css" => {
url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/styles/a11y-dark.min.css",
sri: "sha512-Vj6gPCk8EZlqnoveEyuGyYaWZ1+jyjMPg8g4shwyyNlRQl6d3L9At02ZHQr5K6s5duZl/+YKMnM3/8pDhoUphg==",
extra_tag_attrs: {class: "rrf-dark-mode"},
extra_tag_attrs: { class: "rrf-dark-mode" },
},
"highlight-a11y-light.min.css" => {
url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/styles/a11y-light.min.css",
sri: "sha512-WDk6RzwygsN9KecRHAfm9HTN87LQjqdygDmkHSJxVkVI7ErCZ8ZWxP6T8RvBujY1n2/E4Ac+bn2ChXnp5rnnHA==",
extra_tag_attrs: {class: "rrf-light-mode"},
extra_tag_attrs: { class: "rrf-light-mode" },
},

# NeatJSON
Expand Down Expand Up @@ -117,7 +117,7 @@ module RESTFramework
raise "Unknown asset extension: #{ext}."
end

[name, cfg]
[ name, cfg ]
}.to_h.freeze
# rubocop:enable Layout/LineLength

Expand All @@ -126,8 +126,8 @@ module RESTFramework
# Global configuration should be kept minimal, as controller-level configurations allows multiple
# APIs to be defined to behave differently.
class Config
DEFAULT_LABEL_FIELDS = %w(name label login title email username url).freeze
DEFAULT_SEARCH_COLUMNS = DEFAULT_LABEL_FIELDS + %w(description note).freeze
DEFAULT_LABEL_FIELDS = %w[name label login title email username url].freeze
DEFAULT_SEARCH_COLUMNS = DEFAULT_LABEL_FIELDS + %w[description note].freeze
DEFAULT_EXCLUDE_BODY_FIELDS = %w[
created_at
created_by
Expand Down Expand Up @@ -192,15 +192,15 @@ def initialize
end

def self.config
return @config ||= Config.new
@config ||= Config.new
end

def self.configure
yield(self.config)
end

def self.features
return @features ||= {}
@features ||= {}
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class RESTFramework::Errors::NilPassedToRenderAPIError < RESTFramework::Errors::BaseError
def message
return <<~MSG.split("\n").join(" ")
<<~MSG.split("\n").join(" ")
Payload of `nil` was passed to `render_api`; this is unsupported. If you want a blank
response, pass `''` (an empty string) as the payload. If this was the result of a `find_by`
(or similar Active Record method) not finding a record, you should use the bang version (e.g.,
Expand Down
2 changes: 1 addition & 1 deletion lib/rest_framework/errors/unknown_model_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def initialize(controller_class)
end

def message
return <<~MSG.split("\n").join(" ")
<<~MSG.split("\n").join(" ")
The model class for `#{@controller_class}` could not be determined. Any controller that
includes `RESTFramework::BaseModelControllerMixin` (directly or indirectly) must either set
the `model` attribute on the controller, or the model must be deducible from the controller
Expand Down
6 changes: 3 additions & 3 deletions lib/rest_framework/filters/ordering_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class RESTFramework::Filters::OrderingFilter < RESTFramework::Filters::BaseFilter
# Get a list of ordering fields for the current action.
def _get_fields
return @controller.class.ordering_fields&.map(&:to_s) || @controller.get_fields
@controller.class.ordering_fields&.map(&:to_s) || @controller.get_fields
end

# Convert ordering string to an ordering configuration.
Expand Down Expand Up @@ -34,7 +34,7 @@ def _get_ordering
return ordering
end

return nil
nil
end

# Order data according to the request query parameters.
Expand All @@ -46,7 +46,7 @@ def filter_data(data)
return data.send(reorder ? :reorder : :order, ordering)
end

return data
data
end
end

Expand Down
Loading