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

Init setup to lint HTML & HTML ERB files #730

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
Open

Init setup to lint HTML & HTML ERB files #730

wants to merge 11 commits into from

Conversation

Splines
Copy link
Member

@Splines Splines commented Dec 15, 2024

New HTML Linters

With version 2.1.0, I've made my eslint-plugin-erb ready to be pluggable into html-eslint, also see my comment on this issue. This allows us to lint the pure HTML part (in .html and .html.erb files).

To also lint the ERB tags inside .html.erb files, I set up Shopify's erb_lint and deactivate purely HTML-specific linters. This allows us to have RuboCop look over the ERB tags and many other linters which is quite nice.


VSCode Integration

  • ESLint is already included in our setup as VSCode extension, such that you will now also get support for any HTML files. I've added respective rules for this.

Tip

After having checked out this branch, you have to update your NPM dependencies, i.e. yarn install. Otherwise, no linting with ESLint will work anymore.

  • erb_lint only offers a CLI tool. I've also tried out this ERB Linter extension but it didn't quite work for me. So, instead, I've added this Run on Save extension and let it run the erb_lint CLI every time the file is saved. I've also added the respective CLI command to a new just lint erb command.
    Note that compared to the speed of ESLint wrapped inside the extension, this is really slow as bundle exec has to invoked and then erb_lint itself seems to be quite slow. So what you will experience is quick linting for HTML, then wait a bit to also get ERB parts auto-corrected.
    In the future, we might consider finding (or writing our own small) VSCode extension such that erb_lint can run more quickly on files as it doesn't have to use the terminal and instead can be directly integrated as formatter into the VSCode API.

Tip

I've added a new recommended extension (Run on Save) to our workspace that you should install in order for erb_lint to work automatically as soon as you save the file.

Warning

erb_lint will overwrite the file content. As it is slow, you might have already adjusted the file in the meantime. VSCode will then show a popup "The content on disk is newer...". As this is quite annoying, I've added the "files.saveConflictResolution": "overwriteFileOnDisk",. This also means: don't edit files outside of VSCode for MaMpf, otherwise you might loose some code!


Reviewers

This PR is currently in draft as I want to experiment a bit more with all the rules that html-eslint provides. Feel free to do the same and see the effects on some real-world examples in our codebase. After this PR, I will file another PR that does something like this:

yarn run eslint --config ./.config/eslint.mjs --max-warnings 0

and additionally adds the --fix option.

I also hope that html-eslint will get a max-length for lines, see my feature request here: yeonjuan/html-eslint#251.

@Splines Splines added the ide Related to integrated developer environments, e.g. VSCode etc. label Dec 15, 2024
@Splines Splines self-assigned this Dec 15, 2024
f-buerckel

This comment was marked as duplicate.

@f-buerckel f-buerckel self-requested a review December 30, 2024 15:33
Copy link
Collaborator

@f-buerckel f-buerckel left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ide Related to integrated developer environments, e.g. VSCode etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants