Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

58 lignes
1.9 KiB

  1. 'use strict';
  2. var _jsxAstUtils = require('jsx-ast-utils');
  3. var _ariaQuery = require('aria-query');
  4. var _schemas = require('../util/schemas');
  5. var errorMessage = 'The autoFocus prop should not be used, as it can reduce usability and accessibility for users.'; /**
  6. * @fileoverview Enforce autoFocus prop is not used.
  7. * @author Ethan Cohen <@evcohen>
  8. */
  9. // ----------------------------------------------------------------------------
  10. // Rule Definition
  11. // ----------------------------------------------------------------------------
  12. var schema = (0, _schemas.generateObjSchema)({
  13. ignoreNonDOM: {
  14. type: 'boolean',
  15. default: false
  16. }
  17. });
  18. module.exports = {
  19. meta: {
  20. docs: {
  21. url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/no-autofocus.md'
  22. },
  23. schema: [schema]
  24. },
  25. create: function create(context) {
  26. return {
  27. JSXAttribute: function JSXAttribute(attribute) {
  28. // Determine if ignoreNonDOM is set to true
  29. // If true, then do not run rule.
  30. var options = context.options[0] || {};
  31. var ignoreNonDOM = !!options.ignoreNonDOM;
  32. if (ignoreNonDOM) {
  33. var type = (0, _jsxAstUtils.elementType)(attribute.parent);
  34. if (!_ariaQuery.dom.get(type)) {
  35. return;
  36. }
  37. }
  38. // Don't normalize, since React only recognizes autoFocus on low-level DOM elements.
  39. if ((0, _jsxAstUtils.propName)(attribute) === 'autoFocus') {
  40. context.report({
  41. node: attribute,
  42. message: errorMessage
  43. });
  44. }
  45. }
  46. };
  47. }
  48. };