Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rubocop linter and CI job #579

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
46 changes: 44 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
# Omakase Ruby styling for Rails
require:
- rubocop-capybara
- rubocop-minitest
- rubocop-performance
- rubocop-rails
- standard

inherit_gem:
rubocop-rails-omakase: rubocop.yml
standard: config/base.yml

AllCops:
SuggestExtensions: false
TargetRubyVersion: 3.3
NewCops: enable

Minitest/MultipleAssertions:
Max: 10 # default 3

Style/FrozenStringLiteralComment:
Enabled: true

# These below cops are good practice going forward, but due to legacy we exclude some migrations
Rails/CreateTableWithTimestamps:
Exclude:
- db/migrate/20181101154531_create_cms.rb
- db/migrate/20220603215833_create_active_storage_variant_records.active_storage.rb

Rails/SkipsModelValidations:
Exclude:
- db/migrate/20220603215832_add_service_name_to_active_storage_blobs.active_storage.rb

Rails/BulkChangeTable:
Exclude:
- db/migrate/20181101154602_create_friendly_id_slugs.rb
- db/migrate/20181101154832_add_slug_to_profiles.rb

Rails/ThreeStateBooleanColumn:
Exclude:
- db/migrate/20181101154627_create_profiles.rb

# Below are cops that are currently disabled, where we should fix in the future
# TODO: Fix ProfilesController so we don't need to use global vars
Style/GlobalVars:
Exclude:
- app/controllers/profiles_controller.rb
16 changes: 12 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

Expand Down Expand Up @@ -37,12 +39,18 @@ gem "rdoc", ">= 6.6.3.1"

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem "byebug", platforms: [ :mri, :mingw, :x64_mingw ]
gem "byebug", platforms: [:mri, :mingw, :x64_mingw]

# Linters
gem "rubocop", require: false
gem "rubocop-capybara", require: false
gem "rubocop-minitest", require: false
gem "rubocop-performance", require: false
gem "rubocop-rails", require: false
gem "standard", ">= 1.35.1", require: false
end

group :development do
gem "rubocop-rails-omakase", require: false

# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem "web-console", ">= 3.3.0"

Expand All @@ -58,4 +66,4 @@ group :test do
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: [ :mingw, :mswin, :x64_mingw, :jruby ]
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
39 changes: 32 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ GEM
kramdown (2.4.0)
rexml
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand Down Expand Up @@ -191,8 +192,18 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.3)
nokogiri (1.16.5-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.5-arm-linux)
racc (~> 1.4)
nokogiri (1.16.5-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.5-x86-linux)
racc (~> 1.4)
nokogiri (1.16.5-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.5-x86_64-linux)
racc (~> 1.4)
parallel (1.24.0)
parser (3.3.1.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -258,7 +269,7 @@ GEM
rexml (3.2.8)
strscan (>= 3.0.9)
rollbar (3.5.2)
rubocop (1.64.0)
rubocop (1.63.5)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand All @@ -271,6 +282,8 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
rubocop-capybara (2.20.0)
rubocop (~> 1.41)
rubocop-minitest (0.35.0)
rubocop (>= 1.61, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
Expand All @@ -282,11 +295,6 @@ GEM
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails-omakase (1.0.0)
rubocop
rubocop-minitest
rubocop-performance
rubocop-rails
ruby-progressbar (1.13.0)
ruby-vips (2.1.4)
ffi (~> 1.12)
Expand All @@ -313,6 +321,18 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
standard (1.36.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.63.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.4)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.4.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.21.0)
stringio (3.1.0)
strscan (3.1.0)
temple (0.10.3)
Expand Down Expand Up @@ -367,9 +387,14 @@ DEPENDENCIES
rails (~> 7.1.3)
rdoc (>= 6.6.3.1)
rollbar
rubocop-rails-omakase
rubocop
rubocop-capybara
rubocop-minitest
rubocop-performance
rubocop-rails
selenium-webdriver
spring (>= 3.0)
standard (>= 1.35.1)
tzinfo-data
uglifier (>= 1.3.0)
web-console (>= 3.3.0)
Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 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.

require_relative 'config/application'
require_relative "config/application"

Rails.application.load_tasks
2 changes: 2 additions & 0 deletions app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Channel < ActionCable::Channel::Base
end
Expand Down
2 changes: 2 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Connection < ActionCable::Connection::Base
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
end
2 changes: 2 additions & 0 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ErrorsController < ApplicationController
def file_not_found
end
Expand Down
112 changes: 56 additions & 56 deletions app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,68 +1,69 @@
# frozen_string_literal: true

class ProfilesController < ApplicationController
$units = { access: "Access Services",
archives: "Archives",
bib: "Cataloguing Strategies",
collections: "Collection Strategies",
copyright: "Copyright",
digital: "Digital Production & Preservation Services",
digrepo: "Digital Repository & Data Services",
dsc: "Digital Scholarship Centre",
facilities: "Facilities",
health: "Faculty Engagement (Health Sciences)",
science: "Faculty Engagement (Natural + Applied Sciences)",
humanities: "Faculty Engagement (Social Sciences + Humanities)",
iss: "Information Services & User Engagement",
admin: "Library Administration",
lad: "Library Application Development",
las: "Library Application Support",
metadata: "Metadata Strategies",
open: "Open Publishing & Digitization Services",
rdm: "Research Data Management",
researchimpact: "Research Impact",
its: "Specialized Technical Support",
special: "Special Collections",
stratigic: "Strategic Partnerships",
tl: "Teaching & Learning",
ux: "User Experience" }
$buildings = { augustana: "Augustana Campus Library",
bsj: "Bibliothèque Saint-Jean",
bpsc: "Bruce Peel Special Collections",
cameron: "Cameron Library",
sperber: "Sperber Library",
rcrf: "Research & Collections Resource Facility",
rutherford: "Rutherford Library",
stjosephs: "St. Joseph's Library" }
$units = {access: "Access Services",
archives: "Archives",
bib: "Cataloguing Strategies",
collections: "Collection Strategies",
copyright: "Copyright",
digital: "Digital Production & Preservation Services",
digrepo: "Digital Repository & Data Services",
dsc: "Digital Scholarship Centre",
facilities: "Facilities",
health: "Faculty Engagement (Health Sciences)",
science: "Faculty Engagement (Natural + Applied Sciences)",
humanities: "Faculty Engagement (Social Sciences + Humanities)",
iss: "Information Services & User Engagement",
admin: "Library Administration",
lad: "Library Application Development",
las: "Library Application Support",
metadata: "Metadata Strategies",
open: "Open Publishing & Digitization Services",
rdm: "Research Data Management",
researchimpact: "Research Impact",
its: "Specialized Technical Support",
special: "Special Collections",
stratigic: "Strategic Partnerships",
tl: "Teaching & Learning",
ux: "User Experience"}
$buildings = {augustana: "Augustana Campus Library",
bsj: "Bibliothèque Saint-Jean",
bpsc: "Bruce Peel Special Collections",
cameron: "Cameron Library",
sperber: "Sperber Library",
rcrf: "Research & Collections Resource Facility",
rutherford: "Rutherford Library",
stjosephs: "St. Joseph's Library"}

# You'll have to define "cmsPassword" in secrets.yml, or this will fail. Thanks, ansible.
http_basic_authenticate_with name: Rails.application.secrets.cms_user, password: Rails.application.secrets.cms_password, except: [ :index, :show ]
http_basic_authenticate_with name: Rails.application.secrets.cms_user, password: Rails.application.secrets.cms_password, except: [:index, :show]

def index
path = request.url
if path.include? "unit"
@unit = params[:unit]
if path.include? "unit"
@unit = params[:unit]
@unitname = $units[params[:unit].to_sym]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing indentation here until line 47

@allunit = Profile.where(unit: @unit)
@heads = @allunit.where(opt_in: true).order(:last_name)
@staff = @allunit.where(opt_in: nil).order(:last_name)
@profiles = @heads + @staff
elsif path.include? "building"
@building = params[:building]
elsif path.include? "building"
@building = params[:building]
@buildingname = $buildings[params[:building].to_sym]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing indentation here and on line below

@profiles = Profile.where("campus_address=?", params[:building]).order(:first_name)
else
@profiles = Profile.all.order(:first_name)
end
respond_to do |format|
format.html
format.csv { send_data @profiles.to_csv }
end
else
@profiles = Profile.order(:first_name)
end
respond_to do |format|
format.html
format.csv { send_data @profiles.to_csv }
end
end

def show
@profile = Profile.friendly.find(params[:id])
@profile = Profile.friendly.find(params[:id])
end


def new
@profile = Profile.new
@buildings = $buildings
Expand All @@ -76,26 +77,26 @@ def edit
end

def create
@profile = Profile.new(profile_params)
@profile.save
redirect_to @profile
@profile = Profile.new(profile_params)
@profile.save
redirect_to @profile
end

def update
@profile = Profile.friendly.find(params[:id])
@profile = Profile.friendly.find(params[:id])

if @profile.update(profile_params)
redirect_to @profile
else
render "edit"
render "edit"
end
end

def destroy
@profile = Profile.friendly.find(params[:id])
@profile.destroy
@profile = Profile.friendly.find(params[:id])
@profile.destroy

redirect_to profiles_path
redirect_to profiles_path
end

def units
Expand All @@ -104,7 +105,6 @@ def units
@profiles = Profile.where("unit=?", params[:id])
end


private

def profile_params
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module ApplicationHelper
end
2 changes: 2 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

class ApplicationJob < ActiveJob::Base
end
2 changes: 2 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout "mailer"
Expand Down
2 changes: 2 additions & 0 deletions 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
Loading
Loading