Added lints for ERB templates #609

Merged
igor-alexandrov merged 5 commits from erblint into main 2024-04-09 20:08:58 +08:00
igor-alexandrov commented 2024-04-08 20:06:09 +08:00 (Migrated from github.com)

This PR adds lints to the ERB templates. Yes, erblint is not perfect, however currently it is the only solution that exists and works.

I fixed existing errors and added erblint step to the CI.

This PR adds lints to the ERB templates. Yes, `erblint` is not perfect, however currently it is the only solution that exists and works. I fixed existing errors and added `erblint` step to the CI.
zachgoll (Migrated from github.com) reviewed 2024-04-08 21:30:58 +08:00
zachgoll (Migrated from github.com) left a comment

Thanks for the cleanup! Just left a few potential suggestions.

Thanks for the cleanup! Just left a few potential suggestions.
@@ -55,2 +55,4 @@
run: bin/rubocop -f github
- name: Lint templates for consistent style
run: ./bin/erblint ./app/**/*.erb
zachgoll (Migrated from github.com) commented 2024-04-08 20:50:25 +08:00

Could we keep this all in a single lint job with multiple steps to lint Ruby and ERB?

Also, is there a reason we're not calling ./bin/erblint --lint-all?

Could we keep this all in a single `lint` job with multiple steps to lint Ruby and ERB? Also, is there a reason we're not calling `./bin/erblint --lint-all`?
@@ -43,6 +43,7 @@ group :development, :test do
gem "dotenv-rails"
gem "letter_opener"
gem "i18n-tasks"
gem "erb_lint"
zachgoll (Migrated from github.com) commented 2024-04-08 21:29:38 +08:00

What do you think of adding a .erb-lint.yml file for a bit more explicitness and integrating with our Rubocop setup?

EnableDefaultLinters: true
linters:
  Rubocop:
    enabled: true
    rubocop_config:
      inherit_from:
        - .rubocop.yml
What do you think of adding a `.erb-lint.yml` file for a bit more explicitness and integrating with our Rubocop setup? ```yml EnableDefaultLinters: true linters: Rubocop: enabled: true rubocop_config: inherit_from: - .rubocop.yml ```
igor-alexandrov (Migrated from github.com) reviewed 2024-04-08 22:01:18 +08:00
@@ -55,2 +55,4 @@
run: bin/rubocop -f github
- name: Lint templates for consistent style
run: ./bin/erblint ./app/**/*.erb
igor-alexandrov (Migrated from github.com) commented 2024-04-08 22:01:18 +08:00

@zachgoll I merged two tasks into one. I prefer calling ./bin/erblint ./app/**/*.erb because of explicitness, but --lint-all also makes sense, updated.

@zachgoll I merged two tasks into one. I prefer calling `./bin/erblint ./app/**/*.erb` because of explicitness, but `--lint-all` also makes sense, updated.
igor-alexandrov (Migrated from github.com) reviewed 2024-04-08 22:24:36 +08:00
@@ -43,6 +43,7 @@ group :development, :test do
gem "dotenv-rails"
gem "letter_opener"
gem "i18n-tasks"
gem "erb_lint"
igor-alexandrov (Migrated from github.com) commented 2024-04-08 22:24:35 +08:00

@zachgoll Yes, I forget about the config for the erblint. At the same time, I am completely against enabling all Rubocop rules for erblint. I tried doing this locally, and I got about 3500 errors with only 3000 auto-correctable. Besides this, some HTML tags started to look really strange after the automatic correction.

@zachgoll Yes, I forget about the config for the `erblint`. At the same time, I am completely against enabling all Rubocop rules for `erblint`. I tried doing this locally, and I got about 3500 errors with only 3000 auto-correctable. Besides this, some HTML tags started to look really strange after the automatic correction.
igor-alexandrov (Migrated from github.com) reviewed 2024-04-08 22:25:16 +08:00
@@ -43,6 +43,7 @@ group :development, :test do
gem "dotenv-rails"
gem "letter_opener"
gem "i18n-tasks"
gem "erb_lint"
igor-alexandrov (Migrated from github.com) commented 2024-04-08 22:25:16 +08:00

I added .erb-lint.yml, please check.

I added `.erb-lint.yml`, please check.
zachgoll (Migrated from github.com) reviewed 2024-04-08 22:54:15 +08:00
@@ -43,6 +43,7 @@ group :development, :test do
gem "dotenv-rails"
gem "letter_opener"
gem "i18n-tasks"
gem "erb_lint"
zachgoll (Migrated from github.com) commented 2024-04-08 22:54:15 +08:00

Sounds good, and very understandable on the rubocop integration. I'm all for auto checks, but not if it's going to slow us down too much.

Sounds good, and very understandable on the rubocop integration. I'm all for auto checks, but not if it's going to slow us down too much.
zachgoll (Migrated from github.com) approved these changes 2024-04-08 22:56:16 +08:00
zachgoll (Migrated from github.com) left a comment

Looks good! Thanks again for the cleanup 👍

Looks good! Thanks again for the cleanup 👍
zachgoll commented 2024-04-08 22:57:27 +08:00 (Migrated from github.com)

@igor-alexandrov looks like the --lint-all picked up vendor code. Could probably add to the config:

exclude:
  - '**/vendor/**/*'

??

@igor-alexandrov looks like the `--lint-all` picked up vendor code. Could probably add to the config: ```yml exclude: - '**/vendor/**/*' ``` ??
igor-alexandrov commented 2024-04-08 23:04:36 +08:00 (Migrated from github.com)

erblint can be tricky. I prefer to have a very explicit call that will only lint files inside of an ./app folder.

`erblint` can be tricky. I prefer to have a very explicit call that will only lint files inside of an `./app` folder.
adrienpoly commented 2024-04-08 23:04:49 +08:00 (Migrated from github.com)

Very nice addition

with the linters growing in the CI (in the future we could have i18n-tasks, eslint etc) I usually add to my project a small utility to run them all in a single command

something like that in bin/lint

#!/usr/bin/env bash

# Exit when any command fails
set -e

# Check Ruby code formatting
echo "Checking Ruby code formatting..."
bundle exec rubocop -A

# Check erb file formatting
echo "Checking erb file formatting..."
bundle exec erblint --lint-all --autocorrect
Very nice addition with the linters growing in the CI (in the future we could have i18n-tasks, eslint etc) I usually add to my project a small utility to run them all in a single command something like that in `bin/lint` ```bash #!/usr/bin/env bash # Exit when any command fails set -e # Check Ruby code formatting echo "Checking Ruby code formatting..." bundle exec rubocop -A # Check erb file formatting echo "Checking erb file formatting..." bundle exec erblint --lint-all --autocorrect ```
igor-alexandrov commented 2024-04-09 00:46:46 +08:00 (Migrated from github.com)

@adrienpoly I will open a new PR for this. Thank you for this suggestion.

@adrienpoly I will open a new PR for this. Thank you for this suggestion.
Sign in to join this conversation.