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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate string literal types for configs #740

Merged
merged 3 commits into from
May 21, 2024

Conversation

karlhorky
Copy link
Contributor

Hi there, first of all thanks for this ESLint plugin, great to learn about regular expression antipatterns!

Using the tseslint.config() config helper function from typescript-eslint leads to an error:

import tseslint from 'typescript-eslint';

const config = tseslint.config(
  regexp.configs['flat/recommended'] // 馃挜 Argument of type 'typeof import("/Users/k/p/project/node_modules/eslint-plugin-regexp/dist/configs/flat/recommended")' is not assignable to parameter of type 'ConfigWithExtends'.
                                     // (see more below)
)

Error message:

Argument of type 'typeof import("/Users/k/p/project/node_modules/eslint-plugin-regexp/dist/configs/flat/recommended")' is not assignable to parameter of type 'ConfigWithExtends'.
  Types of property 'rules' are incompatible.
    Type '{ "no-control-regex": string; "no-misleading-character-class": string; "no-regex-spaces": string; "prefer-regex-literals": string; "no-invalid-regexp": string; "no-useless-backreference": string; ... 60 more ...; "regexp/use-ignore-case": string; }' is not assignable to type 'Partial<Record<string, RuleEntry>>'.
      Property '"no-control-regex"' is incompatible with index signature.
        Type 'string' is not assignable to type 'RuleEntry | undefined'.ts(2345)

This is because the types for typescript-eslint require a string of 'error', 'off' or 'warn'

To avoid the type mismatch when using typescript-eslint, this PR aims to generate string literal config property values instead of the current property values of string

Copy link

changeset-bot bot commented May 19, 2024

馃 Changeset detected

Latest commit: 71e159a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-regexp Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Owner

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR!
That file is automatically updated by tools/update-rulesets.ts, so could you please fix that as well?
Also, if there is a similar problem in lib/configs/rules/all.ts, could you please fix it as well?

@karlhorky
Copy link
Contributor Author

karlhorky commented May 20, 2024

@ota-meshi thanks for the feedback!

I've added a SeverityString type and updated the files you mentioned in 7efd9e3

Copy link
Owner

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@ota-meshi ota-meshi merged commit 9f1bd50 into ota-meshi:master May 21, 2024
7 checks passed
@karlhorky
Copy link
Contributor Author

karlhorky commented May 21, 2024

Thanks for the review, merge and publish in eslint-plugin-regexp@2.6.0 馃檶

I can confirm that this fixed the type error mentioned above with typescript-eslint types - no type error anymore 馃憤 :

Screenshot 2024-05-21 at 16 55 58

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.

None yet

2 participants