Trouble with eslint

AI-generated summary

The discussion revolves around troubleshooting issues with ESLint. pfaffman is experiencing lint test failures due to an invalid --ext option, despite not using it in their source tree. Alteras shares a similar experience and suggests that the issue may be caused by updating the ESLint config file to the latest flat config format eslint.config.js, which doesn’t support the --ext option.

Alteras recommends reverting to the older .eslintrc.cjs format and provides a link to setup instructions for lint files. pfaffman is puzzled as they don’t have an eslint.config.js file in their source tree.

Alteras suggests checking the package.json file for an ESLint version mismatch. pfaffman discovers that ESLint and Prettier were updated in package.json, which may be the cause of the issue.

merefield offers a solution by running yarn and yarn eslint --fix from the discourse directory. pfaffman successfully resolves the issue using this method and creates a script to automate the process. However, pfaffman seeks clarification on whether running yarn eslint --fix updates ESLint to the correct version or simply runs ESLint with the correct version.

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 https://eslint.org/docs/v8.x/use/configure/configuration-files#configuration-file-formats.

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.

Jay,

do:

yarn

then

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

(obviously update “my plugin”)

both from discourse directory

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

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?