eslint-plugin-jsx-a11y
eslint-plugin-jsx-a11y copied to clipboard
custom rule - how?
Hi, I am trying to add a custom rule using the logic of heading-has-content rule. But instead of headings I am looking for div elements. Also, in the util hasAccessibleChild I am not only looking for any text but a text that is equal to "apply".
#My questions:
-
I don't know how to handle these errors. Can you suggest some solutions? I generated the rule files using the create-rule.md file. I added my changes to the rule and rule-test files. I run npm test and receive these errors:
Do you have a further guide on these below?
2. How do I test if the rule and the rule-test works as I want it to?
I have read the [eslint documentation](https://eslint.org/docs/developer-guide/unit-tests) but I couldn't find a solution.
- Without merging my rule to the master branch, how do I add my custom jsx-eslint /eslint-plugin-jsx-a11y plugin to test my code against the my new custom rule when I develop a new website?
here is my custom rule: https://github.com/Felicia5/eslint-plugin-jsx-a11y/blob/first-rule-button/src/rules/first-rule-button.js
Hmm - I haven't actually used that script; it was last touched 4 years ago. It's highly likely that it's out of date.
The error looks like it's coming from flow
itself - what code are you running it on?
I got this error right after I :
- run npm run create -- myrule --author="Felicia Kovacs" --description="Enforce use of button elements to display apply text" - this is the command defined in the : https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/scripts/create-rule.md
- added code to files: rule, rule-test and hasAccessibleChildApply.js util
- run npm test within int-plugin-jsx-a11y folder I forked and cloned on my local desktop.
Any idea how I can get rid of the error message coming from flow?
Can you make a branch on your fork, and post the link here? I'll clone it locally and try it out.
here it is: https://github.com/Felicia5/eslint-plugin-jsx-a11y/tree/felicia-rule
These are the steps I have done after forking:
used git clone https://github.com/Felicia5/eslint-plugin-jsx-a11y.git cd eslint-plugin-jsx-a11y git remote add upstream https://github.com/jsx-eslint/eslint-plugin-jsx-a11y.git git checkout -b "felicia-rule" git commit -m "cloned repo locally" git push git push --set-upstream origin felicia-rule npm install npm run create -- myrule --author="Felicia Kovacs" --description="Enforce use of button elements to display apply text"
npm test
git add . git commit -m "generated rule files" git push
I added my changes
npm test
git add .
git commit -m "added my changes to rule, rule-test and hasAccessibleChildMyrule util file."
git push
npm version: 6.14.8
Can I look into this?
Go for it!
The flowconfig error i.e. if [ ! -e ./.flowconfig ]; then echo \"Could not find .flowconfig\"; else flow; test $? -eq 0 -o $? -eq 2; fi
is mentioned in the Issue 855 and has been fixed in this latest commit. So upon replicating the new rule onto the latest commits, I am no longer getting the above errors.
But I am encountering the following errors which are related to import declarations in module.
10:1 error Cannot use import declarations in modules that export
using CommonJS (module.exports = 'foo' or exports.bar = 'hi') import/no-import-module-exports
11:1 error Cannot use import declarations in modules that export
using CommonJS (module.exports = 'foo' or exports.bar = 'hi') import/no-import-module-exports
12:1 error Cannot use import declarations in modules that export
using CommonJS (module.exports = 'foo' or exports.bar = 'hi') import/no-import-module-exports
12:32 error Unable to resolve path to module '../util/hasAccessibleChildMyrule' import/no-unresolved
12:32 error Missing file extension for "../util/hasAccessibleChildMyrule" import/extensions
13:1 error Cannot use import declarations in modules that export using CommonJS (module.exports = 'foo' or exports.bar = 'hi') import/no-import-module-exports
✖ 6 problems (6 errors, 0 warnings)
Cannot use import declarations in modules that export using CommonJS (module.exports = 'foo' or exports.bar = 'hi') import/no-import-module-exports
errors were due to the module.exports
instead of export default
that was mentioned in the boilerplate which is not updated yet.
I'm going to close this; please file a new issue if anyone's still having trouble.