-
Notifications
You must be signed in to change notification settings - Fork 3
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
data-test-id eslint rules, create function and cypress commands #54
Conversation
Should this be kebab-case |
TODO: in another PR adding the following commands to the
|
changed the doc to say I've also seen I know The general guidelines around global data attributes say no caps https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/data-*. The spec itself says no uppers https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes And then finally, every example they have with more than one word has them separated by hyphens so
That context along with my time in webdev makes |
I've also added the cypress commands that make storybook and using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Nice work!
Should it be configurable with |
It could be. the |
Co-Authored-By: Tim Hoiberg <tim.hoiberg@gmail.com>
packages/eslint-plugin/README.md
Outdated
plugins: ["@kablamo"], | ||
extends: ["plugin:@kablamo/recommended"], | ||
rules: { | ||
"test-id-consistent-naming": ["data-testid"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be "test-id-consistent-naming": ["error", "data-testid"],
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i think so. the rulestester complains if you give it more than one arg, and I think that was confusing me.
This has 2 failing tests on the eslint rules, because i cannot get the eslint environment running correctly, for the tests to run.
Kablamo eslint plugin
yarn add -D @kablamo/eslint-plugin
Add the following to your
.eslintrc.js
.Rules
test-id-prefix-match-path
This rule fixes the first argument of
createTestIds(prefix, [ ...ids])
to be a prefix derived from the filescurrent directory. This ensures consistent unique prefixes per component.
You can still suffix variables to the end of your test id for example
data-test-id={
${testId.myId}-${uuid}}`.test-id-consistent-naming
This rule ensures common misspellings always get fixed to the snake-case
data-test-id
.Configurations
This plugin contains a reccomended elsint ruleset to enable the included rules.