Help configuring rubocop, eslint, and so on in vscode and the command line

I am sick of submitting code that fails linting tests. Sometimes, I can copy-paste the rubocop or yarn eslint (and so on) commands from github into my terminal and get that to work, but that’s not working either right now.

I’m getting errors like

 No parser could be inferred for file: ...

For some files in some conditions, vscode will properly reformat on save and tell me that I have a syntax erorr, but that’s not working now.

What would you like done?

I want to do a zoom (or whatever) screen share and have you walk me through stuff so that

  • vscode runs all the stuff it should when it saves and fixes formatting or tells me that something is broken.
  • I can run yarn eslint and whatever other stuff is in the linting tests from the command line

When do you need it done?

Before I go stark raving mad.

What is your budget, in $ USD that you can offer for this task?

I’m running Pop!Os, which is essentially Ubuntu.

If you’re pretty sure that you can solve this problem, I’m prepared to pay an hour of your time at your standard rate. If you can do it in ten minutes, I’m happy to pay for an hour. Everyone wins.



frustrating, huh?

What I do for this kind of thing is:

  • examine the CI workflows for a popular plugin
  • look at the associated config in the root of the plugin

You can see what my linting tests for Chatbot do here:

I believe you can run eslint and prettier from the plugin directory, but rubocop can be run from the discourse directory.

If this solves your problem please feel free to convert this to a dev Topic and you are welcome :slight_smile:

1 Like

What I do is blindly copy the workflows from GitHub - discourse/discourse-plugin-skeleton: Template for Discourse plugins and GitHub - discourse/discourse-theme-skeleton: Template for Discourse themes. (I do have to tweak the plugin one a bit for my dashboard plugin, which depends on the stripe plugin). This, I’m willling to believe, is good enough to do the linting.

What I want, though, is for vscode to do the linting before I do the commit. I’ve had it working in the past, but it’s stopped and I feel like someone who knows about VScode that I knew about Emacs 20 years ago, could say some stuff like “type control-p, now do the thing to install the formatting thingy, now edit the config file so that it does the Right Thing” and then I could once again, type control-S and have my handlebars, javascript, and whatever else formatted pretty, and also find all the pesky variables that I defined but never used and on like that.

Getting closer

OK, but I did this:

      npm install --global yarn
      yarn add prettier

And now I have discourse-prettier:

#!/usr/bin/env bash
if [ -n "$(find assets -type f \( -name "*.scss" -or -name "*.js" -or -name "*.es6" -or -name "*.hbs" \) 2>/dev/null)" ]; then
  yarn prettier --write "assets/**/*.{scss,js,es6,hbs}"
if [ -n "$(find admin/assets -type f \( -name "*.scss" -or -name "*.js" -or -name "*.es6" -or -name "*.hbs" \) 2>/dev/null)" ]; then
  yarn prettier --write "admin/assets/**/*.{scss,js,es6,hbs}"
if [ 0 -lt $(find test -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then
  yarn prettier --write "test/**/*.{js,es6}"

if [ -n "$(find assets -type f \( -name "*.scss" -or -name "*.js" -or -name "*.es6" -or -name "*.hbs" \) 2>/dev/null)" ]; then
  yarn prettier --list-different "assets/**/*.{scss,js,es6,hbs}"
if [ -n "$(find admin/assets -type f \( -name "*.scss" -or -name "*.js" -or -name "*.es6" -or -name "*.hbs" \) 2>/dev/null)" ]; then
  yarn prettier --list-different "admin/assets/**/*.{scss,js,es6,hbs}"
if [ 0 -lt $(find test -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then
  yarn prettier --list-different "test/**/*.{js,es6}"

That’s solved part of my problem, so at least I can get prettier to run from the command line. But I’m still willing to pay for help to get vscode to do my dirtywork. When I save, it should run eslint (or rubop or whatever) and either fix it or tell me that it can’t. I’m too old to think that my editor should write my code, but not so old that I think it shouldn’t format it.

There used to be a topic where someone suggested which vscode plugins they were using, which helped me some, but I don’t see it now.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.