43081j / eslint-plugin-lit

lit-html support for ESLint
115 stars 20 forks source link

feat: support flat configs #196

Closed 43081j closed 3 months ago

43081j commented 4 months ago

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

what1s1ove commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 3 months ago

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!

edgarnansen commented 2 months ago

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

43081j commented 2 months ago

i'll sort a new release out today 👍

43081j commented 2 months ago

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 commented 2 months ago

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

johnemau commented 1 month ago

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 commented 1 month ago

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