antfu / eslint-config

Anthony's ESLint config preset
https://eslint-config.antfu.me/
MIT License
4.07k stars 450 forks source link

Allow setting `files` for each package (react, solid, astro etc.) in the options #626

Open m4rvr opened 4 weeks ago

m4rvr commented 4 weeks ago

Clear and concise description of the problem

At the moment it's only possible to define true or overrides in this config:

export default antfu(
  {
    react: true,
    solid: {
      overrides: {
        // ...
      }
    }
  }
)

If you have a monorepo (like me) where you use React and Solid, the rules collide.

Suggested solution

It would be great to allow the files option in the settings for each package like it's already possible when calling the function like react() or solid(), so the scope can be changed like this:

export default antfu(
  {
    react: {
      files: ['packages/app1/**/*.tsx']
    },
    solid: {
      files: ['packages/app2/**/*.tsx']
    }
  }
)

Alternative

As an alternative, manually calling and adding the packages works too. It just feels a little bit hacky and the feature request is more convenient.

import antfu, { react, solid } from '@antfu/eslint-config'

export default antfu(
  {
    react: false,
    solid: false
  },
  react({
    files: ['packages/app1/**/*.tsx'],
  }),
  solid({
    files: ['packages/app2/**/*.tsx'],
  })
)

Additional context

This was discussed in #625 already.

Validations

pauliesnug commented 3 weeks ago

This is already implemented in most configurations, however the resolveSubOptions aren't passed (only getOverrides) in the factory, despite the fact that almost all configurations support OptionsFiles. All that would need to happen is for the sub options to be resolved as well, so you can override the files per-config, as this is already supported in the options spread types of both Solid and React.

This is a pretty simple fix. I can make a PR

antfu commented 3 weeks ago

PR welcome, thanks!