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

Lint JavaScript and HTML parts of ERB code #333

Open
Splines opened this issue Nov 15, 2023 · 3 comments
Open

Lint JavaScript and HTML parts of ERB code #333

Splines opened this issue Nov 15, 2023 · 3 comments

Comments

@Splines
Copy link

Splines commented Nov 15, 2023

First of all, thanks a lot for your ERB lint project, we will definitely try it with our MaMpf codebase.

I just wanted to ask what setup you use at Shopify in order to autoformat and/or lint the pure JavaScript or pure HTML part of your ERB files? Ideally, for JavaScript, we'd like to run the mature ESLint. However, I've only found this StackOverflow question and the answer indicates you'd have to write your own processor to strip the Ruby parts and then create your custom source map such that the linter can still correctly identify line numbers.

While certainly doable with more research, I was wondering if this was not already a "solved problem" in the Ruby community. We cannot be the first to want to lint JavaScript in .js.erb and HTML code in .html.erb files (locally as well as with a CI/CD pipeline), right?

For IntelliSense to work in VSCode, I've just discovered this extension for HTML which I will give a try and also look closer into this reddit thread. If you're using VSCode: Do you have any recommendations for HTML/JS extensions such that IntelliSense works? Ideally (for our wish list), an autoformatter would format the document according to some style guide whenever you save the file.

Note I've searched for the terms "eslint", "javascript", "js", ".js.erb", "html", ".html.erb" in the issues but did not find anything relevant to my question. This issue is probably not related.

@Splines
Copy link
Author

Splines commented Nov 15, 2023

Maybe helpful for linting JavaScript with ESLint inside ERB files: this plugin.

@Splines
Copy link
Author

Splines commented Nov 17, 2023

Note I've just also asked this question in the Rails forum here.

@Splines
Copy link
Author

Splines commented Nov 19, 2023

Note: for the JS part inside .erb files, I have just finished to develop my own solution (out of frustration 😅): a plugin for ESLint that you can find over here.

eslint-plugin-erb

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

No branches or pull requests

1 participant