From 30d391adda31b441a5c67d4ca51438f5a5976476 Mon Sep 17 00:00:00 2001
From: syed-ali-tw
Date: Tue, 6 Aug 2024 15:47:35 +0100
Subject: [PATCH 1/3] Add erb_lint dependency for erb file linting
---
.erb-lint.yml | 40 ++++++++++++++++++++++++++++++++++++++++
Gemfile | 1 +
Gemfile.lock | 16 ++++++++++++++++
lib/tasks/lint.rake | 5 +++++
4 files changed, 62 insertions(+)
create mode 100644 .erb-lint.yml
diff --git a/.erb-lint.yml b/.erb-lint.yml
new file mode 100644
index 000000000..fc4af28c2
--- /dev/null
+++ b/.erb-lint.yml
@@ -0,0 +1,40 @@
+---
+EnableDefaultLinters: false
+glob: "**/*.{html,text,js}{+*,}.erb"
+exclude:
+ - '**/vendor/**/*'
+ - '**/node_modules/**/*'
+linters:
+ SpaceAroundErbTag:
+ enabled: true
+ Rubocop:
+ enabled: true
+ exclude:
+ - "**/vendor/**/*"
+ - "**/vendor/**/.*"
+ - "bin/**"
+ - "db/**/*"
+ - "spec/**/*"
+ - "config/**/*"
+ - "node_modules/**/*"
+ rubocop_config:
+ inherit_from:
+ - .rubocop.yml
+ AllCops:
+ DisabledByDefault: true
+ Layout/InitialIndentation:
+ Enabled: false
+ Layout/TrailingEmptyLines:
+ Enabled: false
+ Layout/TrailingWhitespace:
+ Enabled: false
+ Naming/FileName:
+ Enabled: false
+ Style/FrozenStringLiteralComment:
+ Enabled: false
+ Layout/LineLength:
+ Enabled: false
+ Lint/UselessAssignment:
+ Enabled: false
+ Layout/FirstHashElementIndentation:
+ Enabled: false
diff --git a/Gemfile b/Gemfile
index cf012ca12..4e2045ff6 100644
--- a/Gemfile
+++ b/Gemfile
@@ -6,6 +6,7 @@ gem "aws-sdk-s3", "~> 1"
gem "bootsnap", require: false
gem "bootstrap-kaminari-views"
gem "diffy"
+gem "erb_lint"
gem "erubis"
gem "flipflop"
gem "gds-api-adapters"
diff --git a/Gemfile.lock b/Gemfile.lock
index cdcfd6ade..e29141c29 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -96,6 +96,13 @@ GEM
aws-sigv4 (1.9.1)
aws-eventstream (~> 1, >= 1.0.2)
base64 (0.2.0)
+ 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)
bootsnap (1.18.4)
msgpack (~> 1.2)
@@ -143,6 +150,13 @@ GEM
diffy (3.4.2)
docile (1.4.0)
domain_name (0.6.20240107)
+ 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)
erubis (2.7.0)
execjs (2.9.1)
@@ -748,6 +762,7 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
+ smart_properties (1.17.0)
snaky_hash (2.0.1)
hashie
version_gem (~> 1.1, >= 1.1.1)
@@ -819,6 +834,7 @@ DEPENDENCIES
climate_control
database_cleaner-mongoid
diffy
+ erb_lint
erubis
factory_bot_rails
flipflop
diff --git a/lib/tasks/lint.rake b/lib/tasks/lint.rake
index 3817bfb01..28def6270 100644
--- a/lib/tasks/lint.rake
+++ b/lib/tasks/lint.rake
@@ -1,5 +1,10 @@
desc "Run all linters"
task lint: :environment do
+ if Rails.env.development?
+ sh "bundle exec erblint --lint-all --autocorrect"
+ else
+ sh "bundle exec erblint --lint-all"
+ end
sh "bundle exec rubocop"
sh "yarn run lint"
end
From f4725a90e011d96d4ac3596f0bbfe99c02cdf16c Mon Sep 17 00:00:00 2001
From: syed-ali-tw
Date: Tue, 6 Aug 2024 15:48:51 +0100
Subject: [PATCH 2/3] Autocorrect erb_lint violations
---
app/views/answers/_fields.html.erb | 6 +--
app/views/artefacts/new.html.erb | 6 +--
app/views/campaigns/_fields.html.erb | 4 +-
app/views/campaigns/_image_upload.html.erb | 2 +-
.../completed_transactions/_fields.html.erb | 34 ++++++++---------
app/views/downtimes/_datetime_fields.html.erb | 4 +-
app/views/downtimes/_form.html.erb | 2 +-
app/views/downtimes/_time_input.html.erb | 11 +++---
app/views/downtimes/delete.html.erb | 10 ++---
app/views/downtimes/edit.html.erb | 14 +++----
app/views/downtimes/index.html.erb | 12 +++---
app/views/downtimes/new.html.erb | 14 +++----
app/views/editions/_reviewer_field.html.erb | 2 +-
app/views/editions/diagram.html.erb | 2 +-
app/views/editions/diff.html.erb | 2 +-
app/views/editions/show.html.erb | 10 ++---
.../event_mailer/_approve_fact_check.text.erb | 2 +-
.../event_mailer/_approve_review.text.erb | 2 +-
app/views/event_mailer/_assign.text.erb | 4 +-
.../_cancel_scheduled_publishing.text.erb | 2 +-
app/views/event_mailer/_create.text.erb | 2 +-
app/views/event_mailer/_new_version.text.erb | 2 +-
app/views/event_mailer/_publish.text.erb | 2 +-
.../event_mailer/_receive_fact_check.text.erb | 2 +-
.../event_mailer/_request_amendments.text.erb | 2 +-
.../event_mailer/_request_review.text.erb | 2 +-
.../event_mailer/_resend_fact_check.text.erb | 2 +-
.../_schedule_for_publishing.text.erb | 2 +-
.../event_mailer/_send_fact_check.text.erb | 4 +-
.../event_mailer/_skip_fact_check.text.erb | 2 +-
app/views/event_mailer/_skip_review.text.erb | 2 +-
app/views/event_mailer/_start_work.text.erb | 2 +-
.../event_mailer/request_fact_check.text.erb | 2 +-
app/views/guides/_fields.html.erb | 8 ++--
app/views/help_pages/_fields.html.erb | 6 +--
.../homepage/popular_links/_sidebar.html.erb | 8 ++--
.../_version_and_status.html.erb | 8 ++--
.../homepage/popular_links/edit.html.erb | 8 ++--
.../homepage/popular_links/show.html.erb | 6 +--
app/views/layouts/design_system.html.erb | 4 +-
app/views/layouts/legacy_application.html.erb | 14 +++----
app/views/legacy_root/_amends_needed.html.erb | 2 +-
app/views/legacy_root/_archived.html.erb | 2 +-
app/views/legacy_root/_drafts.html.erb | 2 +-
.../legacy_root/_fact_check_received.html.erb | 2 +-
app/views/legacy_root/_in_review.html.erb | 2 +-
.../legacy_root/_out_for_fact_check.html.erb | 2 +-
app/views/legacy_root/_publication.html.erb | 12 +++---
app/views/legacy_root/_published.html.erb | 2 +-
app/views/legacy_root/_ready.html.erb | 2 +-
.../_scheduled_for_publishing.html.erb | 2 +-
app/views/legacy_root/index.html.erb | 12 +++---
app/views/licences/_fields.html.erb | 6 +--
app/views/licences/new.html.erb | 6 +--
.../_link_check_report.html.erb | 10 ++---
app/views/link_check_reports/create.js.erb | 2 +-
app/views/link_check_reports/show.js.erb | 2 +-
.../_devolved_administrations.html.erb | 8 ++--
app/views/local_transactions/_fields.html.erb | 12 +++---
app/views/local_transactions/new.html.erb | 6 +--
app/views/places/_fields.html.erb | 10 ++---
app/views/programmes/_fields.html.erb | 6 +--
app/views/reports/index.html.erb | 32 ++++++++--------
app/views/shared/_clone_buttons.html.erb | 2 +-
.../_common_edition_attributes.html.erb | 6 +--
.../shared/_common_part_attributes.html.erb | 14 +++----
.../shared/_edition_activity_fields.html.erb | 15 +++++---
app/views/shared/_edition_header.html.erb | 4 +-
app/views/shared/_error_summary.html.erb | 2 +-
app/views/shared/_fact_check.html.erb | 2 +-
.../shared/_fact_check_received.html.erb | 8 ++--
app/views/shared/_flash.html.erb | 6 +--
app/views/shared/_history.html.erb | 8 ++--
app/views/shared/_important_note.html.erb | 4 +-
app/views/shared/_metadata.html.erb | 8 ++--
app/views/shared/_part.html.erb | 2 +-
app/views/shared/_ready.html.erb | 4 +-
.../_ready_or_review_or_fact_check.html.erb | 10 ++---
.../shared/_related_external_links.html.erb | 6 +--
app/views/shared/_review.html.erb | 8 ++--
app/views/shared/_tagging.html.erb | 38 +++++++++----------
app/views/shared/_unpublish.html.erb | 6 +--
app/views/shared/_workflow_buttons.html.erb | 6 +--
.../simple_smart_answers/_fields.html.erb | 6 +--
app/views/simple_smart_answers/_node.html.erb | 6 +--
app/views/transactions/_fields.html.erb | 16 ++++----
app/views/user_search/index.html.erb | 6 +--
app/views/videos/_fields.html.erb | 6 +--
88 files changed, 289 insertions(+), 287 deletions(-)
diff --git a/app/views/answers/_fields.html.erb b/app/views/answers/_fields.html.erb
index 5706828cc..ad99bef3b 100644
--- a/app/views/answers/_fields.html.erb
+++ b/app/views/answers/_fields.html.erb
@@ -5,15 +5,15 @@
Edit Answer
- <%= render :partial => 'shared/common_edition_attributes', :locals => {:f => f} %>
+ <%= render :partial => "shared/common_edition_attributes", :locals => {:f => f} %>
<%= form_group(f, :body) do %>
<%= f.text_area :body, rows: 20, disabled: @resource.locked_for_edits?, class: "input-md-10 form-control", data: {
- module: "paste-html-to-govspeak"
+ module: "paste-html-to-govspeak",
} %>
<% end %>
-<%= render partial: 'shared/workflow_buttons', locals: { f: f } %>
+<%= render partial: "shared/workflow_buttons", locals: { f: f } %>
diff --git a/app/views/artefacts/new.html.erb b/app/views/artefacts/new.html.erb
index be7bda516..4f1818c5c 100644
--- a/app/views/artefacts/new.html.erb
+++ b/app/views/artefacts/new.html.erb
@@ -1,11 +1,11 @@
<%= content_for :page_title, "New artefact" %>
-<%= form_for(@artefact, html: { class: 'artefact', id: 'edit_artefact' }) do |f| %>
+<%= form_for(@artefact, html: { class: "artefact", id: "edit_artefact" }) do |f| %>
<% end %>
@@ -78,7 +78,7 @@
<% if @resource.important_note %>
<%= form_for(@resource.important_note, :url=> resolve_note_path, :html => { :class => "add-left-margin inline" }, :method => "put") do |f| %>
<%= hidden_field_tag :edition_id, resource.id %>
- <%= f.submit :class=>"btn btn-default", :value => 'Delete important note' %>
+ <%= f.submit :class=>"btn btn-default", :value => "Delete important note" %>
<% end %>
<% end %>
@@ -96,6 +96,6 @@
- <%= render collection: @resource.history, partial: '/shared/edition_history', as: 'edition' %>
+ <%= render collection: @resource.history, partial: "/shared/edition_history", as: "edition" %>
diff --git a/app/views/shared/_important_note.html.erb b/app/views/shared/_important_note.html.erb
index f066f0d7d..f3222b36b 100644
--- a/app/views/shared/_important_note.html.erb
+++ b/app/views/shared/_important_note.html.erb
@@ -5,8 +5,8 @@
<%= action_note(@resource.important_note) %>
- Note <%= with_history ? 'updated' : 'created' %>
- <% if important_note.requester.present? %> by <%= mail_to important_note.requester.email, important_note.requester.name, { class: 'link-inherit' } %><% end %>
+ Note <%= with_history ? "updated" : "created" %>
+ <% if important_note.requester.present? %> by <%= mail_to important_note.requester.email, important_note.requester.name, { class: "link-inherit" } %><% end %>
<% if with_history %>
– See history
<% end %>
diff --git a/app/views/shared/_metadata.html.erb b/app/views/shared/_metadata.html.erb
index 1b5d06293..a4f608118 100644
--- a/app/views/shared/_metadata.html.erb
+++ b/app/views/shared/_metadata.html.erb
@@ -1,7 +1,7 @@
Metadata
<% if Edition::PUBLISHING_API_DRAFT_STATES.include? publication.state %>
- <%= form_for(@artefact, :html => { :class => 'artefact', :id => 'edit_artefact'}) do |f| %>
+ <%= form_for(@artefact, :html => { :class => "artefact", :id => "edit_artefact"}) do |f| %>
<%= f.hidden_field :id, value: @artefact.id %>
@@ -15,14 +15,14 @@
<% end %>
- <%= f.submit 'Update metadata', class: "btn btn-success btn-large" %>
+ <%= f.submit "Update metadata", class: "btn btn-success btn-large" %>
<% end %>
<% else %>
- <% @artefact.attributes.slice('slug', 'language').each do |key, value| %>
+ <% @artefact.attributes.slice("slug", "language").each do |key, value| %>
<%= content_tag :label, key.humanize, for: key %>
- <%= text_field_tag key, value, class: "form-control add-bottom-margin", disabled: 'disabled' %>
+ <%= text_field_tag key, value, class: "form-control add-bottom-margin", disabled: "disabled" %>
<% end %>
diff --git a/app/views/shared/_part.html.erb b/app/views/shared/_part.html.erb
index 1e22f8051..d30214eb7 100644
--- a/app/views/shared/_part.html.erb
+++ b/app/views/shared/_part.html.erb
@@ -1,5 +1,5 @@
<%= form_group(f, :body) do %>
<%= f.text_area :body, rows: 25, disabled: @resource.locked_for_edits?, class: "input-md-7 form-control body", data: {
- module: "paste-html-to-govspeak"
+ module: "paste-html-to-govspeak",
} %>
<% end %>
diff --git a/app/views/shared/_ready.html.erb b/app/views/shared/_ready.html.erb
index 6802601ba..abb5697c9 100644
--- a/app/views/shared/_ready.html.erb
+++ b/app/views/shared/_ready.html.erb
@@ -1,6 +1,6 @@
- <% if current_user.has_editor_permissions?(@resource)%>
+ <% if current_user.has_editor_permissions?(@resource) %>
Request this edition to be amended further.
- <%= render 'shared/request_amendments' %>
+ <%= render "shared/request_amendments" %>
<% end %>
diff --git a/app/views/shared/_ready_or_review_or_fact_check.html.erb b/app/views/shared/_ready_or_review_or_fact_check.html.erb
index 786e5305a..94a3d3116 100644
--- a/app/views/shared/_ready_or_review_or_fact_check.html.erb
+++ b/app/views/shared/_ready_or_review_or_fact_check.html.erb
@@ -1,14 +1,14 @@
<% if @resource.in_review? %>
- <%= render '/shared/review' %>
+ <%= render "/shared/review" %>
<% elsif @resource.fact_check? %>
- <%= render '/shared/fact_check' %>
+ <%= render "/shared/fact_check" %>
<% elsif @resource.fact_check_received? %>
- <%= render '/shared/fact_check_received' %>
+ <%= render "/shared/fact_check_received" %>
<% elsif @resource.fact_check_skipped? %>
Fact check was skipped for this edition.
- <%= render '/shared/ready' %>
+ <%= render "/shared/ready" %>
<% elsif @resource.ready? %>
- <%= render '/shared/ready' %>
+ <%= render "/shared/ready" %>
<% end %>
diff --git a/app/views/shared/_related_external_links.html.erb b/app/views/shared/_related_external_links.html.erb
index b168f8bdb..ecc86758f 100644
--- a/app/views/shared/_related_external_links.html.erb
+++ b/app/views/shared/_related_external_links.html.erb
@@ -12,11 +12,11 @@
<%= link.label :title, "Title" %>
- <%= link.text_field :title, class: 'form-control' %>
+ <%= link.text_field :title, class: "form-control" %>
<%= link.label :url, "URL" %>
- <%= link.text_field :url, class: 'form-control' %>
+ <%= link.text_field :url, class: "form-control" %>
<% unless @resource.retired_format? %>
<%= link.link_to_remove "Remove this URL", class: "remove-row remove-row-related" %>
@@ -34,6 +34,6 @@
<% unless @resource.retired_format? %>
- <%= f.submit 'Save links', class: "btn btn-success btn-large" %>
+ <%= f.submit "Save links", class: "btn btn-success btn-large" %>
<% end %>
<% end %>
diff --git a/app/views/shared/_review.html.erb b/app/views/shared/_review.html.erb
index 138a56d48..180ae2dd6 100644
--- a/app/views/shared/_review.html.erb
+++ b/app/views/shared/_review.html.erb
@@ -8,17 +8,17 @@
<% else %>
<%= @resource.latest_status_action(Action::REQUEST_REVIEW).requester.name %> has sent this edition to be reviewed.
- <%= review_buttons(@resource)%>
+ <%= review_buttons(@resource) %>
<% if activity_forms_required? %>
- <%= review_forms(@resource)%>
+ <%= review_forms(@resource) %>
<% end %>
<% end %>
<% else %>
We're having trouble accessing the action data. This edition has been sent to be reviewed.
- <%= review_buttons(@resource)%>
+ <%= review_buttons(@resource) %>
- <%= review_forms(@resource)%>
+ <%= review_forms(@resource) %>
<% end %>
diff --git a/app/views/shared/_tagging.html.erb b/app/views/shared/_tagging.html.erb
index b3f11bbb7..20d5b83fd 100644
--- a/app/views/shared/_tagging.html.erb
+++ b/app/views/shared/_tagging.html.erb
@@ -7,13 +7,13 @@