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

Add support for Perfectionist #202

Closed
wants to merge 2 commits into from

Conversation

azat-io
Copy link
Contributor

@azat-io azat-io commented Jun 11, 2023

Hi!

I created ESLint Plugin Perfectionist:
https://github.com/azat-io/eslint-plugin-perfectionist

This PR adds support for its types.

@azat-io azat-io requested a review from Shinigami92 as a code owner June 11, 2023 21:17
@azat-io azat-io force-pushed the feat/perfectionist branch from 0b31fba to 1912cbf Compare June 11, 2023 21:23
@Shinigami92
Copy link
Collaborator

I'm sorry I just responding so lately 🙇

I'm not yet sure I would like to support this plugin:

  • it has right now only 4k downloads per week
  • it is counter intuitive and might result in unwanted behavior to sort keys forcefully 🤔
  • it has "possible conflicts" that a person needs to know

eslint-define-config is designed to still be able to define such rules and plugins, you just don't get auto-completion

TLDR: if your issue description gets (I would say) 5 votes (:+1:) I will consider merging/supporting this plugin :slightly_smiling_face:

@azat-io
Copy link
Contributor Author

azat-io commented Jun 15, 2023

it has right now only 4k downloads per week

Yes, this plugin has been released than a week ago.

it is counter intuitive and might result in unwanted behavior to sort keys forcefully
it has "possible conflicts" that a person needs to know

The plugin takes care of security and takes into account such things as comments of object values, spread operators, etc.

Okay. Let's come back to this conversation later.

@so1ve
Copy link

so1ve commented Oct 1, 2023

This plugin has 1.1k+ stars now, let's make it happen? :)

@Shinigami92
Copy link
Collaborator

Actually we are working on something, so we do not need internal support anymore in eslint-define-config itself

But (sadly) I'm a bit exhausted right now of work, open-source and coding

This feature would solve support for any plugins out there and work a bit like DefinitelyTyped

This perfection plugin would fit absolutely best to try out the feature for that 👍
And slowly we would like to remove any internal written plugin support and extract them into their packages
Later I would even hope for having this feature backed into eslint itself and finally eslint-define-config can be fully deprecated

@azat-io azat-io force-pushed the feat/perfectionist branch from 1912cbf to 4e16449 Compare October 1, 2023 17:36
@azat-io
Copy link
Contributor Author

azat-io commented Oct 1, 2023

Didn't see the message. I rebased my PR and updated plugin. Just in case you change your mind.

@Shinigami92
Copy link
Collaborator

Hey @azat-io, could we do a test with your plugin? 🙂

I released a v2.0.0-alpha.0 in #238 (comment)

So I would like to try out to add rule types to your plugin and then we can see if it works

If it works as I would like, then I can slowly remove all the other plugins and ask for their own support

@azat-io
Copy link
Contributor Author

azat-io commented Oct 6, 2023

Sounds cool, let's give it a try

@Shinigami92
Copy link
Collaborator

with v2.0.0-beta.1 you now can support with your own types 🚀
I need to make some minor stuff before officially release it, but its ready to go now

You can have a look into https://github.com/eslint-types/define-config-plugin-types/blob/main/scripts/generate-plugin-dts.ts to find out how to generate these types

@azat-io
Copy link
Contributor Author

azat-io commented Oct 26, 2023

Can I generate plugin types?

@Shinigami92
Copy link
Collaborator

Can I generate plugin types?

As you are the author and owner of https://github.com/azat-io/eslint-plugin-perfectionist, I suggest to add the eslint-define-config support directly into your repo/package, instead of adding it to https://github.com/eslint-types/define-config-plugin-types.
That is the reason why we created this "augmented global properties" support.

So you can have a look into https://github.com/eslint-types/define-config-plugin-types/blob/main/scripts/generate-plugin-dts.ts and see how I generate types out of meta.schemas.

You can either take this script and adjust to your needs, or directly add types into your rules.

So for example: you could add following into your https://github.com/azat-io/eslint-plugin-perfectionist/blob/main/rules/sort-array-includes.ts

export interface Schema0 {
  type?: 'alphabetical' | 'line-length'| 'natural';
  order?: 'asc' | 'desc';
  // ... further stuff
}

export type SortArrayIncludesRuleOptions = [Schema0?];

Then you create a define-config-support.d.ts and it will look something like this:

import type { SortArrayIncludesRuleOptions } from './rules/sort-array-includes';

declare module 'eslint-define-config' {
  export interface CustomExtends {
    'plugin:eslint-plugin-perfectionist/recommended-alphabetical': void;
    'plugin:eslint-plugin-perfectionist/recommended-line-length': void;
    'plugin:eslint-plugin-perfectionist/recommended-natural': void;
  }

  export interface CustomPlugins {
    'eslint-plugin-perfectionist': void;
  }

  export interface CustomRuleOptions {
    /**
     * enforce sorted arrays before include method
     */
    'eslint-plugin-perfectionist/sort-array-includes': SortArrayIncludesRuleOptions;

    // more rules ...
  }

  // It's also possible that you have `CustomParsers`, `CustomParserOptions` and/or `CustomSettings`.
}

A user/dev of eslint-define-config can then use /// <reference types="eslint-plugin-perfectionist/define-config-support" /> to load your provided support.
Make sure you have something like this in your package.json:

  "exports": {
    // ...
    "./define-config-support.d.ts": {
      "types": "./dist/define-config-support.d.ts",
    },
    // ...

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.

3 participants