Shopify / erb_lint

Lint your ERB or HTML files
MIT License
661 stars 122 forks source link

Editor integration #225

Open manuelpuyol opened 3 years ago

manuelpuyol commented 3 years ago

Summary

erb-lint is a great tool to keep your ERB consistent and avoid known security issues, such as rendering raw inputs.

However, the linting process is usually late in the development process, typically being run during CI, which can slow down developers since they may only get notified of errors after opening a PR and getting the build to fail.

Proposal

Make erb-lint easy to integrate with editors (Vim, Emacs, VSCode...) so developers can have real-time feedback of the ERB they are editing.

Problems

The current output that erb-lint provides does not contain all the necessary information to decorate editors with the exact location of linting errors. Right now, it's only possible to get the line where the error occurs instead of the whole block (line + columns).

Solution

Adding a generic formatter that exposes more data about the error, such as a JSON formatter, similar to rubocop's formatter.

Exposing structured information about the errors in the file would allow better decorations for editors, like underlining the exact location of offenses.

Related

https://github.com/Shopify/erb-lint/issues/173 https://github.com/Shopify/erb-lint/pull/219 https://github.com/Shopify/erb-lint/pull/224

roelandxyz commented 3 years ago

vim is now supported: https://github.com/dense-analysis/ale/pull/3931

manuelpuyol commented 3 years ago

VSCode too https://marketplace.visualstudio.com/items?itemName=manuelpuyol.erb-linter

rafaelfranca commented 3 years ago

Maybe we should document in the README? Mind to open a PR?

vlasar commented 4 months ago

I'm attempting to integrate erb-lint for formatting into Neovim using https://github.com/stevearc/conform.nvim.

Is there way to silence the "report" without parsing the output manually?

By "report" I mean, for example, the following:

Linting and autocorrecting 1 files with 15 linters (11 autocorrectable)...

2 error(s) corrected in ERB files

The file gets correctly auto-fixed, but the report is appended to the top of the file.

SCR-20240604-otng
nickpoorman commented 3 months ago

Came here to comment the same thing as @vlasar. I would like to to using this in nvim conform with stdin mode so that it's fast but the report output injected at the top messes that up. Maybe it could have a quiet format like rubocop has. Or possibly redirect the report output at the top to stderr instead of stdout.

rrothenberger commented 1 month ago

@vlasar @nickpoorman I'm a bit late, so I hope you already found solution, but if not, you should be able to use conform with erb_lint through config like that:

    formatters = {
      erb_lint = {
        stdin = false,
        tmpfile_format = ".conform.$RANDOM.$FILENAME",
        command = "bundle",
        args = { "exec", "erblint", "--autocorrect", "$FILENAME" },
      },
    },

Hope it helps!

vlasar commented 1 month ago

@rrothenberger Awesome. That works great. Thank you!