Skip to content

Commit

Permalink
Set up ERB linting in CI and expand/update Rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiarlo committed Aug 9, 2024
1 parent 79e1a96 commit 4fc56ef
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 43 deletions.
4 changes: 1 addition & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ workflows:
- ruby-rails/validate-api:
name: validate
- ruby-rails/lint:
context: dlss
name: lint
- ruby-rails/lint-erb
- ruby-rails/test-rails:
name: test
context: dlss
api-only: true
db-prepare-command: db:reset
executor: ruby-rails/ruby-postgres-redis
- ruby-rails/docker-publish:
context: dlss
name: publish-latest
image: suldlss/preservation_catalog
extra_build_args: --build-arg BUNDLE_GEMS__CONTRIBSYS__COM
Expand Down
36 changes: 36 additions & 0 deletions .erb-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
exclude:
- '**/vendor/**/*'
linters:
Rubocop:
enabled: true
rubocop_config:
inherit_from:
- .rubocop.yml
# Suggested by https://github.com/Shopify/erb-lint#rubocop
Layout/InitialIndentation:
Enabled: false
Layout/LineLength:
Enabled: false
Layout/TrailingEmptyLines:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: false
Naming/FileName:
Enabled: false
Lint/UselessAssignment:
Enabled: false
Rails/OutputSafety: # Already covered by ErbSafety linter
Enabled: false
Rails/LinkToBlank:
Enabled: false
ErbSafety:
enabled: true
PartialInstanceVariable:
enabled: false
DeprecatedClasses:
enabled: true
NoUnusedDisable:
enabled: true
RubocopText:
enabled: true
16 changes: 10 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@ inherit_mode:
AllCops:
TargetRubyVersion: 3.3
DisplayCopNames: true
Include:
- './Rakefile'
- './config.ru'
- '**/*.rb'
- '**/*.rake'
Exclude:
- 'bin/**/*'
- 'config/environments/*.rb'
- 'db/**/*'
- 'vendor/**/*'

Expand Down Expand Up @@ -650,3 +644,13 @@ RSpec/IsExpectedSpecify: # new in 2.27
Enabled: true
RSpec/RepeatedSubjectCall: # new in 2.27
Enabled: true
Gemspec/AddRuntimeDependency: # new in 1.65
Enabled: true
Style/MapIntoArray: # new in 1.63
Enabled: true
Style/SendWithLiteralMethodName: # new in 1.64
Enabled: true
Style/SuperArguments: # new in 1.64
Enabled: true
Rails/WhereRange: # new in 2.25
Enabled: true
20 changes: 11 additions & 9 deletions Capfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# frozen_string_literal: true

# Load DSL and set up stages
require "capistrano/setup"
require 'capistrano/setup'

# Include default deployment tasks
require "capistrano/deploy"
require 'capistrano/deploy'

require "capistrano/scm/git"
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git

require "capistrano/bundler"
require "capistrano/passenger"
require "capistrano/rails"
require "capistrano/honeybadger"
require "dlss/capistrano"
require 'capistrano/bundler'
require 'capistrano/passenger'
require 'capistrano/rails'
require 'capistrano/honeybadger'
require 'dlss/capistrano'
require 'whenever/capistrano'

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
21 changes: 11 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# general Ruby/Rails gems
gem 'aws-sdk-s3', '~> 1.17'
gem 'committee' # Validates HTTP requests/responses per OpenAPI specification
gem 'connection_pool' # Used for redis
gem 'config' # Settings to manage configs on different instances
gem 'connection_pool' # Used for redis
gem 'csv' # will be removed from standard library in Ruby 3.4
gem 'dor-event-client'
gem 'dor-workflow-client' # audit errors are reported to the workflow service
gem 'druid-tools' # for druid validation and druid-tree parsing
gem 'honeybadger' # for error reporting / tracking / notifications
gem "importmap-rails", "~> 1.2"
gem 'importmap-rails', '~> 1.2'
gem 'jbuilder' # Build JSON APIs with ease.
gem 'jwt' # for gating programmatic access to the application
gem 'lograge'
gem 'moab-versioning', '~> 6.0' # work with Moab Objects
gem 'okcomputer' # ReST endpoint with upness status
gem 'pg' # postgres database
gem 'postgresql_cursor' # for paging over large result sets efficiently
gem 'propshaft', '~> 0.8.0' # asset pipeline
# pry is useful for debugging, even in prod
gem 'pry-byebug' # call 'binding.pry' anywhere in the code to stop execution and get a pry-byebug console
gem 'pry' # make it possible to use pry for IRB
gem 'pry-byebug' # call 'binding.pry' anywhere in the code to stop execution and get a pry-byebug console
gem 'puma' # app server
gem 'rails', '~> 7.0.0'
gem 'redis', '~> 5.0'
Expand All @@ -31,20 +35,17 @@ source 'https://gems.contribsys.com/' do
end

# Stanford gems
gem 'dor-event-client'
gem 'dor-workflow-client' # audit errors are reported to the workflow service
gem 'druid-tools' # for druid validation and druid-tree parsing
gem 'moab-versioning', '~> 6.0' # work with Moab Objects

group :development, :test do
gem 'rspec-rails'
gem 'erb_lint', require: false
# Ruby static code analyzer https://rubocop.readthedocs.io/en/latest/
gem 'rubocop', '~> 1.0'
gem 'rubocop-capybara'
gem 'rubocop-factory_bot'
gem 'rubocop-rails'
gem 'rubocop-rspec'
gem 'rubocop-rspec_rails'
gem 'rspec-rails'
gem 'rspec_junit_formatter' # used by CircleCI
end

Expand Down
16 changes: 16 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ GEM
bcrypt_pbkdf (1.1.1)
bcrypt_pbkdf (1.1.1-arm64-darwin)
bcrypt_pbkdf (1.1.1-x86_64-darwin)
better_html (2.1.1)
actionview (>= 6.0)
activesupport (>= 6.0)
ast (~> 2.0)
erubi (~> 1.4)
parser (>= 2.4)
smart_properties
bigdecimal (3.1.8)
builder (3.3.0)
bundler-audit (0.9.1)
Expand Down Expand Up @@ -179,6 +186,13 @@ GEM
zeitwerk (~> 2.1)
druid-tools (3.0.0)
ed25519 (1.3.0)
erb_lint (0.6.0)
activesupport
better_html (>= 2.0.1)
parser (>= 2.7.1.4)
rainbow
rubocop (>= 1)
smart_properties
erubi (1.13.0)
factory_bot (6.4.6)
activesupport (>= 5.0.0)
Expand Down Expand Up @@ -416,6 +430,7 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
smart_properties (1.17.0)
sorted_set (1.0.3)
rbtree
set (~> 1.0)
Expand Down Expand Up @@ -476,6 +491,7 @@ DEPENDENCIES
dor-event-client
dor-workflow-client
druid-tools
erb_lint
factory_bot_rails
honeybadger
importmap-rails (~> 1.2)
Expand Down
13 changes: 12 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

Expand All @@ -7,7 +9,16 @@ Rails.application.load_tasks
require 'rubocop/rake_task'
RuboCop::RakeTask.new

desc 'Run erblint against ERB files'
task erblint: :environment do
puts 'Running erblint...'
system('bundle exec erblint --lint-all --format compact')
end

desc 'Run all configured linters'
task lint: %i[rubocop erblint]

# clear the default task injected by rspec
task(:default).clear

task default: [:rubocop, :spec]
task default: [:lint, :spec]
2 changes: 1 addition & 1 deletion app/services/dashboard/audit_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def moab_audit_age_threshold
def num_moab_audits_older_than_threshold
# This is faster than MoabRecord.version_audit_expired(moab_audit_age_threshold).count
MoabRecord.where(last_version_audit: nil).annotate(caller).count + \
MoabRecord.where('last_version_audit < ?', moab_audit_age_threshold).annotate(caller).count
MoabRecord.where(last_version_audit: ...moab_audit_age_threshold).annotate(caller).count
end

def moab_audits_older_than_threshold?
Expand Down
2 changes: 2 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This file is used by Rack-based servers to start the application.

require_relative 'config/environment'
Expand Down
9 changes: 5 additions & 4 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "active_support/core_ext/integer/time"
# frozen_string_literal: true

require 'active_support/core_ext/integer/time'

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
Expand All @@ -19,13 +21,13 @@

# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join("tmp/caching-dev.txt").exist?
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = true

config.cache_store = :memory_store
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{2.days.to_i}"
'Cache-Control' => "public, max-age=#{2.days.to_i}"
}
else
config.action_controller.perform_caching = false
Expand All @@ -48,7 +50,6 @@
# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true


# Raises error for missing translations.
# config.i18n.raise_on_missing_translations = true

Expand Down
14 changes: 8 additions & 6 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "active_support/core_ext/integer/time"
# frozen_string_literal: true

require 'active_support/core_ext/integer/time'

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
Expand All @@ -22,7 +24,7 @@

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.asset_host = "http://assets.example.com"
Expand All @@ -39,7 +41,7 @@
config.log_level = :info

# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
config.log_tags = [:request_id]

# Use a different cache store in production.
# config.cache_store = :mem_cache_store
Expand All @@ -57,14 +59,14 @@
config.active_support.report_deprecations = false

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
config.log_formatter = Logger::Formatter.new

# Use a different logger for distributed setups.
# require "syslog/logger"
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")

if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
Expand Down
8 changes: 5 additions & 3 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "active_support/core_ext/integer/time"
# frozen_string_literal: true

require 'active_support/core_ext/integer/time'

# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
Expand All @@ -14,12 +16,12 @@
# Eager loading loads your whole application. When running a single test locally,
# this probably isn't necessary. It's a good idea to do in a continuous integration
# system, or in some way before deploying your code.
config.eager_load = ENV["CI"].present?
config.eager_load = ENV['CI'].present?

# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{1.hour.to_i}"
'Cache-Control' => "public, max-age=#{1.hour.to_i}"
}

# Show full error reports and disable caching.
Expand Down

0 comments on commit 4fc56ef

Please sign in to comment.