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

Support ESLint flat configuration #100

Merged
merged 2 commits into from
Feb 16, 2024

Conversation

jgarber623
Copy link
Contributor

First off, thanks for considering this change! I've used your plugin for quite some time and it's been super helpful.

Description

(Drawn from commit message on 15ace41)

This PR refactors ./src/index.js to support ESLint's "new" flat configuration file in a non-disruptive, backwards-compatible manner.

The introduction of the flat configuration changed the "shape" of the object that plugins should export. As a result, plugin authors are adding confis with names like flat/recommended (as I've done here) for consumers ot use. Rules for the "flat"-prefixed configurations are the same as the legacy config, but with the exported objects conforming to the new "flat" syntax.

I followed the recommendations in the plugin migration guide with inspiration drawn from the eslint-plugin-jsdoc's project.

Notable changes:

  • adds the meta key as recommended by ESLint with name and version drawn from package.json
  • adds a flat/recommended configuration matching the rules set by the existing recommended configuration

Usage in an eslint.config.js file would look like:

import sortClassMembers from "eslint-plugin-sort-class-members";

export default [
  sortClassMembers.configs["flat/recommended"],

  rules: {
    // etc. etc. etc.
  },
];

…and also

I neglected to note the "before" in my commit message. Before this change, using this plugin in a "flat" configuration file is possible, but requires a bit of extra work:

import sortClassMembers from "eslint-plugin-sort-class-members";

export default [
  {
    plugins: { "sort-class-members": sortClassMembers },
    rules: sortClassMembers.configs.recommended.rules,
  },
  
  rules: {
    // etc. etc. etc.
  },
];

This commit refactors `./src/index.js` to support ESLint's "new" flat
configuration file [1] in a non-disruptive, backwards-compatible manner.

The introduction of the flat configuration changed the "shape" of the
object that plugins should export. As a result, plugin authors are
adding confis with names like `flat/recommended` (as I've done here) for
consumers ot use. Rules for the "flat"-prefixed configurations are the
same as the legacy config, but with the exported objects conforming to
the new "flat" syntax.

I followed the recommendations in the plugin migration guide [2] with
inspiration drawn from the eslint-plugin-jsdoc's project [3].

Notable changes:

- adds the `meta` key as recommended by ESLint with name and version
  drawn from `package.json`
- adds a `flat/recommended` configuration matching the rules set by the
  existing `recommended configuration`

Usage in an `eslint.config.js` file would look like:

```js
import sortClassMembers from "eslint-plugin-sort-class-members";

export default [
  sortClassMembers.configs["flat/recommended"],

  rules: {
    // etc. etc. etc.
  },
];
```

[1] https://eslint.org/docs/latest/use/configure/configuration-files-new
[2] https://eslint.org/docs/latest/extend/plugin-migration-flat-config
[3] https://github.com/gajus/eslint-plugin-jsdoc/blob/main/src/index.js
@jgarber623
Copy link
Contributor Author

Oh, shoot. In my enthusiasm for getting this PR open, I forgot to update the README. I'm happy to do that but will wait for any feedback on this PR first.

@bryanrsmith
Copy link
Owner

Thanks for the PR and the thorough explanation! I'm kinda out of the loop on the flat config migration, but this looks inline with the recommendation as far as I can tell.

If you wouldn't mind updating the docs that would be great!

@jgarber623
Copy link
Contributor Author

Thanks, @bryanrsmith! Added a bit of detail to the README.md in fe70442. Let me know what you think.

@bryanrsmith bryanrsmith merged commit d076343 into bryanrsmith:main Feb 16, 2024
4 checks passed
@bryanrsmith
Copy link
Owner

Thank you! Published as v1.20.0.

@jgarber623 jgarber623 deleted the refactor-for-flat-config branch February 16, 2024 19:54
@jgarber623
Copy link
Contributor Author

That's great news. Thanks, @bryanrsmith!

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