mthadley / eslint-plugin-sort-destructure-keys

ESLint plugin to check if keys should be sorted in an object pattern.
https://www.npmjs.com/package/eslint-plugin-sort-destructure-keys
ISC License
95 stars 9 forks source link

[docs]: How to use in flat config? #301

Open rakleed opened 1 week ago

rakleed commented 1 week ago

Please add to README information about how to use your plugin in flat config. Now it has information only about usage with eslintrc which is deprecated in ESLint 9.

viveklbs commented 1 week ago

can i pick this up? i am already testing it out in v9.14.0

viveklbs commented 1 week ago

@rakleed it should look something like this

module.exports = {
  files: ["**/*.js"],
  plugins: {
    "sort-destructure-keys": require("eslint-plugin-sort-destructure-keys"),
  },
  rules: {
    "sort-destructure-keys/sort-destructure-keys": [
      "error",
      { caseSensitive: true },
    ],
  },
};
rakleed commented 1 week ago

I was able to get the plugin to work based on the information in https://github.com/mthadley/eslint-plugin-sort-destructure-keys/issues/266#issuecomment-2154205822, but it would be nice for that information to be in the README. If you do PR, that will be great.

By the way, here is my simplified config for ESM:

import sortDestructureKeys from 'eslint-plugin-sort-destructure-keys';

export default [
  {
    files: ['**/*.js', '**/*.jsx'],
    plugins: {
      'sort-destructure-keys': sortDestructureKeys,
    },
    rules: {
      'sort-destructure-keys/sort-destructure-keys': 'error',
    },
  },
];

As an example of documentation for ESM and CJS, you can look at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/readme.md#usage-eslintconfigjs