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

feat: support flat configs #196

Merged
merged 2 commits into from
Mar 23, 2024
Merged

feat: support flat configs #196

merged 2 commits into from
Mar 23, 2024

Conversation

43081j
Copy link
Owner

@43081j 43081j commented Mar 18, 2024

This adds support for eslint's new flat config file feature.

Supporting both systems in one config object is a rather messy situation, so we've opted here for multiple distinct configs instead.

Old style config files can continue using config objects:

{
  extends: ['plugin:lit/recommended']
}

While new style config files can use the flat/recommended variety:

[
  {
    "files": ["*.js"],
    ...configs['flat/recommended']
  }
]

Fixes #194

cc @what1s1ove

This adds support for eslint's new flat config file feature.

Supporting both systems in one config object is a rather messy
situation, so we've opted here for multiple distinct configs instead.

Old style config files can continue using config objects:

```json
{
  extends: ['plugin:lit/recommended']
}
```

While new style config files can use the `flat/recommended` variety:

```json
[
  {
    "files": ["*.js"],
    ...configs['flat/recommended']
  }
]
```
@what1s1ove
Copy link

what1s1ove commented Mar 19, 2024

Hey @43081j !

Thank you for this!

Just tested it locally, the flat config works great!

Could you please adjust the types of the base configs a bit? The thing is, currently the .d.ts file looks like the value of the rules object is a string. Though that's not entirely correct.

image

In ESLint types, Linter.RuleEntry type is used for the values of the rules object in both Linter.BaseConfig and Linter.FlatConfig config.

Currently, I'm including ESLint plugins like this. This is also considered a flat config. It's convenient for me to keep all configuration options in one place.
image

But right now, since the types in the lit plugin's rules object consist only of strings, I'm getting errors that the types are not compatible.

If we fix the types to use Linter.RuleEntry instead of strings, all errors will disappear.

image

@43081j
Copy link
Owner Author

43081j commented Mar 19, 2024

that will be because we're letting typescript infer the type rather than being explicit

i'll update in this branch since it should be a one line change

@what1s1ove
Copy link

that will be because we're letting typescript infer the type rather than being explicit

i'll update in this branch since it should be a one line change

I understood the problem, thanks! Just wanted to give you all the details on why it would be better to change it. Look forward to your changes 🙏

@43081j
Copy link
Owner Author

43081j commented Mar 19, 2024

that should all be sorted now

if you can try it out, that would be super helpful. i'll look to merge/release it in the next couple of days

@what1s1ove
Copy link

that should all be sorted now

if you can try it out, that would be super helpful. i'll look to merge/release it in the next couple of days

Just checked! Everything looks fine, thank you!

@43081j 43081j merged commit 31b701d into master Mar 23, 2024
4 checks passed
@43081j 43081j deleted the flats branch March 23, 2024 11:35
@edgarnansen
Copy link

When will this be published? It's not available in 1.11.0

@43081j
Copy link
Owner Author

43081j commented May 7, 2024

i'll sort a new release out today 👍

@43081j
Copy link
Owner Author

43081j commented May 7, 2024

1.12.0 has been published now, please let me know if all works as expected

you should be able to use configs['flat/recommended'] for example

will update the README separately when i get chance

@edgarnansen
Copy link

@43081j Wow, thanks! Didn't expect it this quick. Seems to work as expected 🥳

@johnemau
Copy link

This is awesome, thank you so much! Just a quick note, the README.md does not mention the flat config style, so at first I didn't think this plugin had updated until I went searching through the issues.

@43081j
Copy link
Owner Author

43081j commented Jun 17, 2024

We should definitely add that 👍 I'll see if I can sort it out this week

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.

Flat config support & improvements for d.ts
4 participants