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 defineRules function #231

Closed
wants to merge 6 commits into from
Closed

Add defineRules function #231

wants to merge 6 commits into from

Conversation

Shinigami92
Copy link
Collaborator

@Shinigami92 Shinigami92 commented Sep 17, 2023

This idea came into my mind by chatting with @antfu 🚀

It is a helper function to shorten the configs a bit by reducing the redundant and sometimes long names by mapping over the rules

defineRules('@typescript-eslint', {
  'array-type': [
    'error',
    { default: 'array-simple', readonly: 'generic' },
  ],
  'consistent-type-imports': 'error',
});

Additionally due to we now provide the specific plugin name, we can ensure that the types are exactly from that plugin and throw a compile time error if the rule e.g. has a typo and does not exists

Also the rules are grouped indirectly together by this, which is also a nice thing

@Shinigami92 Shinigami92 added the enhancement New feature or request label Sep 17, 2023
@Shinigami92 Shinigami92 self-assigned this Sep 17, 2023
@Shinigami92
Copy link
Collaborator Author

We can use

type RemovePrefix<TPrefix extends string, TString extends string>
  = TString extends `${TPrefix}${infer T}`
  ? T
  : never

@Shinigami92
Copy link
Collaborator Author

@antfu right now I just got something like this to work: https://github.com/Shinigami92/eslint-define-config/blob/define-rules-fn/src/define-rules.ts

I have to many TypeScript problems when I try to bring them together into just one function and use generics. 🤕

These explicit functions would work, but they would have the problem that they won't really work anymore,
when we would try to rebuild eslint-define-config with using augmented global properties 🤔

Do you think you can help me a bit with that?

@Shinigami92
Copy link
Collaborator Author

@Shinigami92
Copy link
Collaborator Author

I think due to the augmented global properties support, this feels obsolete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant