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

Configuration Migration of ESLint configuration file from the eslintrc format to the new flat config format #1091

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

insane-22
Copy link
Contributor

Problem

According to ESLint's official docs- "The flat config file format has been the default configuration file format since ESLint v9.0.0". Codebase isn't updated with this new config

Solution

Added new eslint.config.js file and migrated code from .eslintrc.js and .eslintignore to this new config file

insane-22 and others added 3 commits May 30, 2024 00:04
Something went wrong in e2ff10e , I suspect some manual modification that ended up breaking the lockfile with this error message:
"SyntaxError: Invalid value type 1540:0 in yarn.lock"
Copy link
Contributor

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for starting this update!

Something was wrong with the yarn lockfile, I think maybe it got corrupted somehow, or you tried to manually correct something in there?
In any case I regenerated it so at least the tests can run.
This suggests to me that you did not try to run the linting locally, or at least not after the last commit. It is essential that you try running the linting command to make sure everythinng works as you expect it to.

That shows that at least the eslint.config.js file has a lot of linting issues, ironically :)
You can fix a lot of the issues automatically by running yarn lint eslint.config.js --fix.

More problematically, the previous configuration file eslintrc.js still exists in the repo, and I can't tell you which config is used...
I suppose it should probably be deleted in favor of the new file.
Also do a global search in the repo for the file name, to replace it with the new one where appropriate.

I also think this PR would be the perfect occasion to update ESLint to v9 and allow us to test the changes with the target version; without that, i'm not sure the PR actually tests that the config changes will work for v9.

@@ -0,0 +1,444 @@
const { FlatCompat } = require("@eslint/eslintrc");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can write all these imports with the import syntax to modernize it too, like so:

import { FlatCompat } from'@eslint/eslintrc';
import pluginImport from 'eslint-plugin-import';

etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, would make it eslint.config.mjs and add the changes

const pluginNode = require("eslint-plugin-node");
const pluginTypeScript = require("@typescript-eslint/eslint-plugin");

const compat = new FlatCompat({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the warning is howing here (in the files tab of the PR on github), this compat configuration you create here is never used.
Either something is wrong with the configuration as it stands, or the FlatCompat and associated package are not actually needed...
Not sure which it is.

"import/no-unassigned-import": ERROR,
};

module.exports = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot one 😅

Suggested change
module.exports = [
export default [

@insane-22
Copy link
Contributor Author

Thank you very much @MonkeyDo for again helping while solving the issue :)
I actually was trying a few things and that's why lock file error was there. I also tried the the upgrade to eslint v9 but there is a problem, "eslint-plugin-import" dependency does not have compatibility with Eslint v9 (import-js/eslint-plugin-import#2948).

@insane-22
Copy link
Contributor Author

but at the same time eslint.config.js doesnt work with versions prior to v9, hence it doesnt make sense to leave it this way.

One work-around I could find is import-js/eslint-plugin-import#2948 (comment)
or we can wait until the whole v9 ecosystem is ready to use. what in your opinion shall be the next steps?

@MonkeyDo
Copy link
Contributor

I read up ont he whole discussion, and it looks like v9 support in the plugin is going to take some time.
In the meantime, from what I read you should be able to use this drop-in replacement: https://github.com/un-ts/eslint-plugin-import-x
Please add a TODO comment note where you can, with a short explanation that we are using this package as a temporary replacement until v9 support is out, that it should be replaced as soon as available, and a link to the eslint-plugin-import issue.

@MonkeyDo
Copy link
Contributor

Bump @insane-22, do you have the time to look into the alternate plugin, or would you prefer I do?
Thanks again for looking at these config changes!

@insane-22
Copy link
Contributor Author

Hello @MonkeyDo, sorry for this delay, was caught up in a few things and thanks a lot for this reminder.
Please allow me some more time, I will be back with the changes :)

@insane-22
Copy link
Contributor Author

Hello hello, I'm back with new sets of errors :]

"@eslint/[email protected]: The engine "node" is incompatible with this module. Expected version "^18.18.0 || ^20.9.0 || >=21.1.0". Got "20.6.1" "
when i changed dockerfile as "FROM metabrainz/node:20 as bookbrainz-base"
it still has node v20.6.0, which is incompatible, adding any advanced versons shows
"failed to solve: metabrainz/node:20.9.0: failed to resolve source metadata for docker.io/metabrainz/node:20.9.0: docker.io/metabrainz/node:20.9.0: not found"

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

Successfully merging this pull request may close these issues.

2 participants