I want to apply eslint rule for JSX attribute value.
like I have a component having some attribute for example
<Component
attribute1="abc-efg"
/>
In above example I want to place a rule which will check that if attribute1 is having values in lower-case and kebab-case if the value is other then that error will be thrown.
I tried: @typescript-eslint/naming-convention
but not able to achieve anything.
2
Answers
To enforce a rule that checks if JSX attribute values are in lowercase and kebab-case, you can create a custom ESLint rule using the eslint-plugin and @typescript-eslint libraries. Here’s how you can set it up:
After setting up the rule, run ESLint in your project to enforce the rule:
eslint –ext .jsx,.tsx src
I tested some JSX code with eslint with your requirement, and it worked for me.
After setting up the file structure, run
npx eslint Test.jsx
sources