Skip to content

Conversation

@julienw
Copy link

@julienw julienw commented Feb 25, 2025

This converts our existing eslint configuration to use a flat config configuration, which is needed by eslint v9.
Note that this PR doesn't update eslint, I'll let the automatic dependency updates do that later.

@netlify
Copy link

netlify bot commented Feb 25, 2025

Deploy Preview for firefox-devtools-react-contextmenu ready!

Name Link
🔨 Latest commit a220bdf
🔍 Latest deploy log https://app.netlify.com/sites/firefox-devtools-react-contextmenu/deploys/67bf1a1b96ea400008aef859
😎 Deploy Preview https://deploy-preview-290--firefox-devtools-react-contextmenu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 92
Accessibility: 82
Best Practices: 92
SEO: 92
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +10 to +12
function configsForFiles({ files, configs }) {
return configs.map(config => ({ ...config, files }));
}
Copy link
Author

@julienw julienw Feb 25, 2025

Choose a reason for hiding this comment

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

This could be useful to reuse in other eslint config files as well. I believe it makes it more readable by grouping all the configurations that apply to the same set of files:

...configsForFiles({
  files: ['**/tests/*.js'],
  configs: [
    jest.configs['flat/recommended'],
    jestDom.configs['flat/recommended'],
    testingLibrary.configs['flat/react'],
    {
      rules: {
        // ... other rules
      }
    }
  ]
}),

The alternatives without using such a utility are much more verbose IMO:

{
  files: ['**/tests/*.js'],
  plugins: {
    jest: jest,
    "jest-dom": jestDom,
    "testing-library": testingLibrary,
  },
  languageOptions: {
    globals: jest.environments.globals.globals
  },
  rules: {
    ...jest.configs['flat/recommended'].rules,
    ...jestDom.configs['flat/recommended'].rules,
    ...testingLibrary.configs['flat/react'].rules,
    'prefer-arrow-callback': 'off',
    ... // other rules
  }
}

or

{
  ...jest.configs['flat/recommended'],
  files: ['**/tests/*.js'],
}, 
{
  ...jestDom.configs['flat/recommended'],
  files: ['**/tests/*.js'],
},
{
  ...testingLibrary.configs['flat/react'],
  files: ['**/tests/*.js'],
},
{
  files: ['**/tests/*.js'],
  rules: {
    // other rules
  }

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the helper method looks good.
I'm really not a big fan of the new config format :/ And still pissed that they had to do a huge breaking change like this...

@julienw julienw force-pushed the update-eslint-flatconfig branch from 5517a20 to 4b233f7 Compare February 25, 2025 12:56
@julienw julienw requested a review from canova February 25, 2025 12:58
Copy link
Member

@canova canova left a comment

Choose a reason for hiding this comment

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

Looks good to me! I guess this project was the one that had smallest eslintrc files. Hopefully the other projects will not be too bad.

window.resizeTo = (width, height) => {
window.innerWidth = width || window.innerWidth;
window.innerHeight = width || window.innerHeight;
window.innerHeight = height || window.innerHeight;
Copy link
Member

Choose a reason for hiding this comment

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

Oh, was this warned by the eslint? That's cool.

Copy link
Author

Choose a reason for hiding this comment

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

yeah, I guess this was ignored for some reason before... Not sure why :-)

Comment on lines +10 to +12
function configsForFiles({ files, configs }) {
return configs.map(config => ({ ...config, files }));
}
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the helper method looks good.
I'm really not a big fan of the new config format :/ And still pissed that they had to do a huge breaking change like this...

}

// Useful to import legacy shared configuration
const compat = new FlatCompat();
Copy link
Member

Choose a reason for hiding this comment

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

Oh did they have FlatCompat from the start? I don't remember seeing it while I was looking at it a while ago. It could make the migration a bit less painful at least.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not so sure :-)

I found it initially by running the migration script (that wasn't doing a super good job).
Also it's mentioned in the migration docs (https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config) but not in a very visible way IMO.

@julienw julienw enabled auto-merge February 26, 2025 13:42
@julienw julienw merged commit 5ca1175 into firefox-devtools:master Feb 26, 2025
6 checks passed
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