Trouble with eslint

I’ve got a new plugin that’s failing lint tests:

Run if test -f .prettierrc.cjs; then
yarn run v1.22.22
$ /home/runner/work/discourse-multi-rating/discourse-multi-rating/node_modules/.bin/eslint --ext .js,.gjs,.js.es6 --no-error-on-unmatched-pattern test/javascripts assets/javascripts admin/assets/javascripts
Invalid option '--ext' - perhaps you meant '-c'?
You're using eslint.config.js, some command line flags are no longer available. Please see https://eslint.org/docs/latest/use/command-line-interface for details.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 2.

I don’t see --ext in my source tree, so maybe it’s in @discourse/lint-configs/eslint")? I don’t know where to find that.

I can’t see what I’m doing wrong or how this isn’t affecting a whole bunch of plugins. :person_shrugging:

I’ve seen this error on my own plugin. I figured out it was because I tried to update the eslint config file from .eslintrc.cjs to the latest flat config format eslint.config.js via the eslint migration. eslint.config.js doesn’t support the --ext (Command Line Interface Reference - ESLint - Pluggable JavaScript Linter), so changing the file to the older .eslintrc.cjs should fix it.

There are some extra instructions on how to setup the lint files in lint-configs/lint-configs at main · discourse/lint-configs · GitHub

For some extra context, @discourse/lint-configs use eslint 8.57.0, which by default doesn’t utilize the new flat config Configuration Files - ESLint - Pluggable JavaScript Linter.

2 Likes

That’s what’s so strange. I don’t see a eslint.confi.js anywhere on my filesystem (if I’m to trust locate, and certainly not in my source tree).

Did you get it to work?

Oh that’s weird… Yes, I was able to get mine to work.

I would check the package.json to see if the devDependencies has "eslint": "8.57.0", and not a 9.x.x

Yes. :crying_cat_face: I just noticed that eslint and prettier were changed in package.json. I swear it was just a minute ago that I cloned it from the skeleton. :person_shrugging:

Now it’s giving me (legit) errors at github, but I can’t get estlint to run locally to be able to get it to fix stuff.

1 Like

Jay,

do:

yarn

then

yarn eslint --fix plugins/<my-plugin>

(obviously update “my plugin”)

both from discourse directory

2 Likes

OMG. I’d just managed to fix it in some way that was completely impossible to reproduce, so this is a lifesaver. And now I’ve added it to my magic file so this might work next time

if [[ "$ARG" == 'fix-eslint' ]]
then
  cd ~/src/discourse-repos/discourse
  yarn
  for x in ~/plugins/* 
  do
    yarn eslint --fix x
  done
fi
2 Likes

Wait. Are you saying that this will update eslint to the proper version? Or run eslint? Or that if I run it that way, it’ll be the right version?