From 247bad89a0afde1dbf44689c048fdb0f7e0960f5 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Thu, 24 Jul 2025 11:38:55 +0300 Subject: [PATCH 01/12] setting up ERB linting (ACTION WILL NOT PASS) --- .better-html.yml | 3 +++ .erb_lint.yml | 22 ++++++++++++++++++++++ .github/workflows/ci-cd.yml | 23 +++++++++++++++++++++++ Gemfile | 1 + Gemfile.lock | 16 ++++++++++++++++ app/views/admin/create_site.html.erb | 2 +- 6 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 .better-html.yml create mode 100644 .erb_lint.yml diff --git a/.better-html.yml b/.better-html.yml new file mode 100644 index 000000000..7ef90a3d8 --- /dev/null +++ b/.better-html.yml @@ -0,0 +1,3 @@ +# https://github.com/Shopify/better-html#configuration + +allow_single_quoted_attributes: false diff --git a/.erb_lint.yml b/.erb_lint.yml new file mode 100644 index 000000000..109613091 --- /dev/null +++ b/.erb_lint.yml @@ -0,0 +1,22 @@ +# configuration reference: https://github.com/Shopify/erb_lint?tab=readme-ov-file#configuration + +EnableDefaultLinters: false + +exclude: + - 'config/**/*' + - 'db/**/*' + - 'scripts/**/*' + - 'bin/**/*' + - 'lib/namespaced_env_cache.rb' + - 'vendor/bundle/**/*' +glob: '**/*.{html,text,js}{+*,}.erb' + +linters: + ErbSafety: + enabled: true + better_html_config: .better-html.yml + Rubocop: + enabled: true + rubocop_config: + inherit_from: + - .rubocop.yml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index b52fedc41..03d2f501b 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -12,6 +12,28 @@ env: RAILS_ENV: test jobs: + erb_lint: + name: ERB checking + runs-on: ubuntu-latest + + strategy: + matrix: + ruby_version: [3.1, 3.2] + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + - name: Setup dependencies + run: | + sudo apt-get update -qq + sudo apt-get install -yqq libmagickwand-dev + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby_version }} + bundler-cache: true + - run: bundle exec erb_lint --lint-all + rubocop: name: Rubocop checking runs-on: ubuntu-latest @@ -118,6 +140,7 @@ jobs: runs-on: ubuntu-latest if: ${{ github.event_name == 'push' && github.actor != 'dependabot[bot]' }} needs: + - erb_lint - rubocop - typescript - tests diff --git a/Gemfile b/Gemfile index 47f6f9fc2..0cd2bfe84 100644 --- a/Gemfile +++ b/Gemfile @@ -51,6 +51,7 @@ gem 'whenever', '~> 1.0', require: false # Debugging, linting, testing. gem 'awesome_print', '~> 1.9' +gem 'erb_lint', '~> 0.9.0' gem 'rubocop', '~> 1' gem 'rubocop-rails', '~> 2.15' gem 'rubocop-rake', '~> 0.7.1' diff --git a/Gemfile.lock b/Gemfile.lock index 8eaa025e7..755dfa68b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -105,6 +105,13 @@ GEM base64 (0.3.0) bcrypt (3.1.20) benchmark (0.4.1) + better_html (2.1.1) + actionview (>= 6.0) + activesupport (>= 6.0) + ast (~> 2.0) + erubi (~> 1.4) + parser (>= 2.4) + smart_properties bigdecimal (3.2.2) bindex (0.8.1) builder (3.3.0) @@ -157,6 +164,13 @@ GEM e2mmap (0.1.0) erb (4.0.4) cgi (>= 0.3.3) + erb_lint (0.9.0) + activesupport + better_html (>= 2.0.1) + parser (>= 2.7.1.4) + rainbow + rubocop (>= 1) + smart_properties erubi (1.13.1) execjs (2.10.0) fastimage (2.4.0) @@ -405,6 +419,7 @@ GEM simplecov_json_formatter (~> 0.1) simplecov-html (0.13.1) simplecov_json_formatter (0.1.4) + smart_properties (1.17.0) spring (4.3.0) sprockets (4.1.1) concurrent-ruby (~> 1.0) @@ -483,6 +498,7 @@ DEPENDENCIES devise_saml_authenticatable (~> 1.9) diffy (~> 3.4) e2mmap (~> 0.1) + erb_lint (~> 0.9.0) fastimage (~> 2.2) flamegraph (~> 0.9) groupdate (~> 6.1) diff --git a/app/views/admin/create_site.html.erb b/app/views/admin/create_site.html.erb index 5333f94ad..feaa53b86 100644 --- a/app/views/admin/create_site.html.erb +++ b/app/views/admin/create_site.html.erb @@ -16,4 +16,4 @@

Once you are ready, click on the following button:

-To new site \ No newline at end of file +To new site From f9a3dbd4a9afb50b06b9ca537eb7c83231542fae Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Thu, 24 Jul 2025 11:42:43 +0300 Subject: [PATCH 02/12] do not even try to run tests if linting fails --- .github/workflows/ci-cd.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 03d2f501b..d19893570 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -73,6 +73,10 @@ jobs: tests: name: Ruby on Rails tests runs-on: ubuntu-latest + needs: + - erb_lint + - rubocop + - typescript strategy: matrix: From c74f0f6181035fcddfa1b6d353d43e77fe00385a Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Thu, 24 Jul 2025 11:48:43 +0300 Subject: [PATCH 03/12] fine, I'll specify permissions now, CodeQL --- .github/workflows/ci-cd.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index d19893570..9a3e6c522 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -11,6 +11,12 @@ on: env: RAILS_ENV: test +permissions: + actions: write + contents: read + issues: read + pull-requests: read + jobs: erb_lint: name: ERB checking From 05c15315b1a3f7f9fd8ca74e60123be3c6035c21 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Thu, 24 Jul 2025 12:02:32 +0300 Subject: [PATCH 04/12] disabled Layout/TrailingEmptyLines for ERB linting (~3K errors) --- .erb_lint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.erb_lint.yml b/.erb_lint.yml index 109613091..cf3ef4aa9 100644 --- a/.erb_lint.yml +++ b/.erb_lint.yml @@ -20,3 +20,5 @@ linters: rubocop_config: inherit_from: - .rubocop.yml + Layout/TrailingEmptyLines: + Enabled: false # enable when we are ready to solve ~3K errors From 14134b8dfb5e602d5d88da58ccf4936a18a3c9b6 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Thu, 24 Jul 2025 12:05:39 +0300 Subject: [PATCH 05/12] disabled Layout/InitialIndentation due to thousands of false positives --- .erb_lint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.erb_lint.yml b/.erb_lint.yml index cf3ef4aa9..31e8aa9bb 100644 --- a/.erb_lint.yml +++ b/.erb_lint.yml @@ -22,3 +22,5 @@ linters: - .rubocop.yml Layout/TrailingEmptyLines: Enabled: false # enable when we are ready to solve ~3K errors + Layout/InitialIndentation: + Enabled: false # false positives on embedded Ruby indentation in tags From 56e2f3e6e61aeae94e9ba4520fd3388fee41f469 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Thu, 24 Jul 2025 12:09:24 +0300 Subject: [PATCH 06/12] disabled Lint/UselessAssignment due to hundreds of false positives --- .erb_lint.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.erb_lint.yml b/.erb_lint.yml index 31e8aa9bb..3c999799c 100644 --- a/.erb_lint.yml +++ b/.erb_lint.yml @@ -20,7 +20,9 @@ linters: rubocop_config: inherit_from: - .rubocop.yml - Layout/TrailingEmptyLines: - Enabled: false # enable when we are ready to solve ~3K errors Layout/InitialIndentation: Enabled: false # false positives on embedded Ruby indentation in tags + Layout/TrailingEmptyLines: + Enabled: false # enable when we are ready to solve ~3K errors + Lint/UselessAssignment: + Enabled: false # false positives on single-line embedded Ruby assignments From 267401a470612242a2f867ba8630d2abd87d4471 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Thu, 24 Jul 2025 12:26:38 +0300 Subject: [PATCH 07/12] added specific files to ERB lint exclusion list as they cause clobbering --- .erb_lint.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.erb_lint.yml b/.erb_lint.yml index 3c999799c..586162de6 100644 --- a/.erb_lint.yml +++ b/.erb_lint.yml @@ -9,6 +9,17 @@ exclude: - 'bin/**/*' - 'lib/namespaced_env_cache.rb' - 'vendor/bundle/**/*' + # TODO: fix clobbering (autocorrect conflics) first: + - 'app/views/admin/_error_report.html.erb' + - 'app/views/categories/show.html.erb' + - 'app/views/micro_auth/authentication/initiate.html.erb' + - 'app/views/reactions/_form.html.erb' + - 'app/views/reports/reactions.html.erb' + - 'app/views/suggested_edit/category_index.html.erb' + - 'app/views/questions/_list.html.erb' + - 'app/views/tags/category.html.erb' + - 'app/views/users/_activity_items.html.erb' + glob: '**/*.{html,text,js}{+*,}.erb' linters: From a94cbf120fc81efb4c2eefb14233e9ff106b4a76 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Thu, 24 Jul 2025 12:31:28 +0300 Subject: [PATCH 08/12] disabled Layout/LeadingEmptyLine due to false positives --- .erb_lint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.erb_lint.yml b/.erb_lint.yml index 586162de6..d04c942d6 100644 --- a/.erb_lint.yml +++ b/.erb_lint.yml @@ -31,6 +31,8 @@ linters: rubocop_config: inherit_from: - .rubocop.yml + Layout/LeadingEmptyLines: + Enabled: false # false positives on embedded Ruby indentation in tags Layout/InitialIndentation: Enabled: false # false positives on embedded Ruby indentation in tags Layout/TrailingEmptyLines: From d44dc06648fc19965c29fc480b72ad3ed4290f4d Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Thu, 24 Jul 2025 12:44:38 +0300 Subject: [PATCH 09/12] disabled Layout/TrailingWhitespace due to false positives --- .erb_lint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.erb_lint.yml b/.erb_lint.yml index d04c942d6..93a4a25d6 100644 --- a/.erb_lint.yml +++ b/.erb_lint.yml @@ -37,5 +37,7 @@ linters: Enabled: false # false positives on embedded Ruby indentation in tags Layout/TrailingEmptyLines: Enabled: false # enable when we are ready to solve ~3K errors + Layout/TrailingWhitespace: + Enabled: false # false positives on embedded Ruby indentation in tags Lint/UselessAssignment: Enabled: false # false positives on single-line embedded Ruby assignments From daac18ca80b18a4ba4b739e4325a247d2810c59c Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Thu, 24 Jul 2025 15:03:46 +0300 Subject: [PATCH 10/12] removed matrices from linting jobs --- .github/workflows/ci-cd.yml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 9a3e6c522..070e266d0 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -10,6 +10,7 @@ on: env: RAILS_ENV: test + RUBY_VERSION: 3.2 permissions: actions: write @@ -22,10 +23,6 @@ jobs: name: ERB checking runs-on: ubuntu-latest - strategy: - matrix: - ruby_version: [3.1, 3.2] - steps: - name: Checkout repo uses: actions/checkout@v3 @@ -36,7 +33,7 @@ jobs: - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: ${{ matrix.ruby_version }} + ruby-version: ${{ env.RUBY_VERSION }} bundler-cache: true - run: bundle exec erb_lint --lint-all @@ -44,10 +41,6 @@ jobs: name: Rubocop checking runs-on: ubuntu-latest - strategy: - matrix: - ruby_version: [3.1, 3.2] - steps: - name: Checkout repo uses: actions/checkout@v3 @@ -58,7 +51,7 @@ jobs: - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: ${{ matrix.ruby_version }} + ruby-version: ${{ env.RUBY_VERSION }} bundler-cache: true - run: bundle exec rubocop From 038333408c3d876ada59e728b8ff8f6cff8e8e72 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Sat, 22 Aug 2026 03:01:03 +0300 Subject: [PATCH 11/12] resolve ci-cd conflicts --- .github/workflows/ci-cd.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 070e266d0..073e00c45 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -10,13 +10,13 @@ on: env: RAILS_ENV: test - RUBY_VERSION: 3.2 + RUBY_VERSION: 3.4 permissions: actions: write contents: read - issues: read - pull-requests: read + issues: write + pull-requests: write jobs: erb_lint: From 56c7a06d808740da40c61f091e376506ebdd13b2 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Sat, 22 Aug 2026 14:35:37 +0300 Subject: [PATCH 12/12] disable Style/MultilineTernaryOperator for now Blocking the whol linting until we settle on the style seems unreasonable --- .erb_lint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.erb_lint.yml b/.erb_lint.yml index d1f30c286..957d6a417 100644 --- a/.erb_lint.yml +++ b/.erb_lint.yml @@ -36,6 +36,8 @@ linters: - .rubocop.yml Layout/LeadingEmptyLines: Enabled: false # false positives on embedded Ruby indentation in tags + Style/MultilineTernaryOperator: + Enabled: false # enable when we settle on how we conditionally access locale strings Layout/InitialIndentation: Enabled: false # false positives on embedded Ruby indentation in tags Layout/TrailingEmptyLines: