Skip to content

Commit

Permalink
Merge pull request #2347 from sul-dlss/setup-erblint
Browse files Browse the repository at this point in the history
Set up linting of ERBs
  • Loading branch information
justinlittman authored Aug 9, 2024
2 parents 79e1a96 + e1cf6bd commit ca60be3
Show file tree
Hide file tree
Showing 23 changed files with 163 additions and 89 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]
52 changes: 26 additions & 26 deletions app/components/dashboard/audit_information_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Note also:
<table class="table table-bordered border-dark table-hover table-sm">
<thead class="table-info">
<tr>
<th class="col-sm-2"/>
<th class="col-sm-2" />
<th class="col-sm-1">redis queue name</th>
<th class="col-sm-3">expected frequency<br/>(from app/config/schedule.rb)</th>
<th class="col-sm-3">expected frequency<br>(from app/config/schedule.rb)</th>
<th class="col-sm-1">how many objects get queued</th>
<th class="col-sm-2">objects with audit timestamps older than threshold</th>
<th>objects with errors</th>
Expand All @@ -23,50 +23,50 @@ Note also:
</thead>
<tbody class="table-group-divider">
<tr>
<td><strong>Validate Moab</strong><br/>moab-versioning gem validation for well-formedness (not checksums) run for locally stored Moabs.</td>
<td><strong>Validate Moab</strong><br>moab-versioning gem validation for well-formedness (not checksums) run for locally stored Moabs.</td>
<td>validate_moab</td>
<td><strong>on demand</strong></td>
<td><strong>one</strong>:<br/>queued by preservation robot step after updating a Moab</td>
<td class="text-end<%= ' table-warning' if moab_audits_older_than_threshold? %>">Moab audits older than <%= moab_audit_age_threshold %>:<hr/><%= num_moab_audits_older_than_threshold %></td>
<td><strong>one</strong>:<br>queued by preservation robot step after updating a Moab</td>
<td class="text-end<%= ' table-warning' if moab_audits_older_than_threshold? %>">Moab audits older than <%= moab_audit_age_threshold %>:<hr><%= num_moab_audits_older_than_threshold %></td>
<td class="text-end<%= ' table-danger' if any_moab_record_errors? %>"><%= num_moab_record_not_ok %></td>
<td class="table-secondary"/>
<td class="table-secondary" />
</tr>
<tr>
<td><strong>Moab to Catalog</strong><br/>moab-versioning gem validation for well-formedness (not checksums) run for locally stored Moabs and verified against database info.</td>
<td><strong>Moab to Catalog</strong><br>moab-versioning gem validation for well-formedness (not checksums) run for locally stored Moabs and verified against database info.</td>
<td>m2c</td>
<td><strong>Monthly</strong>: 11 am on the 1st of every month</td>
<td><strong>all</strong>:<br/>queued by walking directories on MoabStorageRoot.storage_location</td>
<td class="text-end<%= ' table-warning' if moab_audits_older_than_threshold? %>">Moab audits older than <%= moab_audit_age_threshold %>:<hr/><%= num_moab_audits_older_than_threshold %></td>
<td><strong>all</strong>:<br>queued by walking directories on MoabStorageRoot.storage_location</td>
<td class="text-end<%= ' table-warning' if moab_audits_older_than_threshold? %>">Moab audits older than <%= moab_audit_age_threshold %>:<hr><%= num_moab_audits_older_than_threshold %></td>
<td class="text-end<%= ' table-danger' if any_moab_record_errors? %>"><%= num_moab_record_not_ok %></td>
<td class="table-secondary"/>
<td class="table-secondary" />
</tr>
<tr>
<td><strong>Catalog to Moab</strong><br/>Database info verified against locally stored Moabs and moab-versioning integrity checks for Moabs.</td>
<td><strong>Catalog to Moab</strong><br>Database info verified against locally stored Moabs and moab-versioning integrity checks for Moabs.</td>
<td>c2m</td>
<td><strong>Monthly</strong>: 11 am on the 15th of every month</td>
<td><strong>all</strong>:<br/>queued by associated MoabStorageRoot</td>
<td class="text-end<%= ' table-warning' if moab_audits_older_than_threshold? %>">Moab audits older than <%= moab_audit_age_threshold %>:<hr/><%= num_moab_audits_older_than_threshold %></td>
<td><strong>all</strong>:<br>queued by associated MoabStorageRoot</td>
<td class="text-end<%= ' table-warning' if moab_audits_older_than_threshold? %>">Moab audits older than <%= moab_audit_age_threshold %>:<hr><%= num_moab_audits_older_than_threshold %></td>
<td class="text-end<%= ' table-danger' if any_moab_record_errors? %>"><%= num_moab_record_not_ok %></td>
<td class="table-secondary"/>
<td class="table-secondary" />
</tr>
<tr>
<td><strong>Checksum Validation (CV)</strong><br/>Compare checksums in Moab metadata files on local storage with computed checksums for Moab metadata and content files.</td>
<td><strong>Checksum Validation (CV)</strong><br>Compare checksums in Moab metadata files on local storage with computed checksums for Moab metadata and content files.</td>
<td>checksum_validation</td>
<td><strong>Weekly</strong>: 1am on Sunday<br/><em>for MoabRecords with expired checks</em></td>
<td><strong>subset</strong>:<br/>expired checksums queued by associated MoabStorageRoot</td>
<td class="text-end<%= ' table-warning' if moab_audits_older_than_threshold? %>">Moab audits older than <%= moab_audit_age_threshold %>:<hr/><%= num_moab_audits_older_than_threshold %></td>
<td><strong>Weekly</strong>: 1am on Sunday<br><em>for MoabRecords with expired checks</em></td>
<td><strong>subset</strong>:<br>expired checksums queued by associated MoabStorageRoot</td>
<td class="text-end<%= ' table-warning' if moab_audits_older_than_threshold? %>">Moab audits older than <%= moab_audit_age_threshold %>:<hr><%= num_moab_audits_older_than_threshold %></td>
<td class="text-end<%= ' table-danger' unless moab_checksum_validation_audit_ok? %>"><%= MoabRecord.invalid_checksum.count %></td>
<td class="text-center<%= ' table-warning' if moabs_with_expired_checksum_validation? %>"><%= num_moab_expired_checksum_validation %><br/><br/>(passing checks expire 90 days after they are run)</td>
<td class="text-center<%= ' table-warning' if moabs_with_expired_checksum_validation? %>"><%= num_moab_expired_checksum_validation %><br><br>(passing checks expire 90 days after they are run)</td>
</tr>
<tr>
<td><strong>Catalog to Archive</strong><br/>Confirm a PreservedObject has all versions/parts replicated for each of its target endpoints and attempts to backfill missing ones</td>
<td>moab_replication_audit<br/>part_audit_aws_s3_east_1<br/>part_audit_aws_s3_west_2<br/>part_audit_ibm_us_south</td>
<td><strong>Weekly</strong>: 12am on Wednesday<br/><em>for PreservedObjects with expired checks</em></td>
<td><strong>subset</strong>:<br/>expired archive checks for PreservedObjects and their associated ZipParts are queued</td>
<td class="text-end<%= ' table-warning' if replication_audits_older_than_threshold? %>">PreservedObject replication audits older than <%= replication_audit_age_threshold %>:<hr/><%= num_replication_audits_older_than_threshold %></td>
<td><strong>Catalog to Archive</strong><br>Confirm a PreservedObject has all versions/parts replicated for each of its target endpoints and attempts to backfill missing ones</td>
<td>moab_replication_audit<br>part_audit_aws_s3_east_1<br>part_audit_aws_s3_west_2<br>part_audit_ibm_us_south</td>
<td><strong>Weekly</strong>: 12am on Wednesday<br><em>for PreservedObjects with expired checks</em></td>
<td><strong>subset</strong>:<br>expired archive checks for PreservedObjects and their associated ZipParts are queued</td>
<td class="text-end<%= ' table-warning' if replication_audits_older_than_threshold? %>">PreservedObject replication audits older than <%= replication_audit_age_threshold %>:<hr><%= num_replication_audits_older_than_threshold %></td>
<td class="text-end<%= ' table-danger' unless zip_parts_ok? %>"><%= num_replication_errors %></td>
<td class="text-center"><%= PreservedObject.archive_check_expired.count %><br/><br/>(passing checks expire 90 days after they are run)</td>
<td class="text-center"><%= PreservedObject.archive_check_expired.count %><br><br>(passing checks expire 90 days after they are run)</td>
</tr>
</tbody>
</table>
</div>
</div>
2 changes: 1 addition & 1 deletion app/components/dashboard/audit_status_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
</li>
</ul>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions app/components/dashboard/moab_records_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<th>count</th>
<th>total size</th>
<th>average size</th>
<%status_labels.map do |status| %>
<th class="text-center"><%=status %></th>
<% status_labels.map do |status| %>
<th class="text-center"><%= status %></th>
<% end %>
<th>expired checksum audit</th>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<th class="col-1">average size</th>
<th class="col-1">moab count</th>
<% status_labels.map do |status| %>
<th class="col-sm-1 text-center"><%=status %></th>
<th class="col-sm-1 text-center"><%= status %></th>
<% end %>
<th class="col-sm-1">expired checksum audit</th>
</tr>
Expand All @@ -39,9 +39,9 @@
<tfoot class="table-group-divider">
<tr>
<th>totals</th>
<td class="table-secondary"/>
<td class="table-secondary"/>
<td class="table-secondary"/>
<td class="table-secondary" />
<td class="table-secondary" />
<td class="table-secondary" />
<td class="text-end<%= ' table-danger' unless storage_roots_moab_count_ok? %>"><%= storage_roots_moab_count %></td>
<td class="text-end<%= ' table-danger' unless storage_roots_ok_count_ok? %>"><%= storage_roots_ok_count %></td>
<td class="text-end<%= ' table-danger' unless storage_roots_invalid_moab_count_ok? %>"><%= storage_roots_invalid_moab_count %></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<table class="table table-bordered table-hover table-sm">
<thead class="table-info">
<tr>
<th/>
<th />
<th>count</th>
<th>object version count</th>
<th>highest version</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<tr>
<th>endpoint name</th>
<th>ActiveJob class for replication</th>
<th class="text-center">ZippedMoabVersion replicated count<br/>(according to database)</th>
<th class="text-center">Number of Object Versions<br/>(per PreservedObject)</th>
<th class="text-center">ZippedMoabVersion replicated count<br>(according to database)</th>
<th class="text-center">Number of Object Versions<br>(per PreservedObject)</th>
</tr>
</thead>
<tbody class="table-group-divider">
Expand All @@ -25,4 +25,4 @@
</tbody>
</table>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@
</table>
</div>
</div>

Loading

0 comments on commit ca60be3

Please sign in to comment.