Skip to content

Commit

Permalink
rubocop-ci-integration
Browse files Browse the repository at this point in the history
* precommit hook
  • Loading branch information
aktfrikshun authored Jun 23, 2022
1 parent aa15775 commit 454d140
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 19 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ To start/stop after building
To run tests (TBD -- this currently does not work with selenium web driver)
1. docker-compose run webapp rspec

## Code linting
- Run the script `./rubocop_autocorrect.sh` to fix standardize layout, style, and code using Rubocop
- copy the file ./pre-commit to your .git/hooks/ folder within the project to ensure changed files adhere to project standards, prior to commit.
- to get a commit through without running that pre-commit hook, use the --no-verify option

## License

See [LICENSE](LICENSE.md)
4 changes: 2 additions & 2 deletions app/controllers/admin/digital_products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def search
@digital_products = DigitalProduct.all
@digital_products = @digital_products.where("name ilike '%#{search_text}%'") if search_text && search_text.length >= 3
@digital_products = @digital_products.tagged_with(organization_id, context: 'organizations') if organization_id.present? && organization_id != ''
@digital_products = @digital_products.where('service = ?', params[:service]) if params[:service].present? && params[:service] != 'All'
@digital_products = @digital_products.where('aasm_state = ?', params[:aasm_state].downcase) if params[:aasm_state].present? && params[:aasm_state] != 'All'
@digital_products = @digital_products.where(service: params[:service]) if params[:service].present? && params[:service] != 'All'
@digital_products = @digital_products.where(aasm_state: params[:aasm_state].downcase) if params[:aasm_state].present? && params[:aasm_state] != 'All'
@digital_products
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin/digital_service_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ def search
@digital_service_accounts = DigitalServiceAccount.all
@digital_service_accounts = @digital_service_accounts.where("name ilike '%#{search_text}%'") if search_text && search_text.length >= 3
@digital_service_accounts = @digital_service_accounts.tagged_with(organization_id, context: 'organizations') if organization_id.present? && organization_id != ''
@digital_service_accounts = @digital_service_accounts.where('service = ?', params[:service]) if params[:service].present? && params[:service] != 'All'
@digital_service_accounts = @digital_service_accounts.where('aasm_state = ?', params[:aasm_state].downcase) if params[:aasm_state].present? && params[:aasm_state] != 'All'
@digital_service_accounts = @digital_service_accounts.where(service: params[:service]) if params[:service].present? && params[:service] != 'All'
@digital_service_accounts = @digital_service_accounts.where(aasm_state: params[:aasm_state].downcase) if params[:aasm_state].present? && params[:aasm_state] != 'All'
@digital_service_accounts
end

Expand Down
17 changes: 8 additions & 9 deletions app/controllers/admin/forms_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'csv'

module Admin
Expand Down Expand Up @@ -200,21 +201,19 @@ def create
@form.modal_button_text = t('form.help_improve')
@form.success_text_heading = t('success')
@form.success_text = t('form.submit_thankyou')
@form.delivery_method = "touchpoints-hosted-only"
@form.delivery_method = 'touchpoints-hosted-only'
@form.load_css = true
unless @form.user
@form.user = current_user
end
@form.user = current_user unless @form.user

respond_to do |format|
if @form.save
Event.log_event(Event.names[:form_created], "Form", @form.uuid,"Form #{@form.name} created at #{DateTime.now}", current_user.id)
Event.log_event(Event.names[:form_created], 'Form', @form.uuid, "Form #{@form.name} created at #{DateTime.now}", current_user.id)

UserRole.create!({
user: current_user,
form: @form,
role: UserRole::Role::FormManager
})
user: current_user,
form: @form,
role: UserRole::Role::FormManager,
})

format.html { redirect_to questions_admin_form_path(@form), notice: 'Survey was successfully created.' }
format.json { render :show, status: :created, location: @form }
Expand Down
6 changes: 2 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,12 @@ def self.deactivation_pending(expire_days)
def self.deactivate_inactive_accounts!
# Find all accounts scheduled to be deactivated in 14 days
users = User.active.where('(current_sign_in_at ISNULL AND created_at <= ?) OR (current_sign_in_at <= ?)', 90.days.ago, 90.days.ago)
users.each do |user|
user.deactivate!
end
users.each(&:deactivate!)
end

def self.to_csv
active_users = order('email')
return nil unless active_users.present?
return nil if active_users.blank?

header_attributes = %w[organization_name email current_sign_in_at]
attributes = active_users.map do |u|
Expand Down
1 change: 0 additions & 1 deletion app/views/admin/digital_service_accounts/_results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@
<% end %>
</tbody>
</table>

2 changes: 1 addition & 1 deletion app/views/admin/websites/dendrogram.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<script type="module">
export default function define(runtime, observer) {
const main = runtime.module();
const fileAttachments = new Map([["flare.json", new URL("/admin/websites/dendrogram_json.json/<%= '?office=true' if params["office"] == "true" %>", import.meta.url)]]);
const fileAttachments = new Map([["flare.json", new URL("/admin/websites/dendrogram_json.json/<%= '?office=true' if params["office"] == "true" %>", import.meta.url)]]);
main.builtin("FileAttachment", runtime.fileAttachments(name => fileAttachments.get(name)));

main.variable(observer("chart")).define("chart", ["tree", "d3", "data", "autoBox"], function(tree,d3,data,autoBox)
Expand Down
21 changes: 21 additions & 0 deletions pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env ruby

require 'english'
require 'rubocop'

ADDED_OR_MODIFIED = /A|AM|^M/.freeze

changed_files = `git status --porcelain`.split(/\n/).
select { |file_name_with_status|
file_name_with_status =~ ADDED_OR_MODIFIED
}.
map { |file_name_with_status|
file_name_with_status.split(' ')[1]
}.
select { |file_name|
File.extname(file_name) == '.rb'
}.join(' ')

system("rubocop #{changed_files}") unless changed_files.empty?

exit $CHILD_STATUS.exitstatus
5 changes: 5 additions & 0 deletions rubocop_autocorrect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e

rubocop -A app
rubocop -A spec

0 comments on commit 454d140

Please sign in to comment.