25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

53 lines
1.4 KiB

  1. 'use strict';
  2. var _jsxAstUtils = require('jsx-ast-utils');
  3. var _schemas = require('../util/schemas');
  4. /**
  5. * @fileoverview Enforce tabIndex value is not greater than zero.
  6. * @author Ethan Cohen
  7. */
  8. // ----------------------------------------------------------------------------
  9. // Rule Definition
  10. // ----------------------------------------------------------------------------
  11. var errorMessage = 'Avoid positive integer values for tabIndex.';
  12. var schema = (0, _schemas.generateObjSchema)();
  13. module.exports = {
  14. meta: {
  15. docs: {
  16. url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/tabindex-no-positive.md'
  17. },
  18. schema: [schema]
  19. },
  20. create: function create(context) {
  21. return {
  22. JSXAttribute: function JSXAttribute(attribute) {
  23. var name = (0, _jsxAstUtils.propName)(attribute).toUpperCase();
  24. // Check if tabIndex is the attribute
  25. if (name !== 'TABINDEX') {
  26. return;
  27. }
  28. // Only check literals because we can't infer values from certain expressions.
  29. var value = Number((0, _jsxAstUtils.getLiteralPropValue)(attribute));
  30. // eslint-disable-next-line no-restricted-globals
  31. if (isNaN(value) || value <= 0) {
  32. return;
  33. }
  34. context.report({
  35. node: attribute,
  36. message: errorMessage
  37. });
  38. }
  39. };
  40. }
  41. };