Linter recommendations

Hello everyone, this month I started doing some research for linters so me and my teammates can all use the same code style for our project. I found these tools:

I was able to get the first 4 working with VScode (and seems to be atom extensions for them too) but I can’t make the scss-lint vscode extension work and I can’t find a way to use the htmlbeautifier gem with the code editor.

I’ve also found StandardJS (https://standardjs.com) for JS code but it doesn’t understand sprockets // require... syntax so I was planning to use it only for projects that uses webpacker.

So I was thinking, do you use code style linters? if so, do you have them integrated with your code editor? which editor? can you share your recommendations?

Thanks!

4 Likes

We use Rubocop but not as an editor extension. We set a precommit hook to run it every commit and only on modified Ruby files.

3 Likes

I use rufo. It’s highly opinionated, with little in the way of configuration options. If you’re looking for something that you can install and be productive with right away, then this is a good option. There is a VSCode extension.

1 Like

I chose Rubocop because it is what Rails itself uses and has good documentation and easy configuration.

I chose ESLint for JavaScript because it’s plugins allowed for good compatibility and extra rules with Vue.

For ERB I haven’t found any of the solutions to be very good in terms of VSCode integration. htmlbeautifier seemed to work best though.

For Ruby code I use rubocop and I’ve been delaying trying others. My struggle is with erb, there’s erb-linter from Shopify, but there’s a pending PR that woud allow to use in the editor: https://github.com/Shopify/erb-lint/pull/159

Do you have any recommendations for tools to autoformat and/or lint .js.erb and .html.erb files (preferably for usage in VSCode)? Note I’ve also asked this question with more details at Shopify’s erb-lint GitHub repo here.

Edit: Sorry, I overlooked the htmlbeautifier, will take a look into it.

Out of frustration, I’ve written an ESLint plugin to lint the JavaScript code inside .js.erb files, ignoring the Ruby syntax. You can find it here.

eslint-plugin-erb

1 Like