项目原始demo,不改动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

no-sparse-arrays.js 1.0 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * @fileoverview Disallow sparse arrays
  3. * @author Nicholas C. Zakas
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. docs: {
  12. description: "disallow sparse arrays",
  13. category: "Possible Errors",
  14. recommended: true,
  15. url: "https://eslint.org/docs/rules/no-sparse-arrays"
  16. },
  17. schema: []
  18. },
  19. create(context) {
  20. //--------------------------------------------------------------------------
  21. // Public
  22. //--------------------------------------------------------------------------
  23. return {
  24. ArrayExpression(node) {
  25. const emptySpot = node.elements.indexOf(null) > -1;
  26. if (emptySpot) {
  27. context.report({ node, message: "Unexpected comma in middle of array." });
  28. }
  29. }
  30. };
  31. }
  32. };