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

consistent-data-testid: add support for custom error message #718

Closed
patriscus opened this issue Jan 18, 2023 · 3 comments · Fixed by #719
Closed

consistent-data-testid: add support for custom error message #718

patriscus opened this issue Jan 18, 2023 · 3 comments · Fixed by #719

Comments

@patriscus
Copy link
Contributor

patriscus commented Jan 18, 2023

What rule do you want to change?

consistent-data-testid

Does this change cause the rule to produce more or fewer warnings?

More warnings

How will the change be implemented?

The changes will be implemented by extending the possible rule configuration values by a new field (e.g. customMessage), and consuming it, if present.

Example code

Example ESLint config:

'testing-library/consistent-data-testid': [
    'error',
    {
        'testIdPattern': '^([a-z][a-z0-9]*)(-[a-z0-9]+)*$', // kebab-case
        'testIdAttribute': ['data-testid'],
    }
]
<div data-testid="some_snake_case_value" />

How does the current rule affect the code?

Example ESLint config:

'testing-library/consistent-data-testid': [
    'error',
    {
        'testIdPattern': '^([a-z][a-z0-9]*)(-[a-z0-9]+)*$', // kebab-case
        'testIdAttribute': ['data-testid'],
    }
]

Example code:

<div data-testid="some_snake_case_value" />

Example error:

ESLint: `data-testid` "some_snake_case_value" should match '^([a-z][a-z0-9]*)(-[a-z0-9]+)*$'' (testing-library/consistent-data-testid)

How will the new rule affect the code?

Example ESLint config:

'testing-library/consistent-data-testid': [
    'error',
    {
        'testIdPattern': '^([a-z][a-z0-9]*)(-[a-z0-9]+)*$', // kebab-case
        'testIdAttribute': ['data-testid'],
        'customMessage': 'Please use kebab-case values for data-testids.'
    }
]

Example code:

<div data-testid="some_snake_case_value" />

Example error:

ESLint: `data-testid` Please use kebab-case values for data-testids. (testing-library/consistent-data-testid)

Anything else?

First things first, I hope I've used the right issue template. Also, I am more than happy to have a go at this issue and open a PR, in case you all agree to proceed with this change.

In my opinion adding this change would support devs in providing more meaningful (error) messages. In my example, the developer does not need to think about what the regex means, but is just shown a straight-forward message.

Any feedback is welcome :)

Do you want to submit a pull request to change the rule?

Yes

@patriscus patriscus added enhancement New feature or request triage Pending to be triaged by a maintainer labels Jan 18, 2023
@Belco90 Belco90 removed the triage Pending to be triaged by a maintainer label Jan 19, 2023
@Belco90
Copy link
Member

Belco90 commented Jan 19, 2023

Hi @patriscus! Thanks for opening this issue. No worries, you used the right issue template 👌.

This is a great idea actually, so please if you want to give it a shot, go ahead! Let us know if you need help with anything.

Belco90 pushed a commit that referenced this issue Jan 23, 2023
)

Closes #718

* feat(consistent-data-testid): add support for custom message in the rule configuration

* feat(consistent-data-testid): update docs

* feat(consistent-data-testid): use undefined as default value for customMessage

* feat(consistent-data-testid): add comment to test case

Co-authored-by: Patrick Ahmetovic <patrick.ahmetovic@prescreen.io>
@github-actions
Copy link

🎉 This issue has been resolved in version 5.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

github-actions bot commented Aug 5, 2023

🎉 This issue has been resolved in version 6.0.0-alpha.15 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants