Closed
Description
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