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

Added lints for ERB templates #609

Merged
merged 5 commits into from
Apr 9, 2024
Merged

Conversation

igor-alexandrov
Copy link
Contributor

@igor-alexandrov igor-alexandrov commented Apr 8, 2024

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.

Copy link
Collaborator

@zachgoll zachgoll left a comment

Choose a reason for hiding this comment

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

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

bundler-cache: true

- name: Lint templates for consistent style
run: ./bin/erblint ./app/**/*.erb
Copy link
Collaborator

Choose a reason for hiding this comment

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

@@ -43,6 +43,7 @@ group :development, :test do
gem "dotenv-rails"
gem "letter_opener"
gem "i18n-tasks"
gem "erb_lint"
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Collaborator

@zachgoll zachgoll 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! Thanks again for the cleanup 👍

@zachgoll
Copy link
Collaborator

zachgoll commented Apr 8, 2024

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

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

??

@igor-alexandrov
Copy link
Contributor Author

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

@adrienpoly
Copy link
Contributor

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

@igor-alexandrov
Copy link
Contributor Author

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

@zachgoll zachgoll merged commit b5c56f7 into maybe-finance:main Apr 9, 2024
4 checks passed
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.

3 participants