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

Add rubocop linter and CI job #579

merged 2 commits into from
Jun 17, 2024

Conversation

murny
Copy link
Collaborator

@murny murny commented May 30, 2024

#522

This MR adds Rubcop using StandardRB and other Rubocop addons. This MR fixes all the violations that currently exists and turns on a CI job for rubocop linting going forward.

Uses the new style guide for rubocop from Rails: https://github.com/rails/rubocop-rails-omakase

Which should be a very lightweight style guide. We could later on use the one from Jupiter or go to something like Standard

Decided to use Standard instead, via rubocop.yml. As Connor discovered, many places where tab/spacing wasn't done right with rubocop-rails-omakase. So instead of trying to fix and turn on some custom cops that will fix the spacing, decided to just use Standard instead.

Most corrections are the following:

  • Use double quotes for strings
  • Spacing (spaces in arrays, 2 spaces for tabs, spacing before assignment, etc)
  • Don't use hash rockets for hashes
  • Special comment for frozen string literals on every ruby file

@murny murny changed the title Add rubocop-rails-omakase, autofix violations and turn on CI job Add rubocop linter and CI job May 30, 2024
@@ -307,7 +344,12 @@ GEM
zeitwerk (2.6.13)

PLATFORMS
ruby
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This wasn't working for me with Github Actions. Believe you don't use ruby anymore and instead break it down by individual platforms like so (this is what a newly generated Rails app will do it appears)

@@ -1,113 +1,113 @@
class ProfilesController < ApplicationController
$units = {:access => "Access Services",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mainly whitespace diffs (2 spaces for tabs vs the previous 4 spaces for tabs). Also use symbols over hash rockets.

@murny murny marked this pull request as ready for review June 4, 2024 17:08
Copy link
Contributor

@ConnorSheremeta ConnorSheremeta left a comment

Choose a reason for hiding this comment

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

Noticed some indentation issues, Layout/IndentationWidth is disabled in rubocop-rails-omakase (https://github.com/rails/rubocop-rails-omakase/blob/1c1962b59c5135ed2168fd26229224e9a1c53c8e/rubocop.yml#L70) which I suspect is why these are not flagged as rubocop violations. Everything else looks good to me other than that!

friendly_id :full_name, use: :slugged
def full_name
"#{first_name}-#{last_name}"
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Extra indentation here

t.string :liason
t.timestamps null: false
t.string :first_name
t.string :last_name
Copy link
Contributor

Choose a reason for hiding this comment

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

Extra indentation until line 21

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, good catches. Yeah, not a fan of this 🤔.

Wonder if we can just turn that Layout/IndentationWidth cop you found back on as a one off and this problem goes away.

Will try to do this.

end
def self.to_csv(options = {})
CSV.generate(options) do |csv|
csv << column_names
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 below

@profiles = @heads + @staff
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

path = request.url
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

digrepo: "Digital Repository & Data Services",
dsc: "Digital Scholarship Centre",
facilities: "Facilities",
health: "Faculty Engagement (Health Sciences)",
Copy link
Contributor

Choose a reason for hiding this comment

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

Extra indentation here and on line 16

stratigic: "Strategic Partnerships",
tl: "Teaching & Learning",
ux: "User Experience" }
$buildings = { augustana: "Augustana Campus Library",
Copy link
Contributor

Choose a reason for hiding this comment

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

Extra indentation here


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

Choose a reason for hiding this comment

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

Extra indentation here along with others up until line 98

@murny
Copy link
Collaborator Author

murny commented Jun 14, 2024

Hey @ConnorSheremeta, Trica said your back today. Need another review here if you can 🙏.

Main difference is I switched to Standard over Rails-omakase, due to those weird spacing issues you discovered.

Copy link
Contributor

@ConnorSheremeta ConnorSheremeta left a comment

Choose a reason for hiding this comment

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

Looks good to me! I am however curious about linting being done on CI in a separate job rather than as a step in the main job (which is how jupiter is setup)

I wonder if the runtime of those checks would differ having a different setup 🤔

class Profile < ActiveRecord::Base
# frozen_string_literal: true

class Profile < ApplicationRecord
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

csv << column_names
all.each do |product|
csv << product.attributes.values_at(*column_names)
find_each do |product|
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -84,9 +86,9 @@
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger = ActiveSupport::Logger.new($stdout)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

config.exception_level_filters.merge!({
"ActionController::RoutingError" => "ignore"
})
config.exception_level_filters["ActionController::RoutingError"] = "ignore"
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -83,9 +85,9 @@
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")

if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger = ActiveSupport::Logger.new($stdout)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@murny
Copy link
Collaborator Author

murny commented Jun 17, 2024

Looks good to me! I am however curious about linting being done on CI in a separate job rather than as a step in the main job (which is how jupiter is setup)

I wonder if the runtime of those checks would differ having a different setup 🤔

It's still using the same runtime. ruby/setup-ruby@v1 will set up ruby and bundle install using the project's Gemfile (so we are using the same Rubocop version the project is using). So it should be the exactly same thing just with fewer dependencies involved (don't need a DB, JavaScript runtime, etc to run ruby linter).

This also allows the linter job and test job to run parallel together (which might not be big on a small app but in theory means faster CI runs).

Don't really see much concern here, especially when GitHub Actions is free (I think?) to run it parallelized like this.

@murny murny merged commit b48ea72 into master Jun 17, 2024
2 checks passed
@murny murny deleted the add-rubocop branch June 17, 2024 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants