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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to new eslint config format #991

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Cruikshanks
Copy link
Member

DEFRA/water-abstraction-team#115

In Add linting using eslint with standard as the base we switched from using standard directly for linting to using ESlint.

This is all part of the work we are doing to start codifying our conventions rather than writing them up for no one to read! 馃榿

We then went to make a config change but saw that we were using a deprecated core rule and instead needed to use @stylistic/eslint-plugin-js for max-len rule. So, we fixed that! 馃挭

But then we clocked ESLint was telling us our .eslintrc.js config file format is deprecated! 馃槱 We instead should be using the eslint.config.js flat file config.

So, before we start making changes to our config this change gets us using the latest supported format.

DEFRA/water-abstraction-team#115

In [Add linting using eslint with standard as the base](#948) we switched from using [standard](https://www.npmjs.com/package/standard) directly for linting to using [ESlint](https://eslint.org/).

This is all part of the work we are doing to start codifying our conventions rather than writing them up for no one to read! 馃榿

We then went to make a config change but saw that we were using a deprecated core rule and instead needed to [use @stylistic/eslint-plugin-js for max-len rule](#989). So, we fixed that! 馃挭

But then we clocked ESLint was telling us our `.eslintrc.js` [config file format is deprecated](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated)! 馃槱 We instead should be using the `eslint.config.js` [flat file config](https://eslint.org/docs/latest/use/configure/configuration-files).

So, before we start making changes to our config this change gets us using the latest supported format.
The new flat file format no longer supports `extends:`. Instead, in flat config files

> predefined configs are imported from separate modules into flat config files.

This means you need to `import` your config as you would any other package then specify what you've imported at the top of your config. For example this

```javascript
module.exports = {
  extends: 'standard',
  // ...
```

becomes this

```javascript
const standard = require('eslint-config-standard')

module.exports = [
  standard,
  {
    //...
```
Note - This will error when run
@Cruikshanks Cruikshanks added do not merge Used for spikes and experiments housekeeping Refactoring, tidying up or other work which supports the project labels May 8, 2024
@Cruikshanks Cruikshanks self-assigned this May 8, 2024
@Cruikshanks
Copy link
Member Author

This change is currently blocked. Admittedly we are new to this. But from our reading to switch away from the now deprecated config file format we cannot just have ESLint call out to standard. We have to follow what the docs say about Predefined and Shareable Configs.

This means we have to use eslint-config-standard. The problem is when we do we get this error.

Oops! Something went wrong! :(

ESLint: 8.57.0

A config object is using the "parserOptions" key, which is not supported in flat config system.

Flat config uses "languageOptions.parserOptions" to specify parser options.

Please see the following page for information on how to convert your config object into the correct format:
https://eslint.org/docs/latest/use/configure/migration-guide#configuring-language-options

And it appears we are not the only ones. Now the PR references ESLint v9 and we appear to be on v8. But the problem seems to be the same. There are some workarounds suggested and we can keep an eye on them. But more worrying is the last issue added; A standard that lacks maintenance is no longer a standard.

No one has responded to it or closed the issue.

So, we don't want to switch file formats yet because doing so forces a dependency on eslint-config-standard. And we don't want that until we see some traction on these issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge Used for spikes and experiments housekeeping Refactoring, tidying up or other work which supports the project
Projects
None yet
1 participant