Skip to content

Commit

Permalink
Merge pull request #104 from Shopify/add-rubocop
Browse files Browse the repository at this point in the history
Configure RubyLSP + add and run Rubocop
  • Loading branch information
elsom25 committed Mar 15, 2024
2 parents ec4049a + 8ae39d8 commit 7664c88
Show file tree
Hide file tree
Showing 25 changed files with 206 additions and 118 deletions.
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
// All of these settings are scoped only to the Ruby language
"[ruby]": {
"editor.defaultFormatter": "Shopify.ruby-lsp", // Use the Ruby LSP as the default formatter
"editor.formatOnSave": true, // Format files automatically when saving
"editor.tabSize": 2, // Use 2 spaces for indentation
"editor.insertSpaces": true, // Use spaces and not tabs for indentantion
"editor.semanticHighlighting.enabled": true, // Enable semantic highlighting
"editor.formatOnType": true, // Enable formatting while typing
},
}
6 changes: 6 additions & 0 deletions dev/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
inherit_gem:
rubocop-shopify: rubocop.yml

AllCops:
Exclude:
- 'bin/bundle'
18 changes: 11 additions & 7 deletions dev/Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
source 'https://rubygems.org'
# frozen_string_literal: true

gem 'activerecord', '~> 7.1'
gem 'byebug'
gem 'jekyll', '~> 4.3'
gem 'rake', '~> 13.1'
gem 'sqlite3', '~> 1.7'
source "https://rubygems.org"

gem "activerecord", "~> 7.1"
gem "jekyll", "~> 4.3"
gem "rake", "~> 13.1"
gem "sqlite3", "~> 1.7"

gem "byebug"
gem "rubocop-shopify", require: false

group :test do
gem 'minitest', '~> 5.21'
gem "minitest", "~> 5.21"
end
27 changes: 27 additions & 0 deletions dev/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.6)
byebug (11.1.3)
Expand Down Expand Up @@ -57,26 +58,51 @@ GEM
sass-embedded (~> 1.54)
jekyll-watch (2.2.1)
listen (~> 3.0)
json (2.7.1)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
language_server-protocol (3.17.0.3)
liquid (4.0.4)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.4.0)
minitest (5.21.2)
mutex_m (0.2.0)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (5.0.4)
racc (1.7.3)
rainbow (3.1.1)
rake (13.1.0)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
regexp_parser (2.9.0)
rexml (3.2.6)
rouge (4.2.0)
rubocop (1.62.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
rubocop-shopify (2.15.1)
rubocop (~> 1.51)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
safe_yaml (1.0.5)
sass-embedded (1.70.0-arm64-darwin)
Expand All @@ -103,6 +129,7 @@ DEPENDENCIES
jekyll (~> 4.3)
minitest (~> 5.21)
rake (~> 13.1)
rubocop-shopify
sqlite3 (~> 1.7)

BUNDLED WITH
Expand Down
10 changes: 6 additions & 4 deletions dev/Rakefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
require 'minitest/test_task'
# frozen_string_literal: true

task default: %w[test]
require "minitest/test_task"

Minitest::TestTask.create :test do |t|
task default: ["test"]

Minitest::TestTask.create(:test) do |t|
t.test_globs = [
"test/unit/**/*_test.rb",
]
t.warning = false
end

Minitest::TestTask.create :test_integration do |t|
Minitest::TestTask.create(:test_integration) do |t|
t.test_globs = [
"test/integration/**/*_test.rb",
]
Expand Down
2 changes: 2 additions & 0 deletions dev/app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
6 changes: 4 additions & 2 deletions dev/app/models/category.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

class Category < ApplicationRecord
default_scope { order(:name) }

scope :verticals, -> { where(parent_id: nil) }

has_many :children, class_name: 'Category', inverse_of: :parent
belongs_to :parent, class_name: 'Category', optional: true
has_many :children, class_name: "Category", inverse_of: :parent
belongs_to :parent, class_name: "Category", optional: true
has_and_belongs_to_many :properties

validates :id,
Expand Down
2 changes: 2 additions & 0 deletions dev/app/models/property.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Property < ApplicationRecord
default_scope { order(:name) }

Expand Down
2 changes: 2 additions & 0 deletions dev/app/models/property_value.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class PropertyValue < ApplicationRecord
default_scope { order(Arel.sql("CASE WHEN name = 'Other' THEN 1 ELSE 0 END, name")) }

Expand Down
2 changes: 2 additions & 0 deletions dev/app/serializers/data/category_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Serializers
module Data
class CategorySerializer < ObjectSerializer
Expand Down
6 changes: 4 additions & 2 deletions dev/app/serializers/data/property_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Serializers
module Data
class PropertySerializer < ObjectSerializer
Expand All @@ -6,7 +8,7 @@ def serialize(property)
"id" => property.id,
"name" => property.name,
"friendly_id" => property.friendly_id,
"values" => property.property_values.reorder(:id).map { PropertyValueSerializer.serialize(_1) }
"values" => property.property_values.reorder(:id).map { PropertyValueSerializer.serialize(_1) },
}
end

Expand All @@ -15,7 +17,7 @@ def deserialize(hash)
id: hash["id"],
friendly_id: hash["friendly_id"],
name: hash["name"],
property_value_ids: hash["values"].map { _1["id"] }
property_value_ids: hash["values"].map { _1["id"] },
)
end
end
Expand Down
2 changes: 2 additions & 0 deletions dev/app/serializers/data/property_value_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Serializers
module Data
class PropertyValueSerializer < ObjectSerializer
Expand Down
6 changes: 4 additions & 2 deletions dev/app/serializers/dist/json.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'json'
# frozen_string_literal: true

require "json"

module Serializers
module Dist
Expand Down Expand Up @@ -68,7 +70,7 @@ def serialize_property(property)
def serialize_nested(connection)
{
id: connection.gid,
name: connection.name
name: connection.name,
}
end
end
Expand Down
2 changes: 2 additions & 0 deletions dev/app/serializers/dist/text.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Serializers
module Dist
class Text
Expand Down
2 changes: 2 additions & 0 deletions dev/app/serializers/object_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Serializers
class ObjectSerializer
include Singleton
Expand Down
40 changes: 21 additions & 19 deletions dev/application.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
require 'bundler/setup'
# frozen_string_literal: true

require "bundler/setup"
Bundler.require(:default)

require 'sqlite3'
require 'active_record'
require "sqlite3"
require "active_record"

require_relative 'db/seed'
require_relative "db/seed"

require_relative 'app/models/application_record'
require_relative 'app/models/category'
require_relative 'app/models/property'
require_relative 'app/models/property_value'
require_relative "app/models/application_record"
require_relative "app/models/category"
require_relative "app/models/property"
require_relative "app/models/property_value"

require_relative 'app/serializers/object_serializer'
require_relative 'app/serializers/data/category_serializer'
require_relative 'app/serializers/data/property_serializer'
require_relative 'app/serializers/data/property_value_serializer'
require_relative 'app/serializers/dist/json'
require_relative 'app/serializers/dist/text'
require_relative "app/serializers/object_serializer"
require_relative "app/serializers/data/category_serializer"
require_relative "app/serializers/data/property_serializer"
require_relative "app/serializers/data/property_value_serializer"
require_relative "app/serializers/dist/json"
require_relative "app/serializers/dist/text"

module Application
ROOT = File.expand_path('..', __dir__)
ROOT = File.expand_path("..", __dir__)
private_constant :ROOT

class << self
Expand All @@ -28,16 +30,16 @@ def root
end

def establish_db_connection!(env: :local)
config = YAML.load_file('db/config.yml', aliases: true).fetch(env.to_s)
unless config['database'] == ':memory:'
config.merge!('database' => "#{root}/dev/tmp/#{config['database']}")
config = YAML.load_file("db/config.yml", aliases: true).fetch(env.to_s)
unless config["database"] == ":memory:"
config.merge!("database" => "#{root}/dev/tmp/#{config["database"]}")
end

ActiveRecord::Base.establish_connection(config)
end

def load_and_reset_schema!
require_relative('db/schema')
require_relative("db/schema")
end
end
end
5 changes: 3 additions & 2 deletions dev/bin/generate_dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'yaml'
require_relative '../application'
require "yaml"
require_relative "../application"

Application.establish_db_connection!

Expand Down
Loading

0 comments on commit 7664c88

Please sign in to comment.