Skip to content

Commit

Permalink
Fix linters
Browse files Browse the repository at this point in the history
  • Loading branch information
binos30 committed Jul 25, 2024
1 parent f1b86e3 commit bf5c2ee
Show file tree
Hide file tree
Showing 29 changed files with 195 additions and 56 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ yarn-debug.log*
.yarn-integrity

.cache/
.eslintcache

# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode
Expand Down
36 changes: 33 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
push:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: ${{ github.ref_name != 'main' }}

jobs:
scan_ruby:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -74,10 +78,36 @@ jobs:
path: .cache/eslint
key: eslint-main-cache

- name: Lint code for consistent style
- name: Restore prettier cache
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: .cache/prettier
key: prettier-main-cache

- name: Run prettier
run: yarn prettier-ci

- name: Remove prettier cache
if: github.event_name == 'push'
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.event.repository.full_name }}
run: |
bin/bundle exec stree check "{app,config,lib,spec,test}/**/*.rb"
bin/rubocop -f github
gh api --method DELETE /repos/{owner}/{repo}/actions/caches?key=prettier-main-cache ||
echo "Prettier cache not found"
- name: Save prettier cache
if: github.event_name == 'push'
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: .cache/prettier
key: prettier-main-cache

- name: Run RuboCop
run: yarn rubocop-ci

- name: Run Syntax Tree
run: yarn stree-ci

test:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ yarn-debug.log*
.yarn-integrity

.cache/
.eslintcache

# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode
Expand Down
14 changes: 14 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.cache/
.yarn/
/app/assets/builds/*
/db
/docs
/lib
/log
/node_modules
/public/assets
/spec
/storage
/tmp
/vendor
.eslintcache
5 changes: 0 additions & 5 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@ requirePragma: false
singleQuote: false
tabWidth: 2
trailingComma: "none"

rubyHashLabel: true
rubyModifier: true
rubySingleQuote: false
rubyToProc: false
21 changes: 16 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ inherit_gem:
AllCops:
NewCops: enable
Exclude:
- "vendor/**/*"
- "test/fixtures/**/*"
- "db/**/*"
- ".cache/**/*"
- ".git/**/*"
- ".github/**/*"
- ".husky/**/*"
- ".ruby-lsp/**/*"
- ".vscode/**/*"
- ".yarn/**/*"
- "app/views/**/*"
- "bin/**/*"
- "db/schema.rb"
- "docs/**/*"
- "log/**/*"
- "tmp/**/*"
- "app/views/**/*"
- "node_modules/**/*"
- "storage/**/*"
- "tmp/**/*"
- "vendor/**/*"

# Layout Cops

Expand Down Expand Up @@ -101,6 +109,9 @@ Style/InlineComment:
Description: "Avoid inline comments."
Enabled: false

Style/FrozenStringLiteralComment:
EnforcedStyle: always_true

# Rails Cops

Rails/Delegate:
Expand Down
15 changes: 15 additions & 0 deletions .streerc
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
--ignore-files='.cache/*'
--ignore-files='.git/*'
--ignore-files='.github/*'
--ignore-files='.husky/*'
--ignore-files='.vscode/*'
--ignore-files='.yarn/*'
--ignore-files='app/views/*'
--ignore-files='bin/*'
--ignore-files='db/schema.rb'
--ignore-files='docs/*'
--ignore-files='log/*'
--ignore-files='node_modules/*'
--ignore-files='storage/*'
--ignore-files='tmp/*'
--ignore-files='vendor/*'
--print-width=115
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ group :development, :test do
gem "rubocop-rspec_rails", require: false
# Interact with the Ruby syntax tree [https://github.com/ruby-syntax-tree/syntax_tree]
gem "syntax_tree"
# Provides a comprehensive suite of tools for Ruby programming: intellisense, diagnostics, inline documentation,
# and type checking [https://github.com/castwide/solargraph]
gem "solargraph"
end

group :development do
Expand Down
29 changes: 29 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ GEM
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
backport (1.2.0)
base64 (0.2.0)
bcrypt (3.1.20)
benchmark (0.3.0)
bigdecimal (3.1.8)
bindex (0.8.1)
bootsnap (1.18.3)
Expand Down Expand Up @@ -127,6 +129,7 @@ GEM
dotenv (= 3.1.2)
railties (>= 6.1)
drb (2.2.1)
e2mmap (0.1.0)
erubi (1.13.0)
faker (3.4.2)
i18n (>= 1.8.11, < 2)
Expand Down Expand Up @@ -162,12 +165,17 @@ GEM
irb (1.14.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jaro_winkler (1.6.0)
jbuilder (2.12.0)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jsbundling-rails (1.3.0)
railties (>= 6.0.0)
json (2.7.2)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
language_server-protocol (3.17.0.3)
local_time (3.0.2)
logger (1.6.0)
Expand Down Expand Up @@ -264,6 +272,7 @@ GEM
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.2.1)
rbs (2.8.4)
rdoc (6.7.0)
psych (>= 4.0.0)
redis (5.2.0)
Expand All @@ -276,6 +285,8 @@ GEM
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
reverse_markdown (2.1.1)
nokogiri
rexml (3.3.2)
strscan
rspec-core (3.13.0)
Expand Down Expand Up @@ -350,6 +361,22 @@ GEM
slim_lint (0.27.0)
rubocop (>= 1.0, < 2.0)
slim (>= 3.0, < 6.0)
solargraph (0.50.0)
backport (~> 1.2)
benchmark
bundler (~> 2.0)
diff-lcs (~> 1.4)
e2mmap
jaro_winkler (~> 1.5)
kramdown (~> 2.3)
kramdown-parser-gfm (~> 1.1)
parser (~> 3.0)
rbs (~> 2.0)
reverse_markdown (~> 2.0)
rubocop (~> 1.38)
thor (~> 1.0)
tilt (~> 2.0)
yard (~> 0.9, >= 0.9.24)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand Down Expand Up @@ -403,6 +430,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
yard (0.9.36)
zeitwerk (2.6.16)

PLATFORMS
Expand Down Expand Up @@ -448,6 +476,7 @@ DEPENDENCIES
selenium-webdriver
slim-rails
slim_lint
solargraph
sprockets-rails
stimulus-rails
stripe
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20240108062910_create_roles.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateRoles < ActiveRecord::Migration[7.1]
def change
create_table :roles do |t|
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20240531065752_create_categories.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateCategories < ActiveRecord::Migration[7.1]
def change
create_table :categories do |t|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,62 @@
# frozen_string_literal: true

# This migration comes from active_storage (originally 20170806125915)
class CreateActiveStorageTables < ActiveRecord::Migration[7.0]
def change
def change # rubocop:disable Metrics/MethodLength
# Use Active Record's configured type for primary and foreign keys
primary_key_type, foreign_key_type = primary_and_foreign_key_types

create_table :active_storage_blobs, id: primary_key_type do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.string :service_name, null: false
t.bigint :byte_size, null: false
t.string :checksum
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.string :service_name, null: false
t.bigint :byte_size, null: false
t.string :checksum

if connection.supports_datetime_with_precision?
t.datetime :created_at, precision: 6, null: false
else
t.datetime :created_at, null: false
end

t.index [ :key ], unique: true
t.index [:key], unique: true
end

create_table :active_storage_attachments, id: primary_key_type do |t|
t.string :name, null: false
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
t.references :blob, null: false, type: foreign_key_type
t.string :name, null: false
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
t.references :blob, null: false, type: foreign_key_type

if connection.supports_datetime_with_precision?
t.datetime :created_at, precision: 6, null: false
else
t.datetime :created_at, null: false
end

t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true
t.index %i[record_type record_id name blob_id],
name: :index_active_storage_attachments_uniqueness,
unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end

create_table :active_storage_variant_records, id: primary_key_type do |t|
t.belongs_to :blob, null: false, index: false, type: foreign_key_type
t.string :variation_digest, null: false

t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true
t.index %i[blob_id variation_digest], name: :index_active_storage_variant_records_uniqueness, unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end

private
def primary_and_foreign_key_types
config = Rails.configuration.generators
setting = config.options[config.orm][:primary_key_type]
primary_key_type = setting || :primary_key
foreign_key_type = setting || :bigint
[primary_key_type, foreign_key_type]
end

def primary_and_foreign_key_types
config = Rails.configuration.generators
setting = config.options[config.orm][:primary_key_type]
primary_key_type = setting || :primary_key
foreign_key_type = setting || :bigint
[primary_key_type, foreign_key_type]
end
end
2 changes: 2 additions & 0 deletions db/migrate/20240602040146_create_products.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateProducts < ActiveRecord::Migration[7.1]
def change
create_table :products do |t|
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20240603015753_create_stocks.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateStocks < ActiveRecord::Migration[7.1]
def change
create_table :stocks do |t|
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20240603081751_create_orders.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateOrders < ActiveRecord::Migration[7.1]
def change
create_table :orders do |t|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddSlugToCategoriesAndProducts < ActiveRecord::Migration[7.1]
def change
add_column :categories, :slug, :string
Expand Down
10 changes: 3 additions & 7 deletions db/migrate/20240611030258_create_order_items.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateOrderItems < ActiveRecord::Migration[7.1]
def change
create_table :order_items do |t|
Expand Down Expand Up @@ -30,12 +32,6 @@ def change
add_index :orders, :customer_email
add_column :orders, :order_code, :string, null: false
add_index :orders, :order_code, unique: true
add_column :orders,
:total,
:decimal,
null: false,
precision: 12,
scale: 2,
default: 0
add_column :orders, :total, :decimal, null: false, precision: 12, scale: 2, default: 0
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class IndexOrdersOnCustomerFullName < ActiveRecord::Migration[7.1]
def change
add_index :orders, :customer_full_name
Expand Down
Loading

0 comments on commit bf5c2ee

Please sign in to comment.